I (accidentally) ran mosquitto_sub with --remove-retained and the wrong filter set causing all retained messages on the broker to be removed.
No big deal, I thought, one TelePeriod of Tasmota later (and the equivalent for other integrations), all retained messages would be there again, and apart, HA has its own database, anyway… but no…! Instead, I found all devices gone from HA.
After an hour or so, they were all back, but some entity IDs had changed to a new naming scheme, breaking lots of stuff in my automations etc…
It’s all fixed now, but I’d love to understand what went wrong. Can someone shed any light on the role of retained messages, please?
Thanks for that @francisp, I read the entire Essentials guide and I think I understand it, but maybe not. What I don’t get is why removing retained messages would make HA think that all devices are gone? Doesn’t it keep its own state? And isn’t the next tele message from Tasmota going to put a new, more up-to-date retained message in place?
No. I have around 800 entities in MQTT, including a lot of Tasmota (ranging from version 6.6 to 13.4)
Tasmota (in older versions, but probably in newer versions too) only sends (retained) discovery messages when a devices reboots (this is, after power loss or manual reboot). If there are no discovery messages (because you deleted them), HA thinks the device does no longer exist.
In fact, this is what happens when you delete a MQTT device or entity in HA: HA sends an empty MQTT on that topic to the broker (which is in fact deleting the topic from the broker)