I am writing a S.M.A.R.T. management tool that I want to plug into HA via MQTT. The idea is that the status of a device + failed attributes are passed to an entity representing the disk.
Ideally, I would like to first send a discovery message to set up (or re-re-re…-set-up, it does not hurt) the disk entity and then update the status. This part will be easy.
My problem: disks may change, but a once-discovered entity will live eternally. Worse: it cannot be removed manually via the UI, it needs to be removed via MQTT.
I am not a datacenter and disks will not change daily (hopefully new will just be added annually or so) so I still could use MQTT Explorer or a similar tool to manually remove the entity by sending the right message.
But, in the “let’s make our life difficult” state of mind I would like to have all of this done automatically.
Are there any battle-tested approaches?
Otherwise I will go for the manual curing when needed.
This is not clear cut, you can get some of the way there by not retaining your messages in the MQTT broker (although that can cause other issues).
Such that in the worst case you can just restart HA to clear out the entire state.
I have also found that auto-discovery doesn’t really do updates, you have to completely remove the auto-discovery payload (give it a second to clean up) then re-add your payload in order to make changes.
Finally if you are doing a lot of auto-discovery payloads, you have to rate limit them to about 10 per second or HA gets confused.
I do not know how I missed it, I will throw away what I already wrote (a good exercise anyway). It covers all my needs and I will stick to the manual updates of the docker compose file.