Skip to main content

Async Python client for the Philips Hue Entertainment streaming API (DTLS-PSK + HueStream).

Project description

hue-entertainment

Async Python client for the Philips Hue Entertainment streaming API.

It pairs with a Hue bridge, discovers entertainment areas, and streams colour frames to the lights over DTLS 1.2 PSK using the HueStream protocol with minimal latency. It works with both the Hue V2 ("square") bridge and the Hue Pro bridge.

The DTLS 1.2 PSK handshake, record layer and HueStream encoder are pure Python on top of cryptography — no openssl subprocess, no C bindings, no other DTLS dependency. Blocking socket I/O is confined to a dedicated sender thread, so it never blocks your asyncio event loop.

It powers the Hue Entertainment plugin (the Sendspin bridge) in Music Assistant and the ambilight-hue-pro-bridge.

What it provides

  • Bridge discovery — find Hue bridges on the LAN via mDNS (discover_bridges).
  • Pairing — create an application key and the DTLS client key (HueEntertainmentAPI.pair).
  • Areas — list a bridge's entertainment configurations with their channels and positions.
  • Streaming — start/stop an entertainment stream and push per-channel colours at up to ~50 Hz.
  • EntertainmentSession — a high-level async facade that opens the stream on demand, runs the blocking DTLS work in an executor, enforces the bridge's single-active-stream constraint, and tears the stream down after inactivity.
  • Works with the V2 and Pro bridges; dependencies are aiohttp, cryptography and zeroconf.

What you can build with it

Anything that drives Hue lights from a fast colour source — screen / Ambilight sync, music visualisers, games, rich notifications, or your own virtual bridge — without the Hue Sync hardware.

Planned extensions

  • HueStream v1 framing and the CIE xy colour space (currently HueStream v2 / RGB).

Install

pip install hue-entertainment

Requires Python 3.11+. Runtime dependencies: aiohttp, cryptography, zeroconf.

Usage

import asyncio

from hue_entertainment import EntertainmentSession, HueEntertainmentAPI, LightColorCommand


async def main() -> None:
    host = "192.168.1.50"

    # One-time pairing (press the bridge link button first):
    api = HueEntertainmentAPI(host)
    creds = await api.pair()  # {"username": ..., "clientkey": ...}
    await api.close()

    # Stream to an entertainment area:
    session = EntertainmentSession(host, creds["username"], creds["clientkey"])
    areas = await session.get_entertainment_areas()
    area = areas[0]

    await session.start(area.id)  # activates the area + opens the DTLS stream
    try:
        # Drive frames at your own rate (~25-50 Hz). One command per channel.
        for _ in range(250):
            session.send(
                [LightColorCommand(channel_id=ch.channel_id, red=65535) for ch in area.channels]
            )
            await asyncio.sleep(1 / 50)
    finally:
        await session.aclose()


asyncio.run(main())

API

  • HueEntertainmentAPI(host, app_key=None) — low-level CLIP v2 wrapper: pair(), get_entertainment_areas(), start_entertainment(area_id), stop_entertainment(area_id), get_bridge_id(), close().
  • HueDtlsStreamer() — low-level DTLS/HueStream streamer: connect(host, username, clientkey, area_id) (blocking — run in an executor), send_colors([...]), disconnect(), is_connected.
  • EntertainmentSession(host, app_key, client_key, *, idle_timeout=10.0) — the recommended high-level facade: on-demand start(area_id), non-blocking send(...), stop() / aclose(), automatic idle teardown, and enforcement of the bridge's single-active-stream constraint. The blocking DTLS work runs in an executor for you.
  • ModelsEntertainmentArea, LightChannel, LightColorCommand.

LightColorCommand carries 16-bit RGB; the encoder emits the duplicated-byte HueStream v2 format and lets the bridge gamut-map per light.

Development

scripts/setup.sh
pre-commit run --all-files
pytest

License

Apache 2.0

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

hue_entertainment-0.1.1.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

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

hue_entertainment-0.1.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file hue_entertainment-0.1.1.tar.gz.

File metadata

  • Download URL: hue_entertainment-0.1.1.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hue_entertainment-0.1.1.tar.gz
Algorithm Hash digest
SHA256 070272b80fa84d9f7e4042d48df22f77722650c08fbd55f31627476a0af67c06
MD5 3c63de28c37919936ebf99f992800d37
BLAKE2b-256 8f0ef6f524dc342716ef2cca0d2fcce382a0fe317c39b73a36b083304cbb2cd1

See more details on using hashes here.

File details

Details for the file hue_entertainment-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hue_entertainment-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e64bed3da49806e215d77b67825f15c3369dac050bf9492fa3a432034f56ec07
MD5 f4867a7a6c754ecfa767a0464edaa065
BLAKE2b-256 4827ba28617d918b6ed55db8f8fa6ffc1023b2037e91405b0485438700aa2588

See more details on using hashes here.

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