I removed an esphome device (shouldn’t be related to the problem) and restarted HA, and now my MQTT devices are flip-flopping availability. These are devices that have been working well for years, and all of them are showing this behavior. I’ll attach picture showing the difference in a temperature sensor before and after reboot.
In an attempt to debug, I watched MQTT with mosquitto_sub. I noticed that the homeassistant/status topic was toggling:
I also looked there, but didn’t see anything suspicious. Client connecting and disconnecting, but nothing obviously correlating to HA coming and going.
I have been watching my home assistant logs, and get clear messages about connecting to MQTT. Things are quiet for a while, then I get this flurry of activity. I include the non-MQTT messages for completeness in case they are related.
HA log:
2024-03-27 16:14:13.629 INFO (MainThread) [homeassistant.config_entries] Reloading configuration entries because disabled_by changed in entity registry: 595e016761da4a359654ff65c4aa0d6f
2024-03-27 16:14:15.423 INFO (MainThread) [homeassistant.components.alarm_control_panel] Setting up alarm_control_panel.mqtt
2024-03-27 16:14:15.423 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.mqtt
2024-03-27 16:14:15.423 INFO (MainThread) [homeassistant.components.button] Setting up button.mqtt
2024-03-27 16:14:15.424 INFO (MainThread) [homeassistant.components.camera] Setting up camera.mqtt
2024-03-27 16:14:15.424 INFO (MainThread) [homeassistant.components.climate] Setting up climate.mqtt
2024-03-27 16:14:15.424 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.mqtt
2024-03-27 16:14:15.425 INFO (MainThread) [homeassistant.components.event] Setting up event.mqtt
2024-03-27 16:14:15.425 INFO (MainThread) [homeassistant.components.cover] Setting up cover.mqtt
2024-03-27 16:14:15.425 INFO (MainThread) [homeassistant.components.fan] Setting up fan.mqtt
2024-03-27 16:14:15.425 INFO (MainThread) [homeassistant.components.humidifier] Setting up humidifier.mqtt
2024-03-27 16:14:15.426 INFO (MainThread) [homeassistant.components.image] Setting up image.mqtt
2024-03-27 16:14:15.435 INFO (MainThread) [homeassistant.components.lawn_mower] Setting up lawn_mower.mqtt
2024-03-27 16:14:15.435 INFO (MainThread) [homeassistant.components.light] Setting up light.mqtt
2024-03-27 16:14:15.436 INFO (MainThread) [homeassistant.components.lock] Setting up lock.mqtt
2024-03-27 16:14:15.436 INFO (MainThread) [homeassistant.components.number] Setting up number.mqtt
2024-03-27 16:14:15.436 INFO (MainThread) [homeassistant.components.select] Setting up select.mqtt
2024-03-27 16:14:15.436 INFO (MainThread) [homeassistant.components.scene] Setting up scene.mqtt
2024-03-27 16:14:15.437 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2024-03-27 16:14:15.437 INFO (MainThread) [homeassistant.components.siren] Setting up siren.mqtt
2024-03-27 16:14:15.437 INFO (MainThread) [homeassistant.components.switch] Setting up switch.mqtt
2024-03-27 16:14:15.438 INFO (MainThread) [homeassistant.components.text] Setting up text.mqtt
2024-03-27 16:14:15.438 INFO (MainThread) [homeassistant.components.update] Setting up update.mqtt
2024-03-27 16:14:15.438 INFO (MainThread) [homeassistant.components.vacuum] Setting up vacuum.mqtt
2024-03-27 16:14:15.439 INFO (MainThread) [homeassistant.components.water_heater] Setting up water_heater.mqtt
2024-03-27 16:14:15.455 INFO (Thread-658 (_thread_main)) [homeassistant.components.mqtt.client] Connected to MQTT server localhost:1883 (0)
...
The MQTT broker logs show this at the same time:
1711577655: New connection from 127.0.0.1:35011 on port 1883.
1711577655: New client connected from 127.0.0.1:35011 as 64D7wEiALr2ihz46da8JTb (p2, c1, k60, u'myusername').
1711577656: Client 4fz0cJSqroqdgeeBpcb6Ab closed its connection.
1711577656: Client 28R1er2Za5g4jEzpzOINGm closed its connection.
Is there anything there that could indicate why HA reconnected to MQTT?
(edit: removed red herring errors by disabling automations causing them. The dump above still happens – timing it shows it’s every 30 second)
New information: That first entry in the log didn’t used to show up in my logs. What causes this and how do I find the problem entity?
INFO (MainThread) [homeassistant.config_entries] Reloading configuration entries because disabled_by changed in entity registry: 595e016761da4a359654ff65c4aa0d6f
A quick look in my core.entity_registry file in .storage shows lots of devices with that value as the config_entry_id. Is that normal to reuse config_entry_id between entities?
Edit: Found it clearly labeled in core.config_entries:
Enable debug logging for mqtt to see if that reveals any further info.
Connect to your broker with MQTT Explorer and watch the /homeassistant discovery topics to see if any of them are updating constantly (the topic will highlight when a message is received).