openHAB and zigbee2mqtt Tutorial for Beginners

ZIgbee2mqtt is not a broker.

Using zigbee2mqtt you don’t. OH has a zigbee binding if that is what you are wanting.

Read all the info on gitub about zigbee2mqtt to understand how it works with OH and other home automation software.

1 Like

Thanks for the great tutorial!
Works also very well to control a Livolo Zigbee Wallswitch (T1000).

Another option to define custom messages (commandTopic) on things level to set a state would be:

     Type switch: Livolo_SW1_state "Switch onoff" [stateTopic="zigbee2mqtt/Livolo_SW1",commandTopic="zigbee2mqtt/Livolo_SW1/set",  on="{\"state_left\":\"ON\"}", off="{\"state_left\":\"OFF\"}", transformationPattern="JSONPATH:$.state_left"]

I wish to change my current zigbee2mqtt coordinator (CC2531) to a RF TO USB (CC2530 CC2591) RF switch - as a new coordinator. What would be a painless way to do this without losing all the zigbee connections made?

Just in case someone struggles with the command mosquitto_sub, dont forget to use flags -u and -P.

also see:

https://community.openhab.org/t/struggling-with-oh-2-5-4-and-zigbee2mqtt-tutorial-mosquitto-sub-gives-connection-refused/97966

1 Like
  1. Stop the zigbee2mqtt
  2. Make a backup
  3. Update config (port)
  4. Plugin new hardware and start zigbee2mqtt

You can find this info in FAQ https://www.zigbee2mqtt.io/information/FAQ.html#doesnt-require-repairing

Good luck!

1 Like

Excellent step by step tutorial - it works as described - many thanks. :+1:
This works with the TI development board LAUNCHXL-CC1352P-2. Firmware as reported by zigbee2mqtt: zStack3x0 revision: 20191106
1st serial port /dev/ttyACM0 is correct (this device reports 2 serial ports over USB).

You can skip after step 1 in ‘openHAB Configuration’ (as transformations are no longer necessary). Keep on reading for thing and item configuration.

1 Like

Thank you to z9th3 for the tutorial, i followed it for the Zigbee2Mqtt Install and now I am up and running.
Cheers

I have several power switches working fine over MQTT (flashed with Tasmota). Now I have an Xiaomi Power Socket and paired it with Zigbee2MQTT.

Thing config:

Channels:
Type switch : state “state” [ stateTopic = “zigbee2mqtt/socket”, transformationPattern=“JSONPATH:$.state”, commandTopic=“zigbee2mqtt/socket/set” ]
Type number : power “power” [ stateTopic = “zigbee2mqtt/socket”, transformationPattern=“JSONPATH:$.power” ]
Type number : voltage “voltage” [ stateTopic = “zigbee2mqtt/socket”, transformationPattern=“JSONPATH:$.voltage” ]
Type number : consumption “consumption” [ stateTopic = “zigbee2mqtt/socket”, transformationPattern=“JSONPATH:$.consumption” ]
Type number : linkquality “linkquality” [ stateTopic = “zigbee2mqtt/socket”, transformationPattern=“JSONPATH:$.linkquality” ]

All values are correct, but when I change the switch in my sitemap, my power socket doesn’t turn on or off (allthough I see in the logs the my items changes state)
When I manually publish ON or OFF to zigbee2mqtt/socket/set, my power socket changes state correctly. What am I missing?

Can you subscribe to the MQTT broker on the same topic (or use MQTT Explorer or similar) and watch as you flip the switch in openHAB? Is the broker getting the correct string?

Oh, and do you use the experimental attribute? See here: Zigbee2mqtt revisited: No more ugly transformations

I think without you have to send JSON strings


The broker doesn’t receive anything
 When I switch the socket manually, the state topic changes.
I use MQTT Explorer and use both raw en json with simply ON or OFF.

I already tried it, but I also use Zigbee2Mqtt Assistant, and for full functionality, this required also enabling the homeassistant feature, wich doesn’t work together with the attribute value (only json)

Hmmm. What do the openHAB logs show? Since saving the things files, have you restarted openHAB? If not, you should give that a try!

Just did a restart of openHAB, without any luck

changing switch in sitemap

2020-07-19 21:18:11.671 [ome.event.ItemCommandEvent] - Item ‘mi_socket_state’ received command ON
2020-07-19 21:18:11.734 [nt.ItemStatePredictedEvent] - mi_socket_state predicted to become ON
2020-07-19 21:18:11.745 [vent.ItemStateChangedEvent] - mi_socket_state changed from OFF to ON

publishing topic

2020-07-19 21:19:40.146 [vent.ItemStateChangedEvent] - mi_socket_state changed from OFF to ON

When I change the switch in Paper UI, the set topic toggles between 1 and 0, this isn’t correct offcourse. I’ll add a transformation file.
Just noticed that this is also the case when I toggle in sitemap, a restart pushed me in the right direction


edit: solved! the answer was actually on the first post of this topic


What was the answer? The first post is quite long
!

Adding transformationPatternOut="JS:setstate.js" to the switch Channel + creating the .js file:

You can use Remote SSH to connect to your openhab server directly on vscode, so no need to setup samba just for that.

If you add this to zigbee2mqtt configuration:

experimental:
	output: attribute

you can drop almost all the transforms, here’s a config example of one of my Philips hue bulbs:

Thing mqtt:topic:light_kitchen "Kitchen Light" (mqtt:broker:mosquitto) @ "Home" {
  Channels:
	Type switch  : power "Power" [
	  stateTopic="zigbee2mqtt/philipshue_light_kitchen/state",
	  commandTopic="zigbee2mqtt/philipshue_light_kitchen/set/state",
	  on="ON", off="OFF"
	]
	Type dimmer  : brightness "Brightness" [
	  stateTopic="zigbee2mqtt/philipshue_light_kitchen/brightness",
	  commandTopic="zigbee2mqtt/philipshue_light_kitchen/set/brightness",
	  min=0, max=254, step=1
	]
	Type number  : linkquality "LinkQuality" [
	  stateTopic="zigbee2mqtt/philipshue_light_kitchen/linkquality"
	]
}
2 Likes

See above why I don’t use the experimental feature (yet)

Hello. I use zigbee2mqtt with CC2531. But there is one problem, after restarting the raspberry pi, all zigbee devices have the offline status.I have to press the pairing button for 1 second every time and everything becomes OK. It feels like the devices are in sleeping mode, and I have to press the pairing button to wake them up.

are these main powered or battery devices? The devices normally reconnect after some time without you doing something and send with their normal heartbeat rate. Battery powered devices normally have a longer heartbeat than main powered.

I have only battery powered devices. May be i need to send them birth-message from MQTT-brocker or something else? Status of these devices in topic “availability” - offline.

As stated in github, the availability works well on main powered devices and there are drawbacks on battery powered devices
 They are not gettting pinged so that there is no battery drain. Therefore the implementation is, that if they don’t report for 25h, the payload on this topic is unavailable .

How I check for zigbee devices being online is to set up a DateTime item, which gets the current time when an update hits the broker for this item. after a timout of 12h, when no update is received after that, the device is marked as offline. It’s the same logic as in zigbee2mqtt, but only done in OH (of except for the main powered devices, which are getting pinged).

For your initial question, the battery powered devices send to the bridge an update depenent on their heart beat. This must not be directly after an Raspb reboot. But after some time, every device should have pinged a new update to the bridge. Pressing a button on the device normally directly sends an update