Skip to main content

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():
    async for device in discover_glows(timeout=10.0):
        print(f"{device.name} ({device.address})")

asyncio.run(main())

Control a light

import asyncio
from pycasperglow import CasperGlow, discover_glows

async def main():
    glow = None
    async for device in discover_glows():
        glow = CasperGlow(device)
        break
    if glow is None:
        print("No Casper Glow found")
        return
    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.

Method / Property Description
turn_on() Turn the light on
turn_off() Turn the light off
pause() Pause the active dimming sequence
resume() Resume a paused dimming sequence
set_brightness_and_dimming_time(level, dimming_time_minutes) Set brightness (60–100 %) and dimming duration (15, 30, 45, 60, or 90 min). Both required.
query_state() Query current device state; returns GlowState
handshake(*, max_attempts=4) Test connectivity without sending a command. Raises ConnectionError (or HandshakeTimeoutError) on failure; pass max_attempts=1 when probing unconfirmed devices
register_callback(cb) Register a callback invoked on every state update
state Current GlowState property (last known, or default)
name Device name (property)
address BLE address (property)

GlowState

Dataclass returned by query_state() and passed to registered callbacks.

Field Type Description
is_on bool | None True when on, False when off
is_paused bool | None True when dimming is paused
is_charging bool | None True when plugged in to charger
battery_level BatteryLevel | None Discrete battery level
brightness_level int | None Last-set brightness % (not reported by device)
dimming_time_minutes int | None Remaining dimming time (from device)
configured_dimming_time_minutes int | None Total configured duration

BatteryLevel

IntEnum with four members: PCT_25, PCT_50, PCT_75, PCT_100. Each has a .percentage property returning 25, 50, 75, or 100.

discover_glows(timeout=10.0)

Scan for Casper Glow devices. Async generator that yields BLEDevice objects as they are found. 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: the local name starts with "Jar" and the advertisement includes manufacturer data with company ID 0xFFFF.

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/ tests/ examples/ --strict
ruff check src/ tests/ examples/

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

Metadata

Release files for pycasperglow 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycasperglow 1.3.0
File Size Uploaded Provenance Actions
pycasperglow-1.3.0.tar.gz 33.5 kB With provenance Details for pycasperglow-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycasperglow 1.3.0
File Interpreter ABI Platform Actions
pycasperglow-1.3.0-py3-none-any.whl Python 3 none any Details for pycasperglow-1.3.0-py3-none-any.whl

Total release size: 47.7 kB

Release files / pycasperglow-1.3.0.tar.gz

Download URL pycasperglow-1.3.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b92b4404c7ed470a284df114f1f7fa39048324c0315a18af7c2fb12296890062
BLAKE2b-256 checksum
How to use checksums
ff7094b0e2f7ffe621f1728abccc19d1d9d375118cc51428f5864a6c84af4092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / pycasperglow-1.3.0-py3-none-any.whl

Download URL pycasperglow-1.3.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25d99daef6995600084f20aa02161a4d813b71df4b5285836a91d22c4520b5a0
BLAKE2b-256 checksum
How to use checksums
42619778d66be0e445d1099224533c0353a4f748b22380da55e86b91be1b8c07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for pycasperglow 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pycasperglow-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page