OpenHab - MQTT Homie Convention
Communication according to the MQTT HOMIE Convention
The Homie convention defines a standardized way of how IoT devices and services announce themselves and their data on the MQTT broker. It is thereby a crucial aspect on top of the MQTT protocol for automatic discovery, configuration and usage of devices and services.
Devices that follow the Homie convention 3.x and better are auto-discovered and represented by this binding and the Homie Thing.
Details of the homie convention are available here Homie IoT.
I want to use OpenHab 3 to explore how to configure devices using the Homie Convention with the goal of adding this feature to INSTAR MQTT cameras. I already set-up the OpenHab MQTT Binding which supports the convention. So all I have to do is to add a few configuration topics to register a Homie Device with our MQTT broker using the MQTT Explorer:
# Thing Definition
homie/TestDevices/$homie → 4.0.0
homie/TestDevices/$name → This is a Test
homie/TestDevices/$state → ready # init,ready,disconnected,sleeping,lost,alert
homie/TestDevices/$extensions → ''
homie/TestDevices/$nodes → my_thermostat
# Channel Definition
homie/TestDevices/my_thermostat/$name → My Thermostat
homie/TestDevices/my_thermostat/$properties → temperature
# Channel Properties
homie/TestDevices/my_thermostat/temperature → 22
homie/TestDevices/my_thermostat/temperature/$name → Temperature
homie/TestDevices/my_thermostat/temperature/$unit → °C
homie/TestDevices/my_thermostat/temperature/$datatype → integer # integer, float, boolean, string, enum, color
homie/TestDevices/my_thermostat/temperature/$settable → true
It is important to add the retain flag to all topics. Otherwise the device will not be picked up by the Homie service!
Adding a Thing
Starting up OpenHab I already see that a new Thing was discovered and only needs to be added:
As configured, the Thing comes with temperature Channel configured that we just have to assign to an Item:
Create a new Item for the temperature channel:
And just like this, our Item is receiving updates from the auto-configured Homie device:
Navigate to Pages and click on the block where you would like to add the sensor read-out:
We can add the Item to a page as a Cell with a Trend Line Item: