Zigbee2mqtt revisited: No more ugly transformations

I’ve been using zigbee2mqtt for quite some time, for details look here:

and here:

Recently I discovered a new option of zigbee2mqtt: attribute output. This option, in company with the mqtt2 binding, provides a nice solution.

This option simply gets rid of the json-formatted output and transmits all attributes separately.

You enable it via configuration.yaml.

experimental:
  output: attribute

The benefits are:

  • no more json-encoded output => no jsonpath-transformation
  • no more missing attributes in message => no Javascript-transformation

I use files for erverything, so every device uses two parts of configuration, a things and an items file. The following are my devices so far.

  • Osram SmartPlug thing:
    Thing topic SZLV "SZLV" @ "SZ"
    {
        Channels:
            Type switch : state "state" [ stateTopic = "zigbee2mqtt/SZLV/state", commandTopic = "zigbee2mqtt/SZLV/set/state", on="ON", off="OFF" ]
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/SZLV/linkquality" ]               
    }
  • Osram SmartPlug items:
    Switch SZLV_TOGGLE "Lava [%s]"         <poweroutlet>  {channel="mqtt:topic:broker:SZLV:state"}
    Number SZLV_LINKQUALITY "SZLV [%d]"  {channel="mqtt:topic:broker:SZLV:linkquality"}
  • Xiaomi Aqara wireless switch WXKG11LM thing:
    Thing topic SZKEY0 "SZKEY0" @ "SZ"
    {
        Channels:
            Type string : click "click" [ stateTopic = "zigbee2mqtt/SZKEY0/click" ]
            Type number : voltage "voltage" [ stateTopic = "zigbee2mqtt/SZKEY0/voltage" ]     
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/SZKEY0/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/SZKEY0/linkquality" ]               
    }
  • Xiaomi Aqara wireless switch WXKG11LM items:
    String SZKEY0_CLICK "SZKEY0 [%s]"  <button>  {channel="mqtt:topic:broker:SZKEY0:click"}
    Number SZKEY0_VOLTAGE "SZKEY0 Volt [%d mV]" {channel="mqtt:topic:broker:SZKEY0:voltage"}
    Number SZKEY0_BATTERY "SZKEY0 BAT [%.1f %%]" <battery {channel="mqtt:topic:broker:SZKEY0:battery"}
    Number SZKEY0_LINKQUALITY "SZKEY0 [%d]"  {channel="mqtt:topic:broker:SZKEY0:linkquality"}
  • Xiaomi Aqara water leak sensor SJCGQ11LM thing:
    Thing topic LEAK "LEAK" @ "B1"
    {
        Channels:
            Type switch : water_leak "water_leak" [ stateTopic = "zigbee2mqtt/LEAK/water_leak",on="true", off="false" ]
            Type number : voltage "voltage" [ stateTopic = "zigbee2mqtt/LEAK/voltage" ]     
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/LEAK/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/LEAK/linkquality" ]               
    }
  • Xiaomi Aqara water leak sensor SJCGQ11LM items:
    Switch LEAK_STATE "Leak [%s]"  <water> {channel="mqtt:topic:broker:LEAK:water_leak" }
    Number LEAK_VOLTAGE "Leak Volt [%d mV]"  {channel="mqtt:topic:broker:LEAK:voltage"}
    Number LEAK_BATTERY "Leak BAT [%.1f %%]" <battery> {channel="mqtt:topic:broker:LEAK:battery"}
    Number LEAK_LINKQUALITY "LEAK [%d]"   {channel="mqtt:topic:broker:LEAK:linkquality"}
  • Xiaomi Aqara human body movement and illuminance sensor RTCGQ11LM thing:
    Thing topic TEMD "TEMD"  @ "TE"
    {
        Channels:
            Type switch : occupancy "occupancy" [ stateTopic = "zigbee2mqtt/TEMD/occupancy", on="true", off="false"  ]
            Type number : illuminance "illuminance" [ stateTopic = "zigbee2mqtt/TEMD/illuminance" ]            
            Type number : voltage "voltage" [ stateTopic = "zigbee2mqtt/TEMD/voltage" ]     
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/TEMD/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/TEMD/linkquality" ]     
    }
  • Xiaomi Aqara human body movement and illuminance sensor RTCGQ11LM items:
    Switch TEMD_MOTION "TEMD Motion [MAP(HM-Sen-MDIR-O-2.map):%s]" <motion>   {channel="mqtt:topic:broker:TEMD:occupancy" }

    Number TEMD_BRIGHTNESS "TEMD Brightness [%d lumen]"  {channel="mqtt:topic:broker:TEMD:illuminance"}
    Number TEMD_VOLTAGE "TEMD Volt [%d mV]"  {channel="mqtt:topic:broker:TEMD:voltage"}
    Number TEMD_BATTERY "TEMD BAT [%.1f %%]" <battery>   {channel="mqtt:topic:broker:TEMD:battery"}
    Number TEMD_LINKQUALITY "TEMD [%d]"  {channel="mqtt:topic:broker:TEMD:linkquality"}
  • the map file HM-Sen-MDIR-O-2.map
    0=keine Bewegung
    1=Bewegung
    -=unbekannt
    OPEN=Bewegung
    CLOSED=keine Bewegung
    OFF=keine Bewegung
    ON=Bewegung
    NULL=unbekannt
  • Xiaomi Aqara temperature, humidity and pressure sensor WSDCGQ11LM thing:
    Thing topic KEHK "KEHK" @ "KE"
    {
        Channels:
            Type number : temperature "temperature" [ stateTopic = "zigbee2mqtt/KEHK/temperature" ]
            Type number : humidity "humidity" [ stateTopic = "zigbee2mqtt/KEHK/humidity" ]
            Type number : pressure "pressure" [ stateTopic = "zigbee2mqtt/KEHK/pressure" ]
            Type number : voltage "voltage" [ stateTopic = "zigbee2mqtt/KEHK/voltage" ]     
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/KEHK/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/KEHK/linkquality" ]               
    }
  • Xiaomi Aqara temperature, humidity and pressure sensor WSDCGQ11LM items:
    Number KEHK_TEMP "Kesseltemperatur [%.1f °C]"  <temperature>  {channel="mqtt:topic:broker:KEHK:temperature"}
    Number KEHK_HUMIDITY "KEHK HUMID [%d %%]"    {channel="mqtt:topic:broker:KEHK:humidity"}
    Number KEHK_PRESSURE "KEHK PRESS [%d mbar]"     {channel="mqtt:topic:broker:KEHK:pressure"}
    Number KEHK_VOLTAGE "KEHK Volt [%d mV]"   {channel="mqtt:topic:broker:KEHK:voltage"}
    Number KEHK_BATTERY "KEHK BAT [%.1f %%]" <battery>   {channel="mqtt:topic:broker:KEHK:battery"}
    Number KEHK_LINKQUALITY "KEHK [%d]"    {channel="mqtt:topic:broker:KEHK:linkquality"}
  • IKEA TRADFRI remote control E1524 thing:
    Thing topic SZMS "SZMS" @ "SZ"
    {
        Channels:
            Type string : action "action" [ stateTopic = "zigbee2mqtt/SZMS/action" ]   
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/SZMS/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/SZMS/linkquality" ]               
    }
  • IKEA TRADFRI remote control E1524 items:
    String SZMS_ACTION "SZMS [%s]"  <button>   {channel="mqtt:topic:broker:SZMS:action"}
    Number SZMS_BATTERY "SZMS BAT [%.1f %%]" <battery>  {channel="mqtt:topic:broker:SZMS:battery"}
    Number SZMS_LINKQUALITY "SZMS [%d]"    {channel="mqtt:topic:broker:SZMS:linkquality"}
