How to use homie convention in openhab for auto discovery ? (with example code)

Home automation using esp32 openhab using esp32 openhab homie openhab homie convention

 How to use homie convention in openhab for auto discovery

 I hope you  have a basic idea about openhab installation and initial configuration so here i would like to explain my understanding about  how to enable auto-discovery in openhab using homie convention

 

Requirements 

 Basic knowledge about  :


 What is homie convention?

               Homie convention is nothing but a standardized format for communicating with MQTT broker. we know that MQTT is a messaging protocol in which each device in the network is is connected to the broker and communicates (message) through a particular channel/topic. Here, the homie convention defines some standard ways to do the same !!

The Homie convention defines a standardized way of how IoT devices and services announce themselves and their data on the communication channel”

 

Openhab -Homie convention-Auto discovery

      Openhab 2.4 supports homie convention 3.x(+4.x) . so it supports  automatic discovery of devices that follow the "Homie convention"

Section 1  :  Openhab0

 1.Install and configure openhab2.4 in your raspberry pi

 2. Install MQTT binding 

 

 


 3. Add your mosquitto broker /create a mqtt thing

 

Section 2  :  ESP 32

All we need to do is - just publish mqtt messages from our device (say an esp32).

 Note:-

  • Homies topic layout follows the pattern “homie/device/node/property”. 
  • Retained flag must be true 
  • Nodes in homie convention = channels in openhab 

 

example1:

  homie/DEV_NAME/$homie → 3.0
  homie/DEV_NAME/$name → My device
  homie/DEV_NAME/$state → ready
  homie/DEV_NAME/$extensions → ''
  homie/DEV_NAME/$nodes → my_thermostat
                         ↙↙↙ ↙↙↙
  homie/DEV_NAME/my_thermostat/$name → My thermostat
  homie/DEV_NAME/my_thermostat/$properties → temperature
                                        ↙↙↙↙↙↙
  homie/DEV_NAME/my_thermostat/temperature → 22 
  homie/DEV_NAME/my_thermostat/temperature/$name → Temperature
  homie/DEV_NAME/my_thermostat/temperature/$unit → °C
  homie/DEV_NAME/my_thermostat/temperature/$datatype → integer
 
 
DEV_NAME 
It will be shown as thin line text when the device popup - on openhab inbox
eg: my home
• homie/"DEV_NAME"/$homie : homie version (0.3/0.4)
• homie/"DEV_NAME"/$name :name of the module - Name that popup in inbox as bold letters
eg: my device
• homie/"DEV_NAME"/$state : Current state of the device
Options :init,ready,disconnected,sleeping,lost,alert
eg:ready
• homie/"DEV_NAME"/$extensions : “ ” (future use case)
 just use " " for now
• homie/"DEV_NAME"/$nodes : One or more nodes (light ,fan, dimmer..)

eg:homie/DEV_NAME/$nodes → my_thermostat

 
So here we are completed our device description,now we have a thing (my device) in openhab with one node/channel(my_thermostat) 

 Defining characteristics of each channel/node

homie/"DEV_NAME"/node/$name :Node name (light12)

Just give any name  (it is not necessary to use the same name that we were used in $nodes section)  but in topic, the  “/node/ “ must be replaced with the one we are defined in $nodes

eg: homie/DEV_NAME/my_thermostat/$name → My thermostat

 

homie/"DEV_NAME"/node/$properties :Defining properties of the node temperature,switch or any name as you wish

homie/DEV_NAME/my_thermostat/$properties → temperature 

 • homie/"DEV_NAME"/node/property of node/$name : Any name is fine- It will be the channel name in openhab.
Just give any name  (it is not necessary to use the same name that we were used in $properties section)  but in topic, the  “/property of node / “ must be replaced with the one we are defined in $properties

homie/DEV_NAME/my_thermostat/temperature/$name → Temperature

 

So we have defined the device and its nodes now its the time to define its properties

 
 homie/"DEV_NAME"/node/property of node/$settable :This topic defines 
whether the channel is editable or not , options: true /false
nb:true in our case,other wise we can’t edit the channel.

homie/"DEV_NAME"/node /property of node/$unit :unit ,options: %,C,f
use % in case of dimmer C in temperature sensor , we can also  just
use “ “ as unit
, “ ”  is also a valid unit

homie/"DEV_NAME"/node /property of node/$datatype : datatype
options:
integer, float, boolean, string, enum, color 

For RGB light and dimmer use color as data type and boolean for switch 
 
homie/"DEV_NAME"/node /property of node/$format : 
 (use ‘0:100‘ for dimmer and
‘hsv/rgb ‘ for RGB/Hue light )
 --> normal switch doesn't require this topic👆
 This will create a thing in openhab with one channel (name : temperature) 
                          ***

Read:

Locomotion in mobile robotics. 

What is mavros?.

Introduction to robotics. 

Different types of robots?

ROS : 5 Major advantages of using ROS.

Important branches of robotics?