https://github.com/JohnTheNerd/lightAPI
10K+
A simplistic smart lighting application written in Python 3. It has a Flask-based API to control all light functionality. I run it on my little Raspberry Pi to manage my lights (and popcorn maker). It currently only works with the HS100 smartplug and LifX/Yeelight bulbs. It is also possible to implement all the functions in devices/yeelight.py for any device, which will make the API automatically able to communicate to the bulb by setting the filename as brand in the configuration file.
Everything in the API works as GET requests - this is an intentional design decision. This allows one to trigger any function in the API straight from the browser!
Clone this repository.
Install all the requirements by running pip3 install pyHS100 flask lifxlan.
Rename config.dist.json to config.json.
Open config.json in any text editor and change variables as necessary. All times are in seconds.
multizone represents a LifX Z, and mac/ip should be self-explanatory.initialFadeIn is the amount of time cyan light initially fades in, duration is the total duration of the alarm, and colorChangeFrequency is how often the color will rotate after the initial fade-in. You could install ffplay and put a file under the alarm directory named alarm.mp3 if you'd like to hear an alarm too. If you don't have any form of sensitivity to flashing shiny lights and just need to get out of bed, you could change the mode to insane. If you do so, you must also:
colors as a list of colors you'd like to use.slack to automatically post to a Slack channel a certain period after the alarm starts, if it's still running of course. If you do so, you must also define all the options you can find under config.dist.json.hostIP as the IP address of the computer this is running on.ip is the IP address of your HS100 smart plug, offTimer is an optional timer set for the on command, and onRoutes/offRoutes are the additional endpoints used to control the plug.0.0.0.0 may work if you want to have it wide open, 127.0.0.1 will lock it down to your local computerRun api/main.py. There is also an example lightAPI.service file you can copy to /etc/systemd/system/ (after changing the paths) and run sudo systemctl enable lightAPI to have the API continuously run for you!
If you'd like to have alarm support, run alarm/main.py. The only endpoints are /set/<year>/<month>/<day>/<hour>/<minute>/<second> and /stop/<password> and settings are read as documented above.
To use any module, you can either call the corresponding API endpoints through a browser or just run main.py under their folder.
In order to use the Tasker profiles, you must have purchased all of Tasker, AutoWear, and AutoAlarm. Afterwards,
tasker/tasks directory.tasker/profiles directory.raspberrypi to the IP address of your Raspberry Pi.Oh, it also runs on Docker. You could create a config.json file and run:
docker build -t lightapi .
docker run -p 5000:5000 lightapi # add "--restart always" to continuously restart and "-p 54433:54433" if you have a yeelight bulb
http://my.ip.goes.here:5000/camera/<light>
Triggers a camera alarm, making the light full brightness on white color and sending an e-mail if configured. Your camera system should be pointing here.
http://my.ip.goes.here:5000/camera/off/<password>
Disarms the camera module. If the given password is incorrect, returns with a naive 404.
http://my.ip.goes.here:5000/camera/on
Arms the camera module.
http://my.ip.goes.here:5000/colors
Starts color rotation, for all lights.
http://my.ip.goes.here:5000/colors/<seconds>
Starts color rotation for all lights, with a pre-defined number of seconds between full color changes.
http://my.ip.goes.here:5000/rotate/stop
Stops all color rotation, for all lights.
http://my.ip.goes.here:5000/
Shows the status of all devices.
http://my.ip.goes.here:5000/<light>/set/<hue>/<saturation>/<brightness>/<kelvin>
You can use this to manually set a light color. You can take the values returned from the main page and put them here.
http://my.ip.goes.here:5000/<light>/off/<seconds>
A simple timer. The light will slowly dim down and turn off afterwards. Keep in mind that I intentionally add 5% to the given value because of some race conditions.
http://my.ip.goes.here:5000/<light>/random
Sets the light to a random color.
http://my.ip.goes.here:5000/<light>/random/<brightness>
Sets the light to a random color, with a provided brightness.
http://my.ip.goes.here:5000/<light>/blink
Blinks the light three times, rapidly dimming and re-brightening the light over the span of a second or two.
http://my.ip.goes.here:5000/<light>/blink/<count>
Blinks the light a given number of times, rapidly dimming and re-brightening the light over the span of a second or two.
http://my.ip.goes.here:5000/<light>/blink/<count>/<brightness>
Blinks the light a given number of times, rapidly dimming and re-brightening the light over the span of a second or two. Also allows you to specify the brightness level to dim it to.
http://my.ip.goes.here:5000/<light>/blink/<color>/<count>/<brightness>
Blinks the light in a specific color, a given number of times. If multiple lights are present in a group, they will all blink sequentially.
http://my.ip.goes.here:5000/<light>/<color>
Sets a light to a specific color.
http://my.ip.goes.here:5000/<light>/<color>/<brightness>
Sets a light to a specific color with a specific brightness level.
http://my.ip.goes.here:5000/<light>/<color>/<brightness>/<seconds>/<otherBrightness>
Sets a light to a specific color with a specific brightness level, dimming or brightening it over time.
http://my.ip.goes.here:5000/<light>/on
Turns the light on.
http://my.ip.goes.here:5000/<light>/brightness/<brightness>
Sets a light to a specific brightness. You can also use + or - before your number to increase or decrease the brightness by that amount. For example, setting brightness to +10 will brighten the light by 10%.
http://my.ip.goes.here:5000/<light>/off
Turns the light off.
http://my.ip.goes.here:5000/<light>/toggle
Toggles the light.
http://my.ip.goes.here:5000/toggle
Toggles all lights. If a majority of the lights are on, it will turn all lights off, and vice versa.
http://my.ip.goes.here:5000/toggle/<color>
Toggles all lights. If a majority of the lights are on, it will turn all lights off, and vice versa.
http://my.ip.goes.here:5000/<light>/toggle/<color>
Toggles the light.
http://my.ip.goes.here:5000/<light>/rotate/<seconds>
Starts fading the light to different colors.
http://my.ip.goes.here:5000/<light>/rotate/stop
Stops color rotation for a given light.
Content type
Image
Digest
Size
497.9 MB
Last updated
over 4 years ago
docker pull johnthenerd/lightapi