Rocka84 / pushing-hue

10 stars 2 forks source link

Considering mqtt as trigger option #5

Open Otamay opened 3 years ago

Otamay commented 3 years ago

Hue bridge communications happens within its own mqtt broker (mosquitto) running on default port 1883. When a device changes its status, a payload is published on its mqtt broker under the device own topic (e.g. dt/clip/grouped_light/c72e5c9f-6c87-4163-85ad-81801d565f6e topic for a grouped light).

Adding iptables -I INPUT -p tcp --dport 1883 --syn -j ACCEPT to /etc/rc.local opens the port for remote subscribing. Now from any mqtt client we can subscribe to any topic to get notified when the corresponding device status has changed. E.g. with mosquitto cmdline client we can run:

mosquitto_sub -v -h IP_OF_HUE_BRIDGE -t "#"

to get a notification every time a light, group of lights, or sensor has changed its status. The message in the topic is in binary form which is unknown to me at the moment, hopefully someone could help to decrypt it?

sh00bx commented 3 years ago

Love the idea of making MQTT accessible from outside - Have you gotten anywhere with it?

Besides the binary messages there's this interesting topic: cmd/clip/event/publish Which publishes state changes of all connected devices (example message below). I managed to get these messages to home assistant using the MQTT plugin, and am currently trying to find a way to map the state changes to entities. Will update in case I succeed :)

{ "data": [ { "creationtime": "2021-04-14T18:00:46Z", "data": [ { "dimming": { "brightness": 50 }, "id": "104b88d7-9322-43db-ba48-a77248f06fab", "id_v1": "/lights/4", "type": "light" } ], "id": "3ccd7574-5c44-44b4-bdb4-ad967d51f2c7", "type": "update" } ], "metadata": [ { "key": "event_origin", "value": "zigbee" } ] }

sh00bx commented 3 years ago

Here's my status on this. I was able to create a sensor entity in HA which shows the attributes contained in the mqtt message:

grafik

`sensor:

sh00bx commented 3 years ago

FYI: I managed to get utilize the MQTT channel for my Dimmer Switches. Documented below - feel free to join the party :) https://community.home-assistant.io/t/native-mqtt-push-updates-from-hue-hub/299504