MQTT Binding state not updating in openhab

Hello all,

for a long time now im using zigbee2mqtt on a CC2652RB. Since the beginning I used the MQTT Binding. Everything works well, except that the states of my ikea tradfri bulbs are not updating.

In the z2m frontend i setup the minimal report interval and there its working fine. When i unplug the light and plug it in again, I get the update the light is on after a minute. Openhab doesnt update the state of the light.

In the zigbee2mqtt documentation for IKEA LED1732G11 i found that for the state i should send a message to zigbee2mqtt/FRIENDLY_NAME/get with payload `{“state”: “”}

So whats the best way to set this up?

My actual setup for the thing is this:

Bridge mqtt:broker:Zigbee2Mqtt "Zigbee2Mqtt Broker" [ ... ] {
 Thing mqtt:topic:kitchen "MQTT Kitchen"{   
            Type string : kitchen_switch "KĂĽchenschalter"   [ stateTopic="zigbee2mqtt/KitchenSwitch", transformationPattern="JSONPATH:$.action"]
            //Type switch : tradfri_remote_update "Update verfĂĽgbar"        [ stateTopic="zigbee2mqtt/KitchenSwitch" , transformationPattern="JSONPATH:$.update_available", on="true", off="false" ]
            Type number : battery "KĂĽchenschalter Batterie"   [ stateTopic="zigbee2mqtt/KitchenSwitch", transformationPattern="JSONPATH:$.battery"]
            Type switch : light_table "Licht KĂĽchentisch"                   [ stateTopic="zigbee2mqtt/KitchenLight/state", commandTopic="zigbee2mqtt/KitchenLight/set", on="ON", off="OFF" ]
            Type dimmer : light_table_brightness "KĂĽchenlicht Helligkeit" [ stateTopic="zigbee2mqtt/Kitchenlight", min=0, max=100, step=1, transformationPatternOut="JS:openhabdimmer2zigbeebridge.js", transformationPattern="JS:tradfri2openhab.js" , commandTopic="zigbee2mqtt/KitchenLight/set"]

And by the way, whats the benefit of the zigbee binding? I established all just with this:

This is unusual. I have this setup and this setup, and if I use the physical light switch to turn the bulbs on and off, their eventual on status is definitely updated in openHAB.

Have you verified that your MQTT broker (as opposed to zigbee2mqtt) is receiving/publishing a status at the time? Use MQTT Explorer or mqtt.fx to check.

It cuts out the MQTT middleman - ZigBee directly into openHAB.

1 Like

This can be very confusing to understand.

Create a new rule to ask your device if what state it is.

rule "Get State of light"
 Item cron "0/30 0 0 ? * * *"
   val mqttActions = getActions("mqtt","mqtt:broker:myMQTTBroker")
   mqttActions.publishMQTT("zigbee2mqtt/FRIENDLY_NAME/get", "{\"state\": \"\"}")
   logInfo("Get State Light" , "FRIENDLY_NAME" )

Openhab will then send a message to the light {"state": ""} ever 30 seconds. You should be able to monitor it in another program like

Do this and tell us what else you see. What is the message the light sends to MQTT to tell you what the state is?

1 Like

Thanks for your response,

I changed my setup like in the first link but no change

Thing mqtt:topic:kitchen "MQTT Kitchen" (mqtt:broker:Zigbee2Mqtt) {   
         Type switch : light_table "Licht KĂĽchentisch" [ stateTopic="zigbee2mqtt/KitchenLight/state", commandTopic="zigbee2mqtt/KitchenLight/set", on="ON", off="OFF" ]

Yes, with mqtt.fx i see an update with the new state after a minute.

sounds like it could be faster but i like the webinterface and the many functions like OTA update, so i think i will keep my setting

Maybe thats why I live with this issue for years now :smiley:

This rule is what I expect to do when reading the documentation of the device but I find an error message for every execution:

Command '' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.

But i do see an entry when subscribing the channel every time i trigger (i triggered the rule with a switch):

"hardwareVersion":1,"ieeeAddr":"0x14b457fffe2e91eb","manufacturerID":4476,"manufacturerName":"IKEA of Sweden",
"model":"LED1732G11","networkAddress":62424,"powerSource":"Mains (single phase)",

But item still not updating

You need to extract state out of JSON

            Type switch : light_table "Licht KĂĽchentisch"                   [ stateTopic="zigbee2mqtt/KitchenLight/state", commandTopic="zigbee2mqtt/KitchenLight/set",transformationPattern="JSONPATH:$.state", on="ON", off="OFF" ]

Thats exactly my old setting (i guess the on/off before transformation pattern should be no difference)

Type switch : light_table "Licht KĂĽchentisch"                   [ stateTopic="zigbee2mqtt/KitchenLight/state", commandTopic="zigbee2mqtt/KitchenLight/set", on="ON", off="OFF", transformationPattern="JSONPATH:$.state" ]

I still get the same error when i trigger the rule. i think its because we send a empty state value instead of On/off, but thats what the documentation says.
Just dont understand why the setting of hafniumzinc is working and the exact same does not for me, nether your suggetion does.

But if i get the event from the broker, there is something wrong with my bridge or channel, like its ignoring the new message. Just dont know what else can i do here. i found some channel options in the UI but none of them sound like could solve my problem.

Does the availibility of the channel make any difference to this issue?

The channel options look ok in my eyes

Looking at your JSON string it is invalid the " on the top line should not be there I think.

I would move to configure things in main ui you can copy paste yaml from @hafniumzinc

you mean the " in the error message?

I cant make the thing work in the UI. I made a broker with the UI which goes online but the generic mqtt thing stays offline no matter if i select my text file generated broker or the UI generated one.

KitchenLight is the friendly name of the device

What am I missing here?
EDIT: now its kind of working but also quite strange.

First i changed the experimental feature “output” in zigbee2mqtt configuration from json to attribute like described in the second link of @hafniumzinc.
Then the UI generated generic mqtt thing “Kitchen Light Test” was online for a moment. I created the channel and linked it to an item all by the UI.

Now the thing and the channel are offline but the Item linked to it is working!? And it even updates when I change the state of the bulb unplug the bulb.

I will check how to get the availability to text based and other differences I find to make my text based setting run. The UI is more comfortable but in the end less flexible. Thats why i will keep the text based configuration (as soon as its working :smiley: )

i did a reboot of openhab and now all is online and even the text file generated kitchen switch is reacting to manual manipulation of the bulb.
Now both switches change to ON a few seconds after power on the bulb.
What i forget to mention above is that i also added availability with 5 seconds to zigbee2mqtt configuration (before it was deactivated). So I still understand it completly but looks like availability has an effect here

I do the same. The first linked tutorial is file based configuration. The first link in the second linked tutorial takes you to a tutorial with file based configurations. Example:

Note that openHAB isn’t very good at picking up changes to the Things files on the fly. You can restart openHAB like you’ve done, or I do this.

Good you got it working.

I have no opinion on if you should use text based config or UI. I simply don’t care enough how you want to do it. UI has the benefit of syntax checking but I use VSCode through SSH to do all my config in text.

Ok so remove all the UI created stuff.

Now for your availability in text is setup like

Bridge mqtt:broker:Zigbee2Mqtt "Zigbee2Mqtt Broker" [ ... ] {
 Thing mqtt:topic:kitchen "MQTT Kitchen" [ availabilityTopic="zigbee2mqtt/KitchenLight/availability", payloadAvailable="online", payloadNotAvailable="offline"] {   
            Type string : kitchen_switch "KĂĽchenschalter"