openHAB and zigbee2mqtt Tutorial for Beginners

thanks! indeed…
I was waiting for +6months that the Opple Swtich is added to the native zigbee binding.
In Z2M its there and many more. So I think I should finally move.

Yes absolutely

Still convinced, and with the more powerful coordinators that have come out since then it is better than ever. I am now using the zzh! stick and the range and response is orders of magnitude better than the CC2531

Is there step by step tutorial how to setup zigbee2mqtt (on cc 2531 stick ) on OH3 from clean OH3 to totally working solution, and then, for example, connect first xiaomi wall switch to stick.
now i have:

  • cc 2531 stick with firmware (seller say it zigbee2mqtt completable)
  • clean OpenHub3 on raspberry pi 4

Or maybe there another way, i find zigbee bunding inside OH3 it but it not work…

1 Like

I switched to the sonoff ZB bridge since a couple of weeks, flashed with Tasmota. For me this is a lot easier then playing with a separate raspberry pi and the range is much better (at least for me).

I created things for all my devices (in this case an Aqara temp & hum sensor)

UID: mqtt:topic:mosquitto:thp_ground
label: THP ground
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
location: Office
channels:
  - id: temperature
    channelTypeUID: mqtt:number
    label: temperature ground
    description: ""
    configuration:
      stateTopic: tele/sonoffbridge/THP_ground/SENSOR
      transformationPattern: REGEX:(.*\"Temperature\".*)∩JSONPATH:$.ZbReceived.THP_ground.Temperature
      unit: °C
  - id: humidity
    channelTypeUID: mqtt:number
    label: humidity ground
    description: null
    configuration:
      stateTopic: tele/sonoffbridge/THP_ground/SENSOR
      transformationPattern: REGEX:(.*\"Humidity\".*)∩JSONPATH:$.ZbReceived.THP_ground.Humidity
      unit: "%"
  - id: linkquality
    channelTypeUID: mqtt:number
    label: linkquality ground
    description: null
    configuration:
      stateTopic: tele/sonoffbridge/THP_ground/SENSOR
      transformationPattern: REGEX:(.*\"LinkQuality\".*)∩JSONPATH:$.ZbReceived.THP_ground.LinkQuality
      unit: / 255
  - id: battery
    channelTypeUID: mqtt:number
    label: battery ground
    description: null
    configuration:
      stateTopic: tele/sonoffbridge/THP_ground/SENSOR
      transformationPattern: REGEX:(.*\"BatteryPercentage\".*)∩JSONPATH:$.ZbReceived.THP_ground.BatteryPercentage
      unit: "%"

item

// Equipmment
Group                   thp_ground                 "thp ground"              <Equipment_Sensor>    (office)          ["Sensor"]
 // items
Number:Temperature      thp_ground_temperature     "Temperature ground"      <temperature>         (thp_ground)      ["Measurement","Temperature"]    {channel="mqtt:topic:mosquitto:thp_ground:temperature"}
Number:Dimensionless    thp_ground_humidity        "Humidity ground"         <humidity>            (thp_ground)      ["Measurement","Humidity"]       {channel="mqtt:topic:mosquitto:thp_ground:humidity"}
Number                  thp_ground_linkQuality     "Link Quality ground"     <energy>              (thp_ground)      ["Status", "Level"]              {channel="mqtt:topic:mosquitto:thp_ground:linkquality"}
Number                  thp_ground_batteryLevel    "Battery level ground"    <battery>             (thp_ground)      ["LowBattery", "Level"]          {channel="mqtt:topic:mosquitto:thp_ground:battery"}

There’s five steps to this:

  1. Install Mosquitto MQTT broker.
  2. Install zigbee2mqtt on your Pi. Follow the instructions from zigbee2mqtt.
  3. Pair your Zigbee device with zigbee2mqtt - find your device in this list and follow the instructions.
  4. Connect openHAB to Mosquitto
  5. Create a Generic MQTT Thing and configure it with the information for your Zigbee device.

Steps 1 & 4 are described here.

Step 5 depends on your Zigbee device. An example for a bulb is here.

Note that this assumes that your cc2531 already has the correct firmware, as per

If not, you will have to flash it using these instructions.

1 Like

I haven’t transitioned to OH3 yet, as my system with 2.5.10 is very stable. Will probably wait until OH3.1 is released before taking the plunge.
What I did do since the tutorial was written is change to the zig-a-zig-ah adapter instead of the CC2531 stick and this greatly improved stability and range with about 30 zigbee devices in my system.

i successfully instal mqtt with Mosquitto, but when I try to instal zigbee2mqtt have an error . Try to do another instal on top, but always fail on this “npm start” command. I use clean OH3.0.1.

PS this my second try, in the first try I easy instal zigbee2mqtt (on clean OH), but the first time I have another problem with mqtt broker, maybe I broke something and can’t connect zigbe2mqtt to mqtt server). Now in the new (third) try, i will format my sd again and try to setup zigbee2mqtt first and then MQTT on clean OH

Make sure that you selected the correct user during installation

image

i try instal again (on top of existing zigbee2mqtt) now I have this a litle different error

can you give an example of your /opt/zigbee2mqtt/data/configuration.yaml file?

now I try to erase my OP3 and try from start on version 3.1 snapshot, I hope it helps…

PS how to check if my c2531 stick work correct?

after erasing my OH3.0.0.1 I setup a new 3.1.0.m1 and try setup zigbee2mqtt first, and all go ok like in the tutorial (the only problem that no MQTT server to connect). Then setup mosquito and MQTT broker they go online. Then I check
the status of zigbe2mqtt but I don’t know it works or not? how I can add new devices from the scan button in the thing menu?

Looking at the log, it seems your zigbee2mqtt works.
For auto discovery, if I am not wrong, you need to activate the home assistant feature in your zigbee2mqtt conf though. (I don’t use auto discovery, only use generic mqtt things and manually add them).

I looking in the log and connect 2 devices (water leak sensor and wall switch) and they show in log But how to discover them automatically from UI (as things), it is possible? or only manual by writing the text?

for example, I have this and what do with this? i totally don’t understand this tutorial!!!

I always do it manually using the OH3 interface (generic MQTT thing).
Yes, I know it is quite tedious work.

Thanks for the tutorial. It’s almost all working on OH2.1, but I only seem to be able to send commands to Zigbee2MQTT and don’t get any feedback, so don’t see link quality for example.

Would anyone have any ideas? I have paired a simple SA-003-Zigbee switch with the following things and items. JSONPATH has also been installed.

mqtt.things

Bridge mqtt:broker:mosquitto [ host="localhost", port=1883, secure=false ]
{

    Thing topic switchLoungeAmp  "Lounge Amplifer" @ "Office" {
    Channels:
        Type switch : state       "state" 		[ stateTopic="zigbee2mqtt/switchLoungeAmp", commandTopic="zigbee2mqtt/switchLoungeAmp/set", transformationPattern="JSONPATH:$.state", on="ON", off="OFF" ]
		Type number : linkquality "linkquality" [ stateTopic="zigbee2mqtt/switchLoungeAmp", transformationPattern="JSONPATH:$.linkquality", unit="lqi" ]            
    }

}

mqtt.items

Switch	ZigbeeLoungeAmplifer 		   "Lounge Amplifer Power [%s]" { channel="mqtt:topic:mosquitto:switchLoungeAmp:state" }
Number	ZigbeeLoungeAmpliferLinkquality "Lounge Amplifer LQ [%s]"    { channel="mqtt:topic:mosquitto:switchLoungeAmp:linkquality" }

I don’t think this is a valid unit.

Can you show the JSON published to zigbee2mqtt/switchLoungeAmp by your Zigbee device?

Thanks @hafniumzinc, have removed the unit and it still loads the things file but unfortunately same issue.

Bit new to this, but think the JSON is { “linkquality”: 26, “state”: “ON” } I got this from MQTT explorer.

Good news, it’s now working. Not sure why, reboot fixed it :grinning_face_with_smiling_eyes:

Now to get my TRVs working!

openHAB has a problem with Things files, not always updating after a save. You can restart openHAB, but I do this.

1 Like

Hello together,

how can i create an item with transition? At the moment i created a dummy item and a rule with an command like this:
SchlafzimmerTVLampeControl.sendCommand("{“brightness”:0, “transition”:30}")
Is there another way to set this both values into an item with OH3???

Thanks.