Skip to main content

Hue2MQTT

Python Hue to MQTT Bridge

What and Why?

Hue2MQTT lets you control your Hue setup using MQTT and publishes the current state in real-time.

  • Python 3.8+ with type hints and asyncio
  • Uses the excellent aiohue library to communicate with Hue.
  • Control your lights using MQTT
  • Receive live events (i.e button pushes, motion sensors) in real-time.
  • No polling your Hue Bridge for changes
  • IPv6 Support

Configuration

Hue2MQTT is configured using hue2mqtt.toml.

# Hue2MQTT Default Config File

[mqtt]
# use host.docker.internal to connect to mqtt broker installed on docker host
# host = "host.docker.internal"
host = "::1"
port = 1883
enable_tls = false
force_protocol_version_3_1 = true

enable_auth = false
username = ""
password = ""

topic_prefix = "hue2mqtt"

[hue]
ip = "192.0.2.2"  # or IPv6: "[2001:db0::1]"
username = "some secret here"

If you do not know the username for your bridge, find it using hue2mqtt --discover.

Running Hue2MQTT

Usually, it is as simple as running hue2mqtt.

Usage: hue2mqtt [OPTIONS]

  Main function for Hue2MQTT.

Options:
  -v, --verbose
  -c, --config-file PATH
  --discover
  --help                  Show this message and exit.

Bridge Status

The status of Hue2MQTT is published to hue2mqtt/status as a JSON object:

{"online": true, "bridge": {"name": "Philips Hue", "mac_address": "ec:b5:fa:ab:cd:ef", "api_version": "1.45.0"}}

If online is false, then all other information published by the bridge should be assumed to be inaccurate.

The bridge object contains information about the Hue Bridge, if available.

Getting information about Hue

Information about the state of Hue is published to MQTT as retained messages. Messages are re-published when the state changes.

Lights

Information about lights is published to hue2mqtt/light/{{UNIQUEID}} where UNIQUEID is the Zigbee MAC of the light.

e.g hue2mqtt/light/00:17:88:01:ab:cd:ef:01-02

{"id": 1, "name": "Lounge Lamp", "uniqueid": "00:17:88:01:ab:cd:ef:01-02", "state": {"on": false, "alert": "none", "bri": 153, "ct": 497, "effect": "none", "hue": 7170, "sat": 225, "xy": [0, 0], "transitiontime": null, "reachable": true, "color_mode": null, "mode": "homeautomation"}, "manufacturername": "Signify Netherlands B.V.", "modelid": "LCT012", "productname": "Hue color candle", "type": "Extended color light", "swversion": "1.50.2_r30933"}

Groups

A group represents a group of lights, referred to as Rooms and Zones in the Hue app.

Information about lights is published to hue2mqtt/group/{{GROUPID}} where GROUPID is an integer.

hue2mqtt/group/3 {"id": 3, "name": "Lounge", "lights": [24, 21, 20, 3, 5], "sensors": [], "type": "Room", "state": {"all_on": false, "any_on": false}, "group_class": "Living room", "action": {"on": false, "alert": "none", "bri": 153, "ct": 497, "effect": "none", "hue": 7170, "sat": 225, "xy": [0, 0], "transitiontime": null, "reachable": null, "color_mode": null, "mode": null}}

Sensors

Sensors represent other objects in the Hue ecosystem, such as switches and motion sensors. There are also a number of "virtual" sensors that the Hue Hub uses to represent calculated values (e.g daylight), but these are ignored by Hue2MQTT.

Information about sensors is published to hue2mqtt/sensor/{{UNIQUEID}} where UNIQUEID is the Zigbee MAC of the device.

e.g hue2mqtt/sensor/00:17:88:01:ab:cd:ef:01-02

Switch

{"id": 10, "name": "Lounge switch", "type": "ZLLSwitch", "modelid": "RWL021", "manufacturername": "Signify Netherlands B.V.", "productname": "Hue dimmer switch", "uniqueid": "00:17:88:01:ab:cd:ef:01-02", "swversion": "6.1.1.28573", "state": {"lastupdated": "2021-07-10T11:37:58", "buttonevent": 4002}, "capabilities": {"certified": true, "primary": true, "inputs": [{"repeatintervals": [800], "events": [{"buttonevent": 1000, "eventtype": "initial_press"}, {"buttonevent": 1001, "eventtype": "repeat"}, {"buttonevent": 1002, "eventtype": "short_release"}, {"buttonevent": 1003, "eventtype": "long_release"}]}, {"repeatintervals": [800], "events": [{"buttonevent": 2000, "eventtype": "initial_press"}, {"buttonevent": 2001, "eventtype": "repeat"}, {"buttonevent": 2002, "eventtype": "short_release"}, {"buttonevent": 2003, "eventtype": "long_release"}]}, {"repeatintervals": [800], "events": [{"buttonevent": 3000, "eventtype": "initial_press"}, {"buttonevent": 3001, "eventtype": "repeat"}, {"buttonevent": 3002, "eventtype": "short_release"}, {"buttonevent": 3003, "eventtype": "long_release"}]}, {"repeatintervals": [800], "events": [{"buttonevent": 4000, "eventtype": "initial_press"}, {"buttonevent": 4001, "eventtype": "repeat"}, {"buttonevent": 4002, "eventtype": "short_release"}, {"buttonevent": 4003, "eventtype": "long_release"}]}]}}

Light Sensor

{"id": 5, "name": "Hue ambient light sensor 1", "type": "ZLLLightLevel", "modelid": "SML001", "manufacturername": "Signify Netherlands B.V.", "productname": "Hue ambient light sensor", "uniqueid": "00:17:88:01:04:b7:b5:20-02-0400", "swversion": "6.1.1.27575", "state": {"lastupdated": "2021-07-10T12:28:17", "dark": true, "daylight": false, "lightlevel": 14606}, "capabilities": {"certified": true, "primary": false}}

Controlling Hue

Lights and Groups can be controlled by publishing objects to the hue2mqtt/light/{{UNIQUEID}}/set or hue2mqtt/group/{{GROUPID}}/set topics.

The object should be a JSON object containing the state values that you wish to change.

{"on": "true"}

Docker

Included is a basic Dockerfile and docker-compose example.

Connections to Docker Host

To establish a MQTT-Connection to the Docker Host (localhost is the docker instance) use host.docker.internal inside hue2mqtt.toml

host = "host.docker.internal"

Metadata

Release files for hue2mqtt 0.4.2

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

Source distribution (sdist)

Source distribution for hue2mqtt 0.4.2
File Size Uploaded Provenance Actions
hue2mqtt-0.4.2.tar.gz 13.3 kB Without provenance Details for hue2mqtt-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 27.4 kB

Release files / hue2mqtt-0.4.2.tar.gz

Download URL hue2mqtt-0.4.2.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c7c515c8bb715f8c8b542616ca10652bb61138e48d0937978035596e217f739
BLAKE2b-256 checksum
How to use checksums
8aff107553ce24ef83d6d23d75a1672be2ee6acf5ee80008ee2488c39f695cf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/22.1.0

Release files / hue2mqtt-0.4.2-py3-none-any.whl

Download URL hue2mqtt-0.4.2-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6059f8d57a60832c55c09abb070e2c6102f15f0e13b60b7d3a69a504ca98271a
BLAKE2b-256 checksum
How to use checksums
eb3c198cd6e8f0e97bc4406554c1c3055a32c29b39fa98397f881f9aec684741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/22.1.0

Security for hue2mqtt 0.4.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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