32 Likes

Nice, will try that ASAP

Hi Joachim,
thanks for your topic.
I am truly desperate while trying to use your solution.

Maybe you can help me to figure out how this works.

I have an ikea bulb and also an ikea remote and some other ikea devices. They are all communicating allready with the mqtt broker an i can see the status changes.

can you give an example how this can be created in paperui? because creating in text is not working for me, here my examples:
Thing:

Bridge mqtt:broker:test [ host=“localhost”, secure=false, username=“username”, password=“password”] {
Thing topic schalter “0x000b57fffe8898b3”
{
Channels:
Type string : action “action” [ stateTopic = “zigbee2mqtt/0x000b57fffe8898b3/action” ]
Type number : battery “battery” [ stateTopic = “zigbee2mqtt/0x000b57fffe8898b3/battery” ]
Type number : linkquality “linkquality” [ stateTopic = “zigbee2mqtt/0x000b57fffe8898b3/linkquality” ]
}
}

item:
Number BATTERY “0x000b57fffe8898b3 BAT [%.1f %%]” {channel=“mqtt:topic:broker:0x000b57fffe8898b3:battery”}

I am completly new to openhab file creating, i always tried to configure everything in paper UI.

Maybe if its not to much for you, is it possible that you can create a step by step guide?, i am now trying this for the third day each day arround four ours.

Thanks for your reply.

Chris

@chriswooo

It’s quite simple to use files. First of all you need to find your configuration folder ($OPENHAB_CONF is its placehodername in the documentation).
This depends on your operating system and such stuff. Within this folder you find a things and an items subfolder. Simplydrop a file with the suffix in the subfolder, openHAB will autmatically pick it up.

I use openHABian on a RaspberryPi and edit the files from my Windows Workstation with Visual Studio Code (open folder). I access the network share on the Pi with \\<openhabianip>\openHAB2-conf.

I don’t use PaperUI because i do not enjoy click-orgies. With files it is just copy, paste and edit.

@job
Thank you very much. How this works i know already :slight_smile: but thanks

My Main Problem is, how i configure things, that they use the mqtt binding to get information from zigbee2mqtt. It would be very helpfull if the would be a step by step guide. If i use the example that you provide, openhab will not show the thing in paper UI, so i think there is something missing. Also the log is empty.

Is your broker (openHAB thing) online? As you are using zigbee2mqtt already, i suspect you are running an external mosquitto, right?

That’s the first step.

If you are running openHAB 2.4 you need to restart openHAB after changing anything with the files. (This should be ok with 2.5m5, but sometimes a restart is necessary as well.)

i use the mqtt broker service from openhab 2.4 and the mqtt broker thing is online.

my problem ist, where in your example you adress the broker?

to make it on an example i have this device in zigbee2mqtt listed:

‘0x000b57fffe8898b3’:
friendly_name: ‘0x000b57fffe8898b3’
Its an IKEA E1524 Remote.

So how would the thing file should be? Is that correct?

   Thing topic Schalter1 "0x000b57fffe8898b3" @ "test"
    {
        Channels:
            Type string : action "action" [ stateTopic = "zigbee2mqtt/0x000b57fffe8898b3/action" ]   
            Type number : battery "battery" [ stateTopic = "zigbee2mqtt/0x000b57fffe8898b3/battery" ]     
            Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/0x000b57fffe8898b3/linkquality" ]               
    }


And the Item File:

        Number 0x000b57fffe8898b3_BATTERY "0x000b57fffe8898b3 BAT [%.1f %%]" <battery>  {channel="mqtt:topic:broker:0x000b57fffe8898b3:battery"}

}

Is that correct?

If it is correct than there most be something else wrong, because, i can see the item:

But i can not see the created thing.

I hope i could explane my problem now :smiley:

Also in Basic UI i could not see the battery status
screen_basicui

So, there musst be a problem for openhab reading information from MQTT Broker. but i could not find my misstake.

Yes, looks fine.

No. My broker is called “broker”, i guess your broker is called “test”.

Try that

    Number 0x000b57fffe8898b3_BATTERY "0x000b57fffe8898b3 BAT [%.1f %%]" <battery>  {channel="mqtt:topic:test:0x000b57fffe8898b3:battery"}

