Domoticz MQTT connection using Homie Convention
Posted: Sunday 24 November 2019 21:09
Hi All,
I've created a Python script that publishes Domoticz devices to MQTT using the Homie Convention (https://github.com/homieiot/convention).
Although it's still a raw 1st version, it seems to be running stable on my own install. There are probably devices in the wild that are not supported at this time. These devices will be reported on startup and excluded for MQTT publishing. Currently omong others, switches, dimmers, temperature, wind, uv, ozone, illuminance and thermostats are working. Adding additional devices should not be that difficult, due to the nature of the script.
It both publishes the states of the devices and makes them controllable through MQTT.
I've chosen the Homie convention, as this seems to be an effort to create an independent standard for MQTT IoT devices including support for auto discovery and configuration of exposed capabilities.
I'll attach the script to this post, so others can give it a go, and comment/adapt/improve the script.
Just a quick head-start: if you want to change the state of a device, you need to publish a message to the 'set' topic. (It's best to read the Homie convention for all the details.)
So for a switch published at:
homie/domoticz/1/switch - publishes the state (either On or Off)
To control the switch send On or Off to:
/homie/domoticz/1/switch/set
Oh, before I forget: Domoticz should be configured with the MQTT Client Gateway with LAN interface posting Domoticz messages using domoticz/out (flat format).
25/11/2019 UPDATE: Uploaded a new version, since the scipt failed to run on Linux due to a missing encoding definition.
On the RPi I needed to add the following libraries using pip3, additional libraries may be needed, as I've not tried on a clean install.
pip3 install requests
pip3 install paho-mqtt
Kind regards,
Jorg
I've created a Python script that publishes Domoticz devices to MQTT using the Homie Convention (https://github.com/homieiot/convention).
Although it's still a raw 1st version, it seems to be running stable on my own install. There are probably devices in the wild that are not supported at this time. These devices will be reported on startup and excluded for MQTT publishing. Currently omong others, switches, dimmers, temperature, wind, uv, ozone, illuminance and thermostats are working. Adding additional devices should not be that difficult, due to the nature of the script.
It both publishes the states of the devices and makes them controllable through MQTT.
I've chosen the Homie convention, as this seems to be an effort to create an independent standard for MQTT IoT devices including support for auto discovery and configuration of exposed capabilities.
I'll attach the script to this post, so others can give it a go, and comment/adapt/improve the script.
Just a quick head-start: if you want to change the state of a device, you need to publish a message to the 'set' topic. (It's best to read the Homie convention for all the details.)
So for a switch published at:
homie/domoticz/1/switch - publishes the state (either On or Off)
To control the switch send On or Off to:
/homie/domoticz/1/switch/set
Oh, before I forget: Domoticz should be configured with the MQTT Client Gateway with LAN interface posting Domoticz messages using domoticz/out (flat format).
25/11/2019 UPDATE: Uploaded a new version, since the scipt failed to run on Linux due to a missing encoding definition.
On the RPi I needed to add the following libraries using pip3, additional libraries may be needed, as I've not tried on a clean install.
pip3 install requests
pip3 install paho-mqtt
Kind regards,
Jorg