Control Daybetter RGB LED strips over BLE
Project description
daybetter-led-strip
Python package to control Daybetter RGB LED strips over BLE. Uses bleak.
Installation
daybetter-led-strip is on PyPI
$ pip install daybetter-led-strip
Usage
The DaybetterLedStrip constructor only requires the device MAC address. After that, the actual underlying device and advertisment data can be updated any number of times using .update_device. If the device disconnects for any reason, it will not reconnect.
from bleak import BleakScanner
from daybetter_led_strip import DaybetterLedStrip
from daybetter_led_strip.const import SERVICE_DISCOVERY
device = await BleakScanner.find_device_by_filter(lambda _device, data: SERVICE_DISCOVERY in data.service_uuids)
led_strip = DaybetterLedStrip(device.address)
await led_strip.update_device(device, None)
# turn on
await led_strip.set_power(True)
await asyncio.sleep(1)
await led_strip.set_color((255, 0, 0))
await led_strip.set_power(False)
# Must be called when done using
await led_strip.disconnect()
A complete example program is provided in examples/test.py.
This package was created for use in Home Assistant, which may explain some of the API choices.
Protocol
Communication with the LED strip is done over BLE.
The light strip exposes two services: the generic access profile w/ the device name, and a custom "LED control service" (0xe031).
During discovery, the device also advertises itself with a third service (0xc031) for identification.
The LED control service has a read characteristic (0xf031) and a write characteristic (0xa031). As far as I can tell, the read characteristic cannot actually be read directly. Rather, if notifications are enabled on this service, the device will push updates about its state at various times.
Write Data Format
Commands written to the write characteristic have the following format.
- The byte
0xA0(referred to in the app source code as "APP_TO_DEVICE") - The command ID. (1 byte)
- The length of the entire message, not including the checksum. (1 byte)
= len(payload) + 3 - The payload for this command
- The little-endian CRC16 MODBUS checksum of the rest of the message.
Commands
| Command | ID | Payload Description |
|---|---|---|
| Get status | 0x10 |
0x00Results in status payload below being sent on notify |
| Set power | 0x11 |
0x01 (on) or 0x00 (off) |
| Show effect | 0x12 |
One of the effect bytes listed below |
| Set brightness | 0x13 |
A byte representing the brightness, from 0 (0x00) to 100 (0x64). Brightness 0 still has the LEDs slightly on |
| Set color | 0x15 |
3 bytes, in RGB order |
Example command (set to red): A0 15 06 FF 00 00 25 C0
Notify/read data format
The payloads received over notify have a similar structure as the write commands:
- The byte
0xA1("DEVICE_TO_APP") - Command ID
- Length of entire message excluding checksum
- Payload
- LE Checksum
Received "commands"
When any of the above write commands are written to the characteristic successfully, the device responds with a message with the same command ID and 0x01 for the payload.
For instance, the above color command would result in A1 15 04 01 F1 1C
When the strip is turned on/off from the IR remote, a message with command ID 0x10 and the payload 00 01 01 64 32 32 ff 31 2d f0 00 00 00 00 (off) or 01 01 01 64 32 32 ff 31 2d f0 00 00 00 00. The first byte indicates the on/off status, but I don't know what the rest means. It seems unrelated to the color of the light.
Running the "get status" command also results in this being sent.
Effects
Note: the brightness can be changed during the following effects. Lower brightnesses result in blinking happening faster, likely because there is a smaller range of brightnesses to interpolate between.
RGB: just red/green/blue
All preset colors: red/green/blue/yellow/teal/purple/white
0x02..0x08: show preset colors0x09: switch RGB abruptly, no transition0x0A: switch all preset colors0x0B: fade between colors quickly0x0C: fade between colors slowly0x0D..0x13: blink individual preset colors0x14: fade red/green0x15: fade red/blue0x16: fade green/blue0x17: flash all preset colors0x18..0x1E: flash individual preset colors0x1F: strobe RGB0x20: strobe all colors
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file daybetter_led_strip-0.2.1.tar.gz.
File metadata
- Download URL: daybetter_led_strip-0.2.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7e9a1a4d412ac5f2686f533e797ce6ba037e410e1b9adc7cfeb93e29f2bbf3e
|
|
| MD5 |
997f8ed5195ab6602aeb410d95b86bc4
|
|
| BLAKE2b-256 |
7fcc7a84cb9275bdb44b25cbb36834f08f863e61d8fcb6a72cfe7b10cdc7647b
|
Provenance
The following attestation bundles were made for daybetter_led_strip-0.2.1.tar.gz:
Publisher:
release.yml on grimsteel/daybetter-led-strip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
daybetter_led_strip-0.2.1.tar.gz -
Subject digest:
a7e9a1a4d412ac5f2686f533e797ce6ba037e410e1b9adc7cfeb93e29f2bbf3e - Sigstore transparency entry: 782305011
- Sigstore integration time:
-
Permalink:
grimsteel/daybetter-led-strip@55863df82e85b9f251d160c96a55f172e73f8467 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/grimsteel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@55863df82e85b9f251d160c96a55f172e73f8467 -
Trigger Event:
push
-
Statement type:
File details
Details for the file daybetter_led_strip-0.2.1-py3-none-any.whl.
File metadata
- Download URL: daybetter_led_strip-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5490022e0810db41e9428e4bee9a80ff9e29213f62b9fd171c25047f8bc3d736
|
|
| MD5 |
ea50d08e0241bd9ba86a5eb758832ad8
|
|
| BLAKE2b-256 |
0edf3d6db4ef6f643d636ab86694a6384b215966cc3dfefe1606fe6e958ca62e
|
Provenance
The following attestation bundles were made for daybetter_led_strip-0.2.1-py3-none-any.whl:
Publisher:
release.yml on grimsteel/daybetter-led-strip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
daybetter_led_strip-0.2.1-py3-none-any.whl -
Subject digest:
5490022e0810db41e9428e4bee9a80ff9e29213f62b9fd171c25047f8bc3d736 - Sigstore transparency entry: 782305012
- Sigstore integration time:
-
Permalink:
grimsteel/daybetter-led-strip@55863df82e85b9f251d160c96a55f172e73f8467 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/grimsteel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@55863df82e85b9f251d160c96a55f172e73f8467 -
Trigger Event:
push
-
Statement type: