A comprehensive Python toolkit for Philips Hue Entertainment API
Project description
Hue Entertainment PyKit
Introduction
Unlock the full spectrum of Philips Hue lighting with the Hue Entertainment PyKit. This Python library simplifies connecting to the Hue Bridge and controlling lights with minimal latency, empowering developers to create dynamic and responsive lighting environments.
Motivation
Confronted with the complexity of the official Hue EDK and challenges in DTLS handshake implementation which many in the community had, Hue Entertainment PyKit was crafted to provide a straightforward, Python-centric approach to light control using the Philips Hue Entertainment API.
Quick Start
Installing
To install Hue Entertainment PyKit, ensure you have Python installed on your system, and then run the following command:
pip install hue-entertainment-pykit
Note: Python 3.13 and later are currently unsupported due to python-mbedtls not yet providing compatible wheels. This sucks cause last update was in second quarter of 2024 and it looks like there won't be any anymore.
Usage
To interact with your Philips Hue lights you can do:
Logging Configuration (Optional)
Hue Entertainment PyKit configures logging only for its own logger namespace
(hue_entertainment_pykit.*). It does not modify the root logger.
import logging
from hue_entertainment_pykit import setup_logs
# Enable library logging with the default formatter and handlers
setup_logs()
# Or customize the logging level (e.g., exclude DEBUG messages)
setup_logs(level=logging.INFO)
# You can also further customize logging by specifying the maximum log file size and the number of backup files
setup_logs(level=logging.INFO, max_file_size=1024 * 1024, backup_count=1)
# Each parameter is optional and comes with predefined default values
To log messages from your own application code in the same format, use a named logger under the same namespace:
import logging
logger = logging.getLogger("hue_entertainment_pykit.example")
logger.info("Example started")
If you prefer to use logging.info(...) (root logger), configure it separately:
import logging
logging.basicConfig(level=logging.INFO)
Silencing noisy third-party logs
Some dependencies (e.g. urllib3, zeroconf) may emit verbose DEBUG logs if
root logging is enabled. You can reduce noise like this:
import logging
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("zeroconf").setLevel(logging.WARNING)
Discovery (Optional)
Use only on your Local Area Network (LAN) to discover and fetch all Bridges that can be used then for streaming
from hue_entertainment_pykit import Discovery
discovery = Discovery()
# returns dict[str, Bridge] where the key is name of the bridge and value is the Bridge model with all important info for connecting to Entertainment API
bridges = discovery.discover_bridges()
Streaming
The Streaming service in Hue Entertainment PyKit provides thread-safe communication with Hue lights, ensuring smooth and uninterrupted interactions. To prevent connection timeouts, the service implements a keep-alive feature: if no command is sent for 9.5 seconds, the last message is automatically resent to maintain the connection.
Below is a streamlined example to set up and manage your streaming session:
import time
from hue_entertainment_pykit import create_bridge, Entertainment, Streaming
# Set up the Bridge instance with the all needed configuration
bridge = create_bridge(
identification="4abb74df-5b6b-410e-819b-bf4448355dff",
rid="d476df48-83ad-4430-a104-53c30b46b4d0",
ip_address="192.168.1.100",
swversion=1962097030,
username="8nuTIcK2nOf5oi88-5zPvV1YCt0wTHZIGG8MwXpu",
hue_app_id="94530efc-933a-4f7c-97e5-ccf1a9fc79af",
clientkey="B42753E1E1605A1AB90E1B6A0ECF9C51",
name="1st Bridge"
)
# Set up the Entertainment API service
entertainment_service = Entertainment(bridge)
# Fetch all Entertainment Configurations on the Hue bridge
entertainment_configs = entertainment_service.get_entertainment_configs()
# Add some Entertainment Area selection logic
# For the purposes of example I'm going to do manual selection
entertainment_config = list(entertainment_configs.values())[0]
# Set up the Streaming service
streaming = Streaming(
bridge, entertainment_config, entertainment_service.get_ent_conf_repo()
)
# Start streaming messages to the bridge
streaming.start_stream()
# Set the color space to xyb or rgb
streaming.set_color_space("xyb")
# Set input commands for the lights
# First three values in the tuple are placeholders for the color RGB8(int) or (in this case) XYB(float) and the last integer is light ID inside the Entertainment API
streaming.set_input((0.0, 0.63435, 0.3, 0)) # Light command for the first light
streaming.set_input((0.63435, 0.0, 0.3, 1)) # Light command for the second light
# ... Add more inputs as needed for additional lights and logic
# For the purpose of example sleep is used for all inputs to process before stop_stream is called
# Inputs are set inside Event queue meaning they're on another thread so user can interact with application continuously
time.sleep(0.1)
# Stop the streaming session
streaming.stop_stream()
Replace the placeholders in the set_input method with actual light IDs and the color and brightness values you intend to use. The start_stream method initiates the streaming session, set_color_space configures the color space, and stop_stream terminates the session.
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 hue_entertainment_pykit-0.9.4.tar.gz.
File metadata
- Download URL: hue_entertainment_pykit-0.9.4.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bd495235d91c78d7e3cf01a1f12f173a877ae41092beb342c1a0aee36e96cd6
|
|
| MD5 |
cc4882cf051942481b759c93327c85aa
|
|
| BLAKE2b-256 |
70190014ae39fe19bfd308142f77a450216848fc933059e213267b503acb46f6
|
File details
Details for the file hue_entertainment_pykit-0.9.4-py3-none-any.whl.
File metadata
- Download URL: hue_entertainment_pykit-0.9.4-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6149090c3bc9fb03e6ce21998bd6910155b875231ab8c8b8f0e6ef56bcdec08b
|
|
| MD5 |
e2dfaf5d7b04a1527a05f7dde9a7fa02
|
|
| BLAKE2b-256 |
6ce6fb807bec5aa20e8c3274ff9a1df79e87c88202b8e4fff8d648685927ea2e
|