This is an implementation of the Zencontrol TPI Advanced protocol, written in Python. This library has been written with three levels of abstraction:
- zencontrol.io: Implementation of the raw TPI Advanced UDP packet specification;
- zencontrol.api: Implementation of most TPI Advanced API commands and events;
- zencontrol.interface: An opinionated abstraction layer suitable for integration into smart building control software. It provides methods, objects, and callbacks for managing lights, groups, profiles, buttons, motion sensors, and system variables. This code is still undergoing significant refinement.
Built on top of this is an example application mqtt_bridge.py, which is a bridge to Home Assistant via MQTT. It reads settings from config.json and spams your console with lots of debug messages. To run this, ensure you have Python 3.11 (or later) installed, along with the following Python packages: aiomqtt, yaml, and colorama. Modify config.yaml as needed for your environment, then execute mqtt_bridge.py.
- Python 3.11 (or later)
- Controller firmware 2.2.11 (or later)
The following are the minimum steps necessary to run the MQTT bridge on a machine running a sufficiently modern version of Debian (including Ubuntu and Raspberry Pi OS):
# Update/Install packages:
sudo apt update
sudo apt upgrade -y
sudo apt install -y git python3-yaml python3-colorama python3-pip
pip3 install aiomqtt
# Download this code:
cd ~/Documents
git clone https://github.com/sjwright/zencontrol-python
cd zencontrol-python
# Edit config.yaml to suit your environment
cp examples/config-example.yaml examples/config.yaml
nano examples/config.yaml
# Run the MQTT bridge
cd examples
python3 mqtt_bridge.py
Be aware that many Linux distributions ship with old versions of python and it could require non-trivial steps to install a newer version. You can check your current python version by running python3 -V
Implemented but untested:
- Dealing with multiple controllers (I only have one controller)
- RGB+ and XY colour commands (I don't have any compatible lights)
- Numerical (absolute) instances (I don't have any such ECDs)
- Event filtering (I haven't tested it)
Not implemented:
- Any commands involving DMX, Control4, or virtual instances (I don't have licenses for any of these so I couldn't test them even if I wanted to, but the scaffolding is there if anyone wishes to add support)
- Any commands described in the documentation as "legacy" (they aren't useful)
The following TPI Advanced commands/events are incomplete:
- QUERY_DALI_COLOUR — This command is supposed to be able to return a light's current colour temperature, but it only returns correct values under some instances. If the temperature is changed by way of scene recall, this query returns wrong information. (A fix is anticipated soon)
- COLOUR_CHANGE_EVENT — This event is supposed to fire when a light's colour temperature changes, but it only does so under some circumstances. If the temperature is changed by way of scene recall, the event does not fire. (A fix is anticipated soon)
- Command to return a controller's MAC address used for multicast packets (There are other ways to get or infer the MAC access, but being able to query it directly would be ideal.)
- Command to list active system variables (As a workaround, you can query every number for its label. This assumes no system variables of interest are unlabelled.)
- Command to read an ambient light sensor's lux value. (As a workaround, you can target a light sensor to a system variable. Less elegant but it works.)
- Event notification for ambient light sensor lux values. (Same workaround as above.)