MQTT - How to add Zigbee Devices?

I am trying to move from Domoticz to OpenHAB, but I have trouble setting up my ZigBee devices. I want to have sort of the same setup I had with Domoticz (with eclipse-mosquitto and zigbee2mqtt).

Setup: docker containers (on a QNAP NAS), OpenHab version 2.5.9.

I have done the following:

  • Installed MQTT addon
  • Created a connection to eclipse-mosquitto. That also works (server reports connection)

Now I am trying to add a zigbee device, but I am lost on how to do that.

  • I created a channel for the MQTT broker. mqtt topic: “zigbee2mqtt”. Channel ID: just filled something in (no idea what it is used for).
  • When I pair my devices, they show up in zigbee2mqtt, but nothing in the OpenHab paper UI.

Where do I go from here?

MQTT has no auto discovery feature. You have to add the the things manually.

Here are some informations

There is a Zigbee binding for openHAB that, I believe, has auto discovery.

I have a few things connected to openHAB via zigbee2mqtt and Mosquitto. @chrode has linked the post that got me started with it all. I wrote the following tutorials which might be useful:

Bulb - IKEA Tradfri dimming bulb
Bulbs - 3x IKEA Tradfri GU10 dimming bulbs
Switch - Xiaomi multi-press button
Switch - IKEA Tradfri dimming switch

Not 100% correct. Indeed, for zigbee2mqtt there is no automatic discovery. But for any MQTT device that follows either the Home Assistant or the Homie standard there is automatic discovery of devices.

Manually create a Thing for each device.
On that Thing, manually create a Channel for each sensor reading or actuator that the device handles. The subscription Channel is how the device communicates to OH. The publish Channel is how openHAB communicates with zigbee2mqtt.

3 Likes

Example - cheat sheet

if you already have a broker setup / Mine is mqtt:broker:myMQTTBroker

