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
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.
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.
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.
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…)
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.
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.
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
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