Skip to main content

OpenHab - MQTT Homie Convention

Abashiri, Japan

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

OpenHab for MQTT communication according to the MQTT HOMIE convention

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:

OpenHab for MQTT communication according to the MQTT HOMIE convention

As configured, the Thing comes with temperature Channel configured that we just have to assign to an Item:

OpenHab for MQTT communication according to the MQTT HOMIE convention

Create a new Item for the temperature channel:

OpenHab for MQTT communication according to the MQTT HOMIE convention

And just like this, our Item is receiving updates from the auto-configured Homie device:

OpenHab for MQTT communication according to the MQTT HOMIE convention

Navigate to Pages and click on the block where you would like to add the sensor read-out:

OpenHab for MQTT communication according to the MQTT HOMIE convention

We can add the Item to a page as a Cell with a Trend Line Item:

OpenHab for MQTT communication according to the MQTT HOMIE convention