MQTT Broker shows Online, Zigbee Switch(es) show up in zigbee2mqtt, MQTT Thing shows offline

Hey all! I’m on a fresh install of Openhabian (Openhab 4) + Mosquitto + zigbee2mqtt. I followed the following guides on setting this up:

As it stands, I have the following setup:

Zigbee2MQTT & Mosquitto
In zigbee2mqtt I have both of my switches paired. I have availability on, and I can see via the
mosquitto_sub -h 10.0.0.21 -W 1 -v -t zigbee2mqtt/+/availability
command that availability is being casted (Sorry, new to the terminology, im sure theres a correct word for it).

Output from the command:

zigbee2mqtt/FanSwitch/availability {"state":"online"}
zigbee2mqtt/FanLight/availability {"state":"online"}
Timed out

Mosquitto Configuration:

Openhab

In Openhab I have a Mosquitto MQTT broker defined as such:

I have attempted to add the FanSwitch device to Openhab using the following configuration, however no matter what I do, its always offline:

I have tried everything I can think of:

  • Removing the Transformation
  • Reinstalling zigbee2mqtt & Mosquitto
  • Various inputs for available/not available payload (although they should be online/offline since thats the output of the command above, right?)

Any input on what I can try would be greatly appreciated. I’m completely out of ideas. Let me know if theres any more information I can provide.

Thanks in advance!

published?

For most stuff in OH, but especially Things, screen shots tell us almost nothing. Click on the code tab and paste the text you find there.

Use code fences

```
code goes here
```

Unless the online/offline message is retained (I’ve no idea if zigbee2mqtt applies the retained flag) OH would have had to be both online and connected to the Mosquitto broker and this Thing would have had to have been configured as you’ve shown before zigbee2mqtt published it’s online status message.

If any of that stuff on the OH side happened after zigbee2mqtt published the message, OH didn’t get the message so it has no idea whether the device is online, which defaults to offline.

Thanks for the quick reply! Ill make sure to include code in the future vs screenshots. Here is the code from the MQTT Thing:

UID: mqtt:topic:MosquittoMQTTBroker:FanSwitch
label: FanSwitch
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/FanSwitch/availability
  payloadAvailable: online
bridgeUID: mqtt:broker:MosquittoMQTTBroker
location: Man Cave

Unless the online/offline message is retained (I’ve no idea if zigbee2mqtt applies the retained flag) OH would have had to be both online and connected to the Mosquitto broker and this Thing would have had to have been configured as you’ve shown before zigbee2mqtt published it’s online status message.

I remember seeing something like this in zigbee2mqtt in the device settings. I’ll try enabling it and doing a restart of the pi.

If any of that stuff on the OH side happened after zigbee2mqtt published the message, OH didn’t get the message so it has no idea whether the device is online, which defaults to offline.

Thats an interesting point. I don’t think the MQTT Thing was made when the message was published. I’ll see if theres a way to have it re-publish if the retain flag set doesn’t do the job.

I use mosquitto_sub to check the data.
Example:

mosquitto_sub -h 192.168.1.164 -v -t "zigbee2mqtt/sensor-blitzwolf-kitchen/#"

gives result:

zigbee2mqtt/sensor-blitzwolf-kitchen/availability {"state":"online"}
zigbee2mqtt/sensor-blitzwolf-kitchen {"battery":50,"humidity":78.1,"last_seen":"2024-01-31T07:52:40+11:00","linkquality":109,"temperature":23.6,"voltage":2600}

You would do:

mosquitto_sub -h 10.0.0.21 -v -t "zigbee2mqtt/FanSwitch/#"

See what results you get.

If that doesn’t work then the mosquitto.conf might need the add 0.0.0.0 to the listener:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid
#listener 1883
listener 1883 0.0.0.0
allow_anonymous true
persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

Your screenshot above shows a transformation for the availability topic but your text config does not. You do indeed need that or you need to change your payload fields to exactly match the online/offline messages.

The retained flag will do the job. What that means is that broker will keep the message and when ever a client subscribes to that topic, the broker will immediately published the retained message. This ensures that the message gets delivered even if the subscriber wasn’t connected when the message was published. Note that the broker doesn’t keep track of whether it’s already sent that message to that client. So every time OH connects to the broker, it’ll get that same retained message again.

But usually that’s OK.

I tried this command, and it gave the following output:

zigbee2mqtt/FanSwitch/availability {"state":"online"}
zigbee2mqtt/FanSwitch/update-state available
zigbee2mqtt/FanSwitch/update-installed_version 33685764
zigbee2mqtt/FanSwitch/update-latest_version 33685765
zigbee2mqtt/FanSwitch/linkquality 189
zigbee2mqtt/FanSwitch/fan_state ON
zigbee2mqtt/FanSwitch {"fan_state":"ON","linkquality":189,"update":{"installed_version":33685764,"latest_version":33685765,"state":"available"}}

I tried adding 0.0.0.0 to the listener in the mosquitto.conf file, and now zigbee2mqtt GUI does not open… The broker shows as online though, the switch still offline. Some guidance on where I can find the log files for zigbee2mqtt would be appreciated to check this (I cant find it…)

The transformation pattern is missing:
Here is mine:

UID: mqtt:topic:mqttbroker:8a54d5a032
label: Zigbee temperature kitchen
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  transformationPattern: JSONPATH:$.state
  availabilityTopic: zigbee2mqtt/sensor-blitzwolf-kitchen/availability

Adding this did not resolve the issue.

I had a problem with adding 0.0.0.0 to the listener, but I resolved it by updating the zigbee2mqtt config yaml file to look for the MQTT server at the IP vs localhost. Now i’m basically back to square one, except I have the “retain” checkbox clicked in zigbee2mqtt and the transformation pattern applied to the MQTT Thing in OpenHAB.

Try deleting the fan thing and start again.

no luck

UID: mqtt:topic:MosquittoMQTTBroker:db65e9009a
label: FanSwitch
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  transformationPattern: JSONPATH:$.state
  availabilityTopic: zigbee2mqtt/FanSwitch/availability
bridgeUID: mqtt:broker:MosquittoMQTTBroker
location: Man Cave

Hi, did you check you zigbee2mqtt settings?

My thing code is

UID: mqtt:topic:mqttbroker:Fensterkontakt_Schublade
label: Fensterkontakt_Schublade
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/Fensterkontakt_Schublade/availability
  payloadAvailable: online

No transformation pattern

Greets

I used to have no transformations but I think after upgrading zigbee2mqtt it added
{“state”:“online”} and I had to go and add transformation to all my zigbee devices.
I am using simple availability as well.

I am on version: 1.35.1 commit: 9eaaa0f9

The OP has run:
mosquitto_sub -h 10.0.0.21 -v -t “zigbee2mqtt/FanSwitch/#”`

zigbee2mqtt/FanSwitch/availability {"state":"online"}

Hey! Yes, I have this setting set to Availability(Simple) like yours. It does not fix the issue :frowning:

Hmm…
Try the mosquitto_sub thing and see which answer you get.
I’m also on z2m version 1.35.1 and I get availability online like always… No transformation needed…
Greets

Still nothing sadly.

$ mosquitto_sub -h 10.0.0.21 -v -t zigbee2mqtt/FanSwitch/#

zigbee2mqtt/FanSwitch/availability {"state":"online"}
zigbee2mqtt/FanSwitch/update-state available
zigbee2mqtt/FanSwitch/update-installed_version 33685764
zigbee2mqtt/FanSwitch/update-latest_version 33685765
zigbee2mqtt/FanSwitch/linkquality 156
zigbee2mqtt/FanSwitch/fan_state ON
zigbee2mqtt/FanSwitch {"linkquality":156}

Configuration:

UID: mqtt:topic:MQTT_Broker:FanSwitch
label: FanSwitch
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  transformationPattern: JSONPATH:$.state
  availabilityTopic: zigbee2mqtt/FanSwitch/availability
bridgeUID: mqtt:broker:MQTT_Broker
location: Man Cave

Im on z2m 1.35.1 commit: 4b6f50da

I also tried remaking the broker this time, and repairing the devices (Even though they work in z2m no problem). Neither helped

Check this out

https://www.zigbee2mqtt.io/guide/configuration/device-availability.html#availability-payload

im not sure what your comment is suggesting. I have this set as the availability topic, is that not the correct configuration? I do not have legacy mode enabled, and I have the transformation pattern applied, so OH should be picking up the device availability, no?

Ok. I’ve finally found the solution. Even though I have a transformation, for some reason I had to switch the publish mode for availabilty to legacy in the z2m configuration.yaml.

configuration.yaml:

legacy_availability_payload: true

Im going to progress further in the setup now, and if all goes well this will be marked as the solution.

Edit:
The configuration for the channel needed tweaking (Inovelli switches seem to need special parameters for fan switches), but here is the full working config. I can finally toggle the fan on/off and it seems to work fine!

UID: mqtt:topic:MQTT_Broker:FanSwitch
label: FanSwitch
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/FanSwitch/availability
  payloadAvailable: online
bridgeUID: mqtt:broker:MQTT_Broker
location: Man Cave
channels:
  - id: MC_Fan_Switch
    channelTypeUID: mqtt:switch
    label: FanSwitch
    description: Fan Switch in the Man Cave
    configuration:
      commandTopic: zigbee2mqtt/FanSwitch/set
      formatBeforePublish: '{"fan_state": "%s"}'
      stateTopic: zigbee2mqtt/FanSwitch/fan_state
      off: OFF
      on: ON