Skip to main content

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:

  1. Connect and subscribe to notifications on the read characteristic
  2. Write the reconnect packet
  3. Wait for a notification containing the ready marker
  4. Extract the session token from the notification
  5. Build and write the action packet (header + token + action body)
  6. Disconnect

License

MIT

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

pycasperglow-0.3.6.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycasperglow-0.3.6-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pycasperglow-0.3.6.tar.gz.

File metadata

  • Download URL: pycasperglow-0.3.6.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycasperglow-0.3.6.tar.gz
Algorithm Hash digest
SHA256 dda6337043d08c1ff5fd41c5538f9c6ed5faf3d62dcbbf31e1c045d0d78b740f
MD5 8e8cd14f4522a5b9aa6558fb680a1b6e
BLAKE2b-256 9bb461d46dfc677f654577202cd6b5ee1d57de58637f35d433267a80cf99d5cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycasperglow-0.3.6.tar.gz:

Publisher: publish.yml on mikeodr/pycasperglow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycasperglow-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: pycasperglow-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycasperglow-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c3eb70e4a977beacae7c9edee65143c197451f060b9f9ab61a587a50e4214467
MD5 2314c560f52b5440a7aa7be9e7fd72e5
BLAKE2b-256 b0a79e8bf05a2f3b114aa52cb622f408dc78fc61fc131099e21ddcbee0380ecb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycasperglow-0.3.6-py3-none-any.whl:

Publisher: publish.yml on mikeodr/pycasperglow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page