I’ve noticed some inconsistencies in state behavior from zigbee2mqtt:
When switched on i can see two different messages depending on device manufacturer:
zigbee2mqtt/Lamp/set ON
zigbee2mqtt/Lamp/set {“state”:“ON”}
The first one is an Ikea switch, not using JSON payload format
Second one is a Philips Hue Light bulb using JSON payload format
Maybe i’ve made some mistake somewhere, or is this by design different for different device manufacturers?
Or just different by device class (one is a switch the other a light bulb)
Thanks for your feedback!. I had hoped that zigbee2mqtt would straighten out these manufacturer differences internally somehow…
I have another platform subscribing to the zigbee2mqtt topic, so it seems that i have to be prepared to receive different payload formats depending on manufacturer.
You shouldn’t need to worry about it. If you have the homeassistant option enabled in your z2m settings it will publish the required discovery topics home assistant can use and the devices will automatically appear under the mqtt integration. No need to configure any mqtt config yourself.
I understand that and all is fine within Home Assistant !
The concern is actually not Home Assistant related but my own legacy “ESPEasy” platform that i’m running next to Home Assistant.
Maybe i’m going to migrate those units to ESPHOME some day.
Maybe i have to raise a topic on a specific zigbee2mqtt forum because it is not a Home Assistent issue, although zigbee2mqtt is running on top of HAOS.
My ESPEasy devices are connected to the same MQTT broker as zigbee2mqtt and Home Assistent so they receive events like switching a zigbee light.Using rules i can trigger custom actions on the ESPEasy device after receiving such event.
And here i noticed that the event payload format seems to depend on the manufacturer and is different between Ikea and Hue.
I’m not sure if it’s inconsistent: a switch typically has a binary state, ON or OFF, so to limit the amount of data required to change state, a simple “ON”/“OFF” string would be sufficient.
Lights often have other properties that can be set besides state, like brightness, color, transition time, etc. In such a case, using JSON makes more sense.
Although the documentation suggests that /set should only be used with JSON; if you want to change the state directly, the topic should be /set/state
When i look at the documentation, it seems that there is some incorrect behaviour in my own zigbee2mqtt setup.
Zigbee2mqtt actually instructs Home Assistant to use zigbee2mqtt/HA/Zolder/Bureaulamp/set
topic with a plain payload OFF/ON
And according to the documentation the topic should then be zigbee2mqtt/HA/Zolder/Bureaulamp/set/state
Contrary to documentation, zigbee2mqtt seems to accept non-json payloads on “/set” anyway, at least in my setup.
Maybe this is due to some backwards compatibility?