Async Python library for controlling Casper Glow lights via BLE
Project description
pycasperglow
Async Python library for controlling Casper Glow lights via BLE.
Built on bleak and designed for use as a backend for Home Assistant integrations.
Installation
pip install pycasperglow
Usage
Discover devices
import asyncio
from pycasperglow import discover_glows
async def main():
devices = await discover_glows(timeout=10.0)
for device in devices:
print(f"{device.name} ({device.address})")
asyncio.run(main())
Control a light
import asyncio
from pycasperglow import CasperGlow, discover_glows
async def main():
devices = await discover_glows()
if not devices:
print("No Casper Glow found")
return
glow = CasperGlow(devices[0])
await glow.turn_on()
await asyncio.sleep(5)
await glow.turn_off()
asyncio.run(main())
Home Assistant integration
When used within Home Assistant's Bluetooth stack, pass the managed BleakClient to avoid connection conflicts:
glow = CasperGlow(ble_device, client=bleak_client)
await glow.turn_on()
When an external client is provided, pycasperglow will not disconnect it — the caller retains ownership.
API
CasperGlow(ble_device, client=None)
Async client for a single Casper Glow light.
turn_on()— Turn the light on.turn_off()— Turn the light off.name— Device name (property).address— Device BLE address (property).
discover_glows(timeout=10.0)
Scan for Casper Glow devices. Returns a list of BLEDevice objects. For standalone use — Home Assistant uses its own discovery.
is_casper_glow(device, adv)
Returns True if a BLEDevice and AdvertisementData match a Casper Glow (by service UUID or name prefix).
Exceptions
| Exception | Description |
|---|---|
CasperGlowError |
Base exception |
ConnectionError |
Connection or handshake failure |
HandshakeTimeoutError |
Device did not become ready in time |
CommandError |
Failed to send a command |
Examples
See the examples/ directory for runnable scripts. To discover nearby Casper Glow lights and turn them on:
python examples/discover_and_turn_on.py
Development
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
Run checks:
pytest tests/ -v --cov=pycasperglow
mypy src/ --strict
ruff check src/ tests/
Protocol
The BLE protocol was partially reverse-engineered from dengjeffrey/casper-glow-pro. The connection flow is:
- Connect and subscribe to notifications on the read characteristic
- Write the reconnect packet
- Wait for a notification containing the ready marker
- Extract the session token from the notification
- Build and write the action packet (header + token + action body)
- Disconnect
License
MIT
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
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 pycasperglow-0.3.3.tar.gz.
File metadata
- Download URL: pycasperglow-0.3.3.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d360ea288de1f6ab91d5d6ea345b8a192c71554e35771138367276cf9f14e6d
|
|
| MD5 |
d700a040f663a13b08dcef41e4d6ba8f
|
|
| BLAKE2b-256 |
7f07f4d95346bc13afb4ecfc788fb5ae13070cc9155fcff0db3472b8251df370
|
Provenance
The following attestation bundles were made for pycasperglow-0.3.3.tar.gz:
Publisher:
publish.yml on mikeodr/pycasperglow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycasperglow-0.3.3.tar.gz -
Subject digest:
6d360ea288de1f6ab91d5d6ea345b8a192c71554e35771138367276cf9f14e6d - Sigstore transparency entry: 976602980
- Sigstore integration time:
-
Permalink:
mikeodr/pycasperglow@3b05071792e0ba33611829f300160b3555b6a21f -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/mikeodr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3b05071792e0ba33611829f300160b3555b6a21f -
Trigger Event:
push
-
Statement type:
File details
Details for the file pycasperglow-0.3.3-py3-none-any.whl.
File metadata
- Download URL: pycasperglow-0.3.3-py3-none-any.whl
- Upload date:
- Size: 11.6 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 |
cde8e891c4551b412ab4029800fd880dc292b4bce02c0c0ba176f1db856b8516
|
|
| MD5 |
9423ae6bc834683cd251dbb982249b65
|
|
| BLAKE2b-256 |
5e352fb42a0e9069d9291b8574eec85df1bc1b68c008553af47e2ac0a282524a
|
Provenance
The following attestation bundles were made for pycasperglow-0.3.3-py3-none-any.whl:
Publisher:
publish.yml on mikeodr/pycasperglow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycasperglow-0.3.3-py3-none-any.whl -
Subject digest:
cde8e891c4551b412ab4029800fd880dc292b4bce02c0c0ba176f1db856b8516 - Sigstore transparency entry: 976602982
- Sigstore integration time:
-
Permalink:
mikeodr/pycasperglow@3b05071792e0ba33611829f300160b3555b6a21f -
Branch / Tag:
refs/tags/v0.3.3 - Owner: https://github.com/mikeodr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3b05071792e0ba33611829f300160b3555b6a21f -
Trigger Event:
push
-
Statement type: