Closed zvirja closed 6 months ago
I would have created a PR with a fix, but I don't know HASS too good for it to not something stupid 😄 Hope the fix is tiny and can be done fast, this issue is really annoying 😢
Are you using a device node with an MQTT device trigger?
Yeah, I have a couple of Zigbee devices.
The node itself is a pink Device trigger - it the underlying device itself comes from MQTT
Adding the following changes locally helped, but again am not sure whether that's idiomatic:
from homeassistant.components.mqtt.util import async_wait_for_mqtt_client
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
await async_wait_for_mqtt_client(hass)
If you feel that it's a right way to do - I can raise a PR with the change!
My knowledge is lacking on the HA side for this. This method should fix the issue. I was thinking about fixing this on the NR side where it doesn't attempt to register device triggers until HA is in a running state but this approach is probably better.
Feel free to submit a PR.
Version of the custom_component
Version 3.1.2
Configuration
IMO that is not relevant for this issue
Describe the bug
When I restart Home Assistant my MQTT triggers in NodeRed does not work (I press the button, nothing happens). I experience that not every reboot, rather randomly and sometimes it works. It helps to go to NodeRed UI and re-deploy everything. But it's annoying to do that after each reboot.
When it fails, I can find the following error in the log:
Looking a bit into the log below (it's INFO, not DEBUG, but that should be enough IMO) and source code it's obvious that the issue is in initialization order. Component is simply initialized too early, before MQTT component has a chance to kick in.
It should be fixed by either initializing later (which should fix the whole family of errors) or fix this particular one by using
async_wait_for_mqtt_client
fromutils
.It looks like the initialization order is random (as they are all in stage 2), so that explains why sometimes it works when MQTT is initialization before.
Debug log