core: MQTT does not start up properly (sometimes)
The problem
When restarting HA (to apply new settings, updates, etc.) I have a fair chance that MQTT is seemingly starting up properly - but missing certain functionalities. Most prominently, button events are not registered, even though they are clearly visible in Zigbee2MQTT.
The usual workaround: Restarting MQTT until it works again. Sometimes it works after restarting once, sometimes it need 2 or more restarts until all events are registered again.
In the logfile I cannot find anything remotely related. The events seem to just “vanish” silently.
What version of Home Assistant Core has the issue?
core-2024.4.3
What was the last working version of Home Assistant Core?
core-2024.1 (maybe)
What type of installation are you running?
Home Assistant OS
Integration causing the issue
MQTT
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
nothing I can remotely pin point to the issue
Additional information
This issue is fairly new. It probably started in Release 2024.3 or so.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 63 (26 by maintainers)
Commits related to this issue
- Ensure MQTT resubscribes happen before birth message related issue #115958 — committed to home-assistant/core by bdraco 3 years ago
Thanks for testing. I opened a PR to the upstream library as well so we won’t have to use the workaround long term. https://github.com/eclipse/paho.mqtt.python/pull/843
@alexdelprete
I opened https://github.com/home-assistant/core/pull/117672 which should workaround the issue with websockets. Unfortunately I cannot test it myself at the moment because I am on limited emergency power due to the storms in Houston.
If you would like to try it as a custom component you can run the following:
If that doesn’t solve it delete
/config/custom_components/mqttto get back to the core version@umrath Based on the test I have done, I think https://github.com/home-assistant/core/pull/117267 will finally restore functionallity. In a larger setup it seems the default socket buffers are not big enough. Also we reverted increasing the initial subcribe cooldown, so we should wait less long before actually start subscribing to the broker.
That should be fine
Yes exactly
It looks like the paho passes the wrapper when using websockets and
setsockoptmethod isn’t exposed on theWebsocketWrapper. That’s unfortunate. It looks like their example also has the same issue https://github.com/eclipse/paho.mqtt.python/blob/d45de3737879cfe7a6acc361631fa5cb1ef584bb/examples/loop_asyncio.py#L92Let me see if I can come up with a workaround
I have been having issues with my Roborock S5 not reconnecting to HA and all of my Zigbee buttons being non-responsive after a restart. I actually had the same problem in the subsequent reboot after upgrading to 2024.5.2 but I just restarted again and everything worked.
I reload the integration. In 2024.5.1 this fixed the problem reliably twice in a row (did not work in 2024.5).
@umrath clear, thanks!
If you are adventurous and want to test as a custom component
You have to wait till 2025.5.1
That does sound like the exact problem we just fixed in https://github.com/home-assistant/core/pull/116471
I tested. It’s mentioned here https://github.com/home-assistant/core/issues/115958#issuecomment-2082916942