It works and it keeps the last setting after restart or reboot.
However, if HA is down and I change the state of the switch it is not picked up when HA comes back online.
I think that makes sense since RFLink & espRFLinkMQTT are still capturing the events from the physical device and publishing the MQTT to the broker but HA is missing that message while it is offline. Iām not sure how to address that. Does espRFLinkMQTT need to publish those with retain as well or would that mess something else up?
Thank you all for your help. This works now. This last issue isnāt the end of the world but if there is a way to address it, it would be nice.
Thatās what Iām looking into now. Not sure if I can do that with espRFLinkMQTT.
I guess the other way would be to actually do the automation using a Python or some other script on the MQTT broker machine to publish the retain messages if HA is down.
If HA -and- the MQTT broker are both down at the same time then I guess the zombies are going to walk freely in my houseā¦
Please mark my post with the Solution tag. This will help others find it quickly in the event they have a similar requirement and are seeking solutions. By tagging my post, it will appear as a link beneath your first post. It will also place a check-mark next to the topicās title thereby signalling to others that it has an accepted solution.
As for your question about what happens when Home Assistant is offline, I suggest you submit a request to the author of espRFLinkMQTT to add the option of publishing retained messages.
The workaround is to create a āmiddlemanā (running on whatever is hosting your MQTT Broker) that subscribes to rflink/# and re-publishes everything, with retained messages, to new topics (your automation will subscribe to these new topics). You can create this āmiddlemanā using whatever technology you have available on the host (python, Node-Red, etc). FWIW, this would be a trivial Node-Red flow.