Thing mqtt:topic:myMQTTBroker:Absorbar "Absorbar" (mqtt:broker:myMQTTBroker) @ "Kitchen"{
Channels:
      Type switch : Power "Power" [ commandTopic="broadlink/absorbar/power", stateTopic="broadlink/absorbar/power", on="ON", off="OFF" ]
      Type switch : Light "Light" [ commandTopic="broadlink/absorbar/light", stateTopic="broadlink/absorbar/light", on="ON", off="OFF"  ]
      Type string : Move  "FAN Move" [ commandTopic="broadlink/absorbar/move" ]
      Type switch : switch "Lights" [ commandTopic="zigbee2mqtt/living_room_lights/set", stateTopic="zigbee2mqtt/living_room_lights", transformationPattern="JSONPATH:$.state", formatBeforePublish="{\"state\":\"%s\"}", on="ON", off="OFF" ]
      Type dimmer : dimmer "Dimmer" [ commandTopic="zigbee2mqtt/living_room_lights/set", stateTopic="zigbee2mqtt/living_room_lights", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{\"brightness\":%s}",  min=0, max=255, step=1 ]
      Type switch : secondswitch "Test 2Lights" [ commandTopic="zigbee2mqtt/living_room_lights/set", stateTopic="zigbee2mqtt/living_room_lights", transformationPattern="JSONPATH:$.state", formatBeforePublish="{\"state\":\"%s\"}", 1="ON", 0="OFF" ] 

  }

Absorbar "Absorbar" Thing name and label

(mqtt:broker:myMQTTBroker) Is the name of the mqtt broker you have setup`

@ "Kitchen" Where it is, location

You can see 2 technologies used in mqtt channels here broadlink and what you are after.

Type switch : switch "Lights" [ commandTopic="zigbee2mqtt/living_room_lights/set", stateTopic="zigbee2mqtt/living_room_lights", transformationPattern="JSONPATH:$.state", formatBeforePublish="{\"state\":\"%s\"}", on="ON", off="OFF" ]

Need to install JSONPATH transformation

Type switch is the same : switch is the channel name and needs to be unique within the same thing "Lights" is the label

// Item File
Switch Absorbar_light "Lights" {channel="mqtt:topic:myMQTTBroker:Absorbar:switch"}

So the channel mqtt:topic:myMQTTBroker:Absorbar:switch Absorbar is thing switch is the channel name

1 Like

Thanks for all the feedback. I was already suspecting there was no auto discovery.
@chrode. thanks for the confirmation.

@Bruce_Osborne. I already tried the ZigBee binding. When setup the 1st time, it works. But after reboot, it does not work anymore and I get WARN’s in my log about a stuck bootloader (I am using a cc2531) and the ZigBee devices do not initialize.

I am trying to add few Aqara Temperature / Humidity devices to get started.
Zigbee2mqtt looks like to support more devices than the ZigBee binding (but not sure if that is actually true). Looks like I have to dive a bit deeper. Thanks for all the links to help me with it.

1 Like

I managed to get it to work (following the example from [hafniumzinc]. I have 2 questions remaining

  • How do I link the Channels from a Thing to Items without doing it manually in PaperUI?
  • When you have -for example- 8 of the same type of devices. Do you need to copy/paste it all or is there something smart (such as wildcards, macros, ???)

zigbee.things

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
	host="localhost",
	secure=false,
	port=1883,
	clientID="OpenHAB2"
]

Thing mqtt:topic:tempSensor1 "Sensor 1" (mqtt:broker:MosquittoMqttBroker) {
Channels:
	Type number : temperature "Temperature"  [ stateTopic = "zigbee2mqtt/tempSensor1/temperature" ]
	Type number : humidity    "Humidity"     [ stateTopic = "zigbee2mqtt/tempSensor1/humidity" ]
	Type number : pressure    "Pressure"     [ stateTopic = "zigbee2mqtt/tempSensor1/pressure" ]
	Type number : voltage     "Voltage"      [ stateTopic = "zigbee2mqtt/tempSensor1/voltage" ]
	Type number : battery     "Battery"      [ stateTopic = "zigbee2mqtt/tempSensor1/battery" ]
	Type number : linkquality "Link Quality" [ stateTopic = "zigbee2mqtt/tempSensor1/linkquality" ]
}

zigbee.items

Number Sensor1_Office_Temperature "Temperature [%.1f °C]" { channel="zigbee2mqtt/tempSensor1/temperature" }
Number Sensor1_Office_Humidity    "Humidity [%.1f %%]"    { channel="zigbee2mqtt/tempSensor1/humidity" }
Number Sensor1_Office_Pressure    "Pressure [%.1f hPa]"   { channel="zigbee2mqtt/tempSensor1/pressure" }

zigbee.sitemap

sitemap zigbee label="ZigBee"
{
    Frame label="Sensor 1: Office" {
        Text label="Temperature"  item=Sensor1_Office_Temperature
        Text label="Humidity"     item=Sensor1_Office_Humidity
        Text label="Pressure"     item=Sensor1_Office_Pressure
    }
}

Paper UI is not in OpenHAB 3 and is replaced by a different UI

I use VS Code as my editor to edit config files to do most things in openHAB

I use to openhab extention to add Items from things it takes only seconds to add all my items for a thing. Eg

Also your Items should look like

Number   Sensor1_Office_Temperature   "Temperature [%.1f °C]" {channel="mqtt:topic:tempSensor1:temperature"}
Number   Sensor1_Office_Humidity      "Humidity [%.1f %%]"    {channel="mqtt:topic:tempSensor1:humidity"}
Number   Sensor1_Office_Pressure      "Pressure [%.1f hPa]"   {channel="mqtt:topic:tempSensor1:pressure"}
Number   Sensor1_Office_Voltage       "Voltage"               {channel="mqtt:topic:tempSensor1:voltage"}
Number   Sensor1_Office_Battery       "Battery"               {channel="mqtt:topic:tempSensor1:battery"} 
Number   Sensor1_Office_Linkquality   "Link quality"          {channel="mqtt:topic:tempSensor1:linkquality"}
1 Like

To reiterate @denominator

You’ve already linked your Channels to your Items using lines such as the above in your Item definition. However, your syntax is incorrect: you need to be referencing your Thing and your Channel in this line, not the MQTT topic (that’s already referenced in your Thing Channel). So your above line should be:

channel="mqtt:topic:tempSensor1:temperature"
1 Like

@denominator, @hafniumzinc. Thanks that fixed it. Still struggling a bit with the syntax :wink:

As for my other question

  • When you have -for example- 8 of the same type of devices. I have now copy/pasted it 8 times, but I was wondering if there is something smarter (such as wildcards, macros, ???)
1 Like

@denominator essentially answered that one. If you don’t like copy/pasting, then get Visual Studio Code setup with the openHAB plugin - this speeds things up a little bit.

1 Like