[SOLVED] Creating items / things for zigbee2mqtt devices

  • Platform information:
    • Hardware: RP 4
    • OS: Buster
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.5.0-1
  • Issue of the topic: How do I add items / things for zigbee2mqtt

I’m starting on my HomeHab journey, but before i get too far I wanted to get the Xiaomi devices working, as I ahve a few of them. Hence I have been playing with zigbee2mqtt

I have installed both the MQTT binding and the MQTT Broker Moquette add-on.
I have zigbee2mqtt installed by following: openHAB and zigbee2mqtt Tutorial for Beginners and have added a MQTT thing as per https://www.openhab.org/blog/2018-12-16-mqtt-arrives-in-the-modern-openhab-2-x-architecture.html#configuration-via-text-files

Following the the beginners instructions in the first link it mentions looking at the Mosquito log using the command: mosquitto_sub -d -t zigbee2mqtt/# however this does not work, I am assuming it is because this relates to the version installed via openhabian-config and not via Paper UI as I have done?

I have managed to pair a device as this appears in the zigbee2mqtt log as follows:

Dec 25 16:57:50 openhab npm[1916]: zigbee2mqtt:info  2019-12-25 16:57:50: MQTT publish: topic 'zigbee2mqtt/0x00158d0003583562', payload '{"battery":86,"voltage":2975,"linkquality":18,"occupancy":true}'

My problem no is I am at a bit of a loss how to proceed, I assume I need to create an item and possibly a thing, but what to I put in??

Thank you


I recommend using mosquitto borker as the embedded broker Moquette lacks support. You can use the openhabian-config tool to install mosquitto.

Yes, you are correct.

Can’t help with the embedded broker but I can give several examples using mosquitto.
Just let me know about the examples and I will post them. FYI, most recommend using PaperUI to create the Thing and files for items. I’m hardheaded and use files for everything…:shushing_face:

It’s Christmas, what the heck here is an example of one of my zigbee2mqtt things and items file.


Bridge mqtt:broker:pibroker "pibroker" [ host="", port=1883, secure=false, username="xxxxxxxx", password="xxxxxxxx" ]
Thing topic zigbee2mqtt "Bedroom Light" @ "Bedroom" {
        Type switch : power  "Power"               [ stateTopic="zigbee/0xb0ce1814030ac279", transformationPattern="JSONPATH:$.state",
                                                    commandTopic="zigbee/0xb0ce1814030ac279/set", on="ON", off="OFF" ]
        Type dimmer : dimmer "Dimmer"              [ stateTopic="zigbee/0xb0ce1814030ac279",
                                                    commandTopic="zigbee/0xb0ce1814030ac279/set", transformationPattern="JSONPATH:$.brightness", formatBeforePublish="{\"brightness\":%s}" ]


Switch BedroomLight "Bedroom Light"    <light> ["Lighting"]  { channel="mqtt:topic:pibroker:zigbee2mqtt:power", expire="120m,command=OFF" }
Dimmer BedroomLight_Level "Bedroom Light Level [%.0f %%]"    <light> ["Lighting"]  { channel="mqtt:topic:pibroker:zigbee2mqtt:dimmer" }

You will likely need a transformation service installed such as JSONPATH (installed via PaperUI > addons > tranformations). You can see how this is used in example above.

Thank you for your prompt reply and Christmas present :slight_smile:

I have created the thing file and the item as below and linked the channel to the item in the Paper UI. I’ve the also installed the JSONPATH transformation.

I’ve moved on :slight_smile: but still not working, do I need to config the JSON somewhere?

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

Thing topic zigbee2mqtt "Garage Movement" @ "Garage" {


        Type switch : movement "Movement" [ stateTopic="zigbee/0x00158d0003583562", transformationPattern="JSONPATH:$.state",commandTopic="zigbee/0xb0ce1814030ac279/set", on="ON", off="OFF" ]


Switch Garage_Movement "Garage Movement" <motion> { channel="mqtt:topic:mosquitto:zigbee2mqtt:onoff"}

What is your device, a motion sensor? You will need to use whatever the payload of mqtt is. Do you have anything reporting from the device? Check the logs for error messages.

The item needs name of thing at end like below.

Switch Garage_Movement "Garage Movement" <motion> { channel="mqtt:topic:mosquitto:zigbee2mqtt:movement"}

Thanks for your prompt replies and support, I’ve been doing some research and I think the config should be as follows, based on the log, although still not working:

Client mosqsub|14472-openhab received PUBLISH (d0, q0, r0, m0, 'zigbee2mqtt/0x00158d0003583562', ... (63 bytes))
Bridge mqtt:broker:mosquitto [host="localhost", secure=false]
Thing topic zigbee2mqtt "Garage Movement" @ "Garage" {
        Type switch : movement "Movement" [ stateTopic="zigbee2mqtt/0x00158d0003583562", transformationPattern="JSONPATH:$.occupancy" ]
Switch Garage_Movement "Garage Movement" <motion> { channel="mqtt:topic:mosquitto:zigbee2mqtt:onoff" }

I’ve obviously missed something :frowning:

I got it working!!! I forgot I had changed the name in the YAML file, also added the “true”/“false” to ON OFF translations in.

I have replicated my config for others who may find it useful.
Thank you @H102 for all your help.

 Bridge mqtt:broker:mosquitto [host="localhost", secure=false]
Thing topic zigbee2mqtt "Garage Movement" @ "Garage" {
        Type switch : movement "Movement" [ stateTopic="zigbee2mqtt/Garage_Movement", transformationPattern="JSONPATH:$.occupancy", on="true",off="false"]
Switch Garage_Movement "Garage Movement" <motion> { channel="mqtt:topic:mosquitto:Garage_Movement:onoff" }

I recommend looking at the post Zigbee2mqtt revisited: No more ugly transformations

1 Like

Thank you, looks like a bit slicker :slight_smile: