Ridiculously unnecessary light switch for a LIFX wifi bulb, using an AWS IoT Button and AWS Lambda
That's a great question. I actually made this about two years ago when I thought the hype for serverless architectures had peaked (lol). I wanted to try out something in the IoT space and get more experience with AWS without having to do something actually difficult.
- You'll need to purchase an AWS IoT Button
- You'll also need a LIFX lightbulb
- Follow the directions on the AWS docs to configure the button
- Follow the instructions to connect the button to lambda
- Generate an authentication method for the bulb. You can use OATH, but I just generated an API key here since that's way easier
- Upload this code to the lambda function from earlier
- Set a lambda environment variable called "API_KEY" with your API token
- Ta-da! You now have a $20 lightswitch that takes 7-10 seconds to work and is dependant on your wi-fi connection (I never said this was a good idea)
Once you follow the setup process, every time you press the IoT button, it will toggle all of your lights. That's because I used the "all" endpoint since I only had one light anyway. You can specify groups and more specific IDs as well. Check out the API Docs if you're interested.
This script only has a single function regardless of how you press the button, but there's actually 3 possible states: SINGLE, DOUBLE, and LONG. These are received in the "clickType" field of the event. A possible extension would be to trigger different scenes or colors based on what type of click you used.