When our son arrives next year, we’re anticipating late night feedings and diapers changes which may mean needing to turn on our smart bulbs without fumbling for our phones or asking Alexa.
(Or honestly, we don’t know. We’re new.)
I bought an AWS IoT button as it appeared to be the least expensive smart button option that wasn’t dependent on a hub or iPhone. And then I wrote some scripts to can control LIFX bulbs from the command line or from a AWS IoT Button.
The scripts can toggle, set, and get the current state of a single light, all lights, or a group of lights. You can check them out on GitHub and try them if you have also LIFX bulbs.
Toggle a light
If I want to toggle a light, group of lights, or all our lights, I can run:
lifx-toggle --bulb=<bulb ID|all>
Set a light
If I want to set a light with a different brightness, color, power, or duration, I can run:
lifx-set --bulb=<bulb ID|all> --color=<string> --power=<on|off> --brightness=<number> --duration=<number>
It’s fun to transition between colors by setting a long
duration (which is in seconds).
Get a light
If I want get the status of a particular light, I can run:
lifx-get --bulb=<bulb ID|all>
This script is also handy for finding out the selectors for all your lights.
Hooking up the IoT button
I have another script in the repository that my IoT button runs or I can run from the command line:
lifx --bulb=<bulb ID|all> --click=<SINGLE|DOUBLE|LONG>
In the case of my button, a single click turns my nightstand light on at 30% brightness. When I double click it turns the entire bedroom to 50% and when I long press it turns on all the lights in the house. I created
iot-settings.json to configure these settings and then set the actual bulb IDs as parameters in my CloudFormation template.
To get my button set up, I followed the AWS IoT Button AWS CloudFormation Quickstart guide to learn how to create a CloudFormation template that works with the IoT button. I customized their template so that I could invoke my function.
I deployed my code, created a new stack and had my button up and running. The only issue I’ve found with the AWS IoT Button is a few second delay from when I press the button and LIFX processes the request. Otherwise, I had a great time playing with both the IoT button and the LIFX API.
Did you enjoy this post? Support Soul Fire Farm. Soul Fire Farm is committed to ending racism and injustice in the food system.