Zigbee2mqtt "retain" not working for Xiaomi Power Socket ZNCZ02LM

Hi all,
I’m having great difficulty in getting the zigbee2mqtt hass.io add-on to “retain” the state of the Xiaomi Power Socket ZNCZ02LM. https://www.zigbee2mqtt.io/devices/ZNCZ02LM.html

I have read through the documentation, and tried adding the “retain: true” to devices.yaml, config.yaml, in both /share/zigbee2mqtt folder and /data/ folders with no success.

It is incredibly frustrating when this device is also used as a “repeater” for other devices on my Zigbee network but it will not retain it’s “ON” state if there is a power outage etc…

Can anyone please assist?

Thanks in advance


The retain setting is for the MQTT messages, not for the socket’s state during a power outage. See their documentation for details of that setting, and what (if any) device specific options there are for the device to restore state on startup (very few offer that).

Thanks for your fast reply!

I’m just figuring my way around MQTT etc, seems like I misunderstood the “retain” setting.
Thank you for clearing that up. I’ll see what else I can find.

Thanks again :slight_smile:

it doesn’t seem the “retrieve_state” setting works for this device.

Hmmmmm, perhaps there is a way that if the device is disconnected and the reconnected perhaps nodeRED or something can detect this and change the state to “ON”

Thoughts @Tinkerer?

If the state changes, for example going to unavailable you can detect that and act on it. That works in either Node Red or YAML, or anything else.

I have done something similar in the past, as I use the concept of room lighting modes, and if a light goes from unavailable I’ll check that it matches the current room mode, and if not turn it on or off.