bieniu/ha-shellies-discovery-gen2

Retain flag

Closed this issue · 1 comments

I’m using Shelly pro series for my light control and after rebooting MQTT status of relay is in “unknown” state. (Via Shelly api everything is ok).
image
Shelly gen2 lost option to use in easy way retain flag which should resolve my problem :).

One of Reddit gents got idea how to resolve that using your script - is it possible to implement ?

9mo ago

If you are using Home Assistant and use the gen 2 discovery script for setting it up (https://github.com/bieniu/ha-shellies-discovery-gen2/) - the script that it installs on the device to regularly send status updates to MQTT, can be modified to use the retain flag:

https://github.com/bieniu/ha-shellies-discovery-gen2/blob/master/scripts/send_device_status.js#L13

Update the MQTT.publish options to set the retain flag - https://shelly-api-docs.shelly.cloud/gen2/Scripts/ShellyScriptLanguageFeatures#mqttpublish

The script sends data every 30 seconds, so even if the relay state is not known after HA start, it takes a maximum of 30 seconds. The retain flag may cause problems, e.g. the relay state may change during HA restart and HA will read the state from retained data.

What's more, with a properly configured shellies_discovery_gen2 automation, the update of states is forced on HA start. Check if your automation is up to date and if it starts on HA start.