or set your broker-id to “broker”. (without ", off course)

Channel definition is:

<binding>:<thingtype>:<bridgeid>:<thingid>:<channel>

so for mqtt it is usually (the broker is your bridge):

mqtt:topic:<bridgeid>:<thingid>:<channel>

Really? If you don’t see a thing in things list, your thing definition must be wrong. if you don’t see the “thing” in the control screen, this is most likely due to no items linked.

Hi @job,

First of all, thank you for the detailed OP.

I’m looking to use zigbee2mqtt and had a couple of questions; I have MQTT v2 installed and working with with several sonoff and shelly devices (all config done through files). What are the prerequisites? Do i also need to install Zigbee binding? Any other configurations i should be aware of?

Where would i find the configuration.yaml file? I also have a couple of Xiaomi door sensors, what would the state topic be for that?

Many thanks,

Jeevs :slight_smile:

Zigbee2mqtt is a separate package which must bei nstalled on the raspberry. It then commuicates to OH via mqtt.
So to use the Xiamoi sensors, you first must install zigbee2mqtt on your device. You also have to flash a cc2531 stick with Koenkks zigbee2mqtt firmware. When everything from this side is set up, you can follow the guide at the top of the thread. As you are already familiar with mqtt from your shellys, I think you get the setup of your broker and things.

The Zigbee binding is not required. You can either use zigbee2mqtt or the OH native Zigbee binding. Both have their pros and cons, basically you have to decide which way you go

1 Like

@job thanks for your help, finally i found a way to bring it up working with paper UI :slight_smile:

But in Future i think i will introduce myself more to use files.

Thanks Joachim!
Can you give a thing example for the dimming on, say an ikea bulb?

please describe how you got it working in Paper UI so the rest of us can learn Please thanks

Hey guys,
I’m trying to run zigbee2mqtt without transformations, but still without success.
Here are my brooker, thinks and items:

Bridge mqtt:broker:zigbeeMQTTBroker "zigbeeMQTTBroker" [ host="10.1.0.3", port="1883", secure=false, username="XXX", password="XXX"]
{
    Thing topic zigbeePrinterSmoke "zigbeePrinterSmoke" {
    Channels:
        Type switch : smoke             [ stateTopic="zigbee2mqtt/0x00158d00033e7129/smoke", on="true", off="false"] 
        Type number : smoke_density     [ stateTopic="zigbee2mqtt/0x00158d00033e7129/smoke_density" ] 
        Type number : voltage           [ stateTopic="zigbee2mqtt/0x00158d00033e7129/voltage" ]
        Type number : battery           [ stateTopic="zigbee2mqtt/0x00158d00033e7129/battery" ]
        Type number : linkquality       [ stateTopic="zigbee2mqtt/0x00158d00033e7129/linkquality" ]
    }

Thing topic zigbeeTempPrinter "zigbeeTempPrinter" {
Channels:
    Type number : temperature       [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/temperature" ] 
    Type number : pressure          [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/pressure" ] 
    Type number : humidity          [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/humidity" ] 
    Type number : voltage           [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/voltage" ]
    Type number : battery           [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/battery" ]
    Type number : linkquality       [ stateTopic="zigbee2mqtt/0x00158d00023cfc70/linkquality" ]
  }
}

Items:

Switch	 Printer_Fire_SmokeDetected			"Printer Fire Smoke Detected"  					<smoke>			(gFire, gPrinter)		 {channel="mqtt:topic:zigbeeMQTTBroker:zigbeePrinterSmoke:smoke"}
Number	 Printer_Fire_SmokeDensity			"Printer Fire Smoke Density"  					<smoke>			(gFire, gPrinter)		 {channel="mqtt:topic:zigbeeMQTTBroker:zigbeePrinterSmoke:smoke_density"}
Number	 Printer_Fire_BatteryLevel			"Printer Fire Battery Level"					<batterylevel>	(gFire, gPrinter)		 {channel="mqtt:topic:zigbeeMQTTBroker:zigbeePrinterSmoke:battery"}

Number   Printer_Temperature		"Printer Term Temperature [%.1f]"  			<temperature>   (gPrinter)       	{channel="mqtt:topic:zigbeeMQTTBroker:zigbeeTempPrinter:temperature"}
Number   Printer_Humidity       	"Printer Term Humidity [%.1f]"     			<humidity>      (gPrinter)			{channel="mqtt:topic:zigbeeMQTTBroker:zigbeeTempPrinter:humidity"}
Number   Printer_Pressure           "Printer Term Pressure [%.1f]"     			<pressure>      (gPrinter)          {channel="mqtt:topic:zigbeeMQTTBroker:zigbeeTempPrinter:pressure"}
Number   Printer_BatteryLevel       "Printer Term BatteryLevel"       			<batterylevel>  (gPrinter)      	{channel="mqtt:topic:zigbeeMQTTBroker:zigbeeTempPrinter:battery"}

This is the result:


Can somebody please tell me what I’m doing wrong?
Thanks

Not before you explain what is going wrong. Looks fine on first look.

Did you check the zigbee2mqtt output with e.g. mqtt-explorer?

I"m sorry, I forgot to attach picture

The picture doesn’t help. Did you check the mqtt output?

I checked output from console and i’m receiving the data:

But in paper UI there is error:

Could you show the broker thing? This seems to be the problem.

Which openHAB are you using?

  • If you are running 2.4 you need to restart openhab after making changes. This is a known bug in mqtt 2.4. (the current stable release)

  • I had problems to get mqtt to run in 2.5M6, the current milestone.

  • I am running 2.5M5, which works fine.

1 Like

Sorry, no. I am not running bulbs via zigbee2mqtt. All my bulbs are connected to the hue bridge.