So I have a custom baked (my own sbc and code) relay bank. I have an init function that’s called when the machine boots which sends the mqtt config discovery switch payloads for each relay to broker/HA and HA creates the entities. It’s all working fine
So when HA restarts/reboots it looses the entities which I understand is the way it is
So what is the best practice to have HA request the discovery payloads when it reboots. Should I just make a HA boot delay trigger that publishes an mqtt topic making the request? What do esphome and others do to ensure that their devices are recognized by HA upon reboot of device or HA? Maybe I now need to convert my device into an integration instead of using mqtt discovery? Would doing that better handle this issue?
Further I am using the emqx broker and I wonder if can get the broker to persist those payloads and to send them to any connecting client. Although that might be possible seems rather prone failure.
for those interested here is node code (using mqtt.js)
mqtt.publish(`${topic}/config`,null) // clear existing payload for that topic
mqtt.publish(`${topic}/config`, payload,{retain:true})
note that I first publish a null payload. Per the mqtt broker docs publishing an empty payload to that topic will clear it from being retained. Since whenever this device code restarts it may have updated payloads I clear the existing retained one first.
FYI I run the emqx broker as a docker container rather than mosquitto as I keep having trouble with it.