MQTT topic not published?

I’m fairly new to OH… started using 2.5 on RPI3 about a year ago but didn’t get far due to an accident befalling the RPI :slight_smile: then not having time. So I just started with OH3 on x86/Debian.

Zigbee2mqtt = working
MQTT.fx confirms that my zigbee devices respond as expected, e.g. I can toggle the relay output by publishing the relevant topic/payload.

Test config:

As per https://community.openhab.org/t/zigbee2mqtt-revisited-no-more-ugly-transformations/86362 only I changed battery string from float to decimal since the former resulted in NaN.

Things

Bridge mqtt:broker:584e1eaa63 [host=“localhost”, secure=false, clientID=“OpenHAB”] {
Thing topic Tradfri_E1743_1 “Tradfri_E1743_1” @ “584e1eaa63” {
Channels:
Type string : action “action” [ stateTopic = “zigbee2mqtt/Tradfri_E1743_1/action” ]
Type number : battery “battery” [ stateTopic = “zigbee2mqtt/Tradfri_E1743_1/battery” ]
Type number : linkquality “linkquality” [ stateTopic = “zigbee2mqtt/Tradfri_E1743_1/linkquality” ]
}

Thing topic ConservHeater "Conserv_Heater" @ "584e1eaa63" {
    Channels:
        Type switch : state "state" [ stateTopic = "zigbee2mqtt/Conserv_Heater/get", commandTopic = "zigbee2mqtt/Conserv_Heater/set", on="ON", off="OFF" ]
        Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/Conserv_Heater/linkquality" ]
}

}

Items

String Tradfri_E1743_1_ACTION “E1743-1 [%s]” {channel=“mqtt:topic:584e1eaa63:Tradfri_E1743_1:action”}
Number Tradfri_E1743_1_BATTERY “E1743-1 Bat [%d %%]” {channel=“mqtt:topic:584e1eaa63:Tradfri_E1743_1:battery”}
Number Tradfri_E1743_1_LINKQUALITY “E1743-1 LQ [%d]” {channel=“mqtt:topic:584e1eaa63:Tradfri_E1743_1:linkquality”}

String ZBR3_ConservatoryHeater_ACTION “Heater [%s]” {channel=“mqtt:topic:584e1eaa63:ConservHeater:state”}
Number ZBR3_ConservatoryHeater_LINKQUALITY “Heater LQ [%d]” {channel=“mqtt:topic:584e1eaa63:ConservHeater:linkquality”}

Sitemap

Text label=“Conservatory” {
Frame label=“Heater” {
Switch item=ZBR3_ConservatoryHeater_ACTION label=“Heater” icon=“heating”
}
}

Looking from the web UI of OH I can view the E1743 channel state [action/battery/lqi] changing in realtime.
For the (Sonoff) ZBR3 the lqi is displayed however the state always remains OFF. Same with the sitemap view. Using the app or BasicUI the state (as displayed in OH channels) can be toggled but the relay output does not change state.

I’m not convinced that OH is even publishing the ConservHeater topic.

I guess I’m missing something in the OH config; any pointers please?

As you have MQTT.fx you should be able to confirm this - can you?

Also, you may have fallen victim to the annoying bug where openHAB sometimes doesn’t properly register changes made to Things files (certainly an OH2 problem, not sure about OH3). You can restart openHAB, or do this.

How are you doing the toggling? Your Item is a String, not a Switch? Try changing

String ZBR3_ConservatoryHeater_ACTION "Heater [%s]" {channel="mqtt:topic:584e1eaa63:ConservHeater:state"}

To

Switch ZBR3_ConservatoryHeater_ACTION "Heater [%s]" {channel="mqtt:topic:584e1eaa63:ConservHeater:state"}

Thanks for the response and the tip.

I stopped OH… I still see the relay announcing its state every 5 minutes. At least I assume this is the relay pushing, and not zigbee2mqtt polling the device.

After restarting OH:
I see OH log messages every 1 min: Starting MQTT broker connection to ‘127.0.0.1’ with clientid
Also looks an item has been corrupted that was previously ok

Will have to check both tomorrow

And I added this last minute - do set your Item to Switch:

Also

Instead of localhost, try using the actual IP address of your device (192.168.1.13, or whatever yours is)- that seemed to work better for me (though I set mine up some time back, so the issue may have been resolved by now).

Your heater topics are wrong. Do not know this device, but i doubt zigbee2mqtt uses anything like this.

Your state topic is missing the “state” and a “get” is usually not used. Your command topic misses also the “state”.

Had some issues with Z2M… not touched the system since last post so expected it all to be functioning. However, no zigbee comms and Z2M publish failures when trying to send commands. Z2M log shows nothing of interest.
The frustrating part is OH shows MQTT devices as online/green. If there is a problem I’d rather show that in the UI/sitemap.

The OH log message " Try to restore connection to ‘127.0.0.1’. Next attempt in 60000ms" originates from (guess) a duplicate MQTT broker since the ID does not match that of the one defined with my zigbee.things file. This duplicate fails to connect since it is anon - my MQTT requires auth. I need to work out where it is defined… there is only one MQTT broker listed in things UI. :face_with_raised_eyebrow:

Thanks for the tip on adding state… my button on the sitemap works now. :smiley:

For reference, with my working config below: SONOFF BASICZBR3 control via MQTT | Zigbee2MQTT

My things
> Thing topic ConservHeater “Conserv_Heater” @ “584e1eaa63” {

    Channels:
        Type string : state "state" [stateTopic = "zigbee2mqtt/Conserv_Heater/state", on="ON", off="OFF" ]
        Type switch : switch "switch" [ stateTopic = "zigbee2mqtt/Conserv_Heater/get", commandTopic = "zigbee2mqtt/Conserv_Heater/set", on="ON", off="OFF" ]
        Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/Conserv_Heater/linkquality" ]
}

My items

// Conservatory Relay for heater
String ZBR3_ConservatoryHeater_STATE “Heater [%s]” {channel=“mqtt:topic:584e1eaa63:ConservHeater:state”}
Switch ZBR3_ConservatoryHeater_ACTION “Heater [%s]” {channel=“mqtt:topic:584e1eaa63:ConservHeater:switch”}
Number ZBR3_ConservatoryHeater_LINKQUALITY “Heater LQ [%d]” {channel=“mqtt:topic:584e1eaa63:ConservHeater:linkquality”}

I’ve also got the Ikea dimmers working (state/switch/brightness) - anyone know how to define the second payload?

e.g. zigbee2mqtt/FRIENDLY_NAME/set {“brightness”:254,“transition”:10}

It took me a while to get back to the finer points of formatting.
Here’s the solution (things definition):

Type dimmer : dimmer "Dimmer" [ stateTopic = "zigbee2mqtt/Kitchen_IkeaDimmer1/brightness", commandTopic = "zigbee2mqtt/Kitchen_IkeaDimmer1/set", min=0, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s , \"transition\": 5.0}" ]

Note the commandTopic follows a different format (cf. stateTopic) for compatibility with zigbee2mqtt.

Here’s the payload output:

{ “brightness” : 0 , “transition”: 5.0 }

Thanks to… [SOLVED] transformationPatternOut seems not to work, but why? - #12 by kluszczyn

Only wish I knew why the zigbee coordinator randomly crashes, not an openhab issue though.

1 Like