Control USB connected LED lights, like a human.
Project description
BusyLight for Humans™ gives you control of USB attached LED lights from a variety of vendors. Lights can be controlled via the command-line, using a HTTP API or imported directly into your own python project.
Six Lights Attached to One Host
Back to Front, Left to Right
BlyncLight, BlyncLight Plus, Busylight
Blink(1), Flag, BlinkStick
Features
- Control lights from the command-line.
- Control lights via a Web API.
- Individually addresable lights.
- Supports Five Vendors & Multiple Models:
- Works on MacOS, Linux, probably Windows and BSD too!
- Tested extensively on Raspberry Pi 3b+, Zero W and 4
If you have a USB light that's not on this list, please open an issue with the make and model device you want supported.
Basic Install
$ python3 -m pip install busylight-for-humans
Web API Install
Installs uvicorn
and FastAPI
in addition to busylight
:
$ python3 -m pip install busylight-for-humans[webapi]
Linux Post-Install Activities
Linux controls access to USB devices via the udev subsystem. By default it denies non-root users access to devices it doesn't recognize. I've got you covered!
You'll need root access to configure the udev rules:
$ busylight udev-rules -o 99-busylights.rules
$ sudo cp 99-busylights.rules /etc/udev/rules.d
$ sudo udevadm control -R
$ # unplug/plug your light
$ busylight on
Command-Line Examples
$ busylight on # light turns on green
$ busylight on red # now it's shining a friendly red
$ busylight on 0xff0000 # still red
$ busylight on #00ff00 # now it's blue!
$ busylight blink # it's slowly blinking on and off with a red color
$ busylight blink green fast # blinking faster green and off
$ busylight --all on # turn all lights on green
$ busylight --all off # turn all lights off
HTTP API Examples
First start the busylight
API server:
$ busylight serve
INFO: Started server process [20189]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8888 (Press CTRL+C to quit)
The API is fully documented and available @ https://localhost:8888/redoc
Now you can use the web API endpoints which return JSON payloads:
$ curl -s http://localhost:8888/1/lights
...
$ curl -s http://localhost:8888/1/lights/on | jq
{
"light_id": 0,
"action": "on",
"color": "green"
}
$ curl -s http://localhost:8888/1/lights/off | jq
{
"light_id": 0,
"action": "off"
}
$ curl -s http://localhost:8888/1/light/0/on/purple | jq
{
"light_id": 0,
"action": "on",
"color": "purple"
}
$ curl -s http://localhost:8888/1/light/0/off | jq
{
"light_id": 0,
"action": "off"
}
$ curl -s http://localhost:8888/1/lights/on | jq
{
"light_id": "all",
"action": "on",
"color": "green"
}
$ curl -s http://localhost:8888/1/lights/off | jq
{
"light_id": "all",
"action": "off"
}
$ curl -s http://localhost:8888/1/lights/rainbow | jq
{
"light_id": "all",
"action": "effect",
"name": "rainbow"
}
Code Examples
Simple Case: Turn On a Single Light
In this example, we pick an Embrava Blynclight to activate with the color white.
from busylight.lights.embrava import Blynclight
light = Blynclight.first_light()
light.on((255, 255, 255))
Slightly More Complicated
The busylight
package includes a manager class that great for
working with multiple lights or lights that require a little
more direct intervention like the Kuando Busylight series.
from busylight.manager import LightManager, ALL_LIGHTS
from busylight.effects import rainbow
manager = LightManager()
for light in manager.lights:
print(light.name)
manager.apply_effect_to_light(ALL_LIGHTS, rainbow)
...
manager.lights_off(ALL_LIGHTS)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for busylight-for-humans-0.8.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a969a6f6a99f3abf8f9c48fbe2eb0ebc23e2726d04262ea86d1312509145fe |
|
MD5 | c634950bae8331f5220f8b569c90e7a5 |
|
BLAKE2b-256 | 1be8a88715482339e36b1d6650f43d9943f39a40ec67fec1557361b28a94144c |
Hashes for busylight_for_humans-0.8.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41f266a1ec8b27690af8554944bbd02006a4b05d167f652a95d2a941e4e614b |
|
MD5 | 62b0db0eaae82ddb973b952b6365bcb9 |
|
BLAKE2b-256 | 7785569d27db7598c065891b96265455db238b74a7e902cd37fef24174227afe |