zachowj / hass-node-red

Companion Component for node-red-contrib-home-assistant-websocket to help integrate Node-RED with Home Assistant Core
MIT License
442 stars 181 forks source link

Component might not initialize correctly with MQTT due to order #238

Closed zvirja closed 6 months ago

zvirja commented 6 months ago

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:

Logger: custom_components.nodered.websocket
Source: components/mqtt/util.py:179
Integration: Node-RED Companion ([documentation](https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/custom_integration/), [issues](https://github.com/zachowj/hass-node-red/issues))
First occurred: 3:39:13 PM (7 occurrences)
Last logged: 3:39:13 PM

Error setting up trigger
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_automation/trigger.py", line 64, in async_attach_trigger
    return await platform.async_attach_trigger(hass, config, action, trigger_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    mqtt_data = get_mqtt_data(hass)
                ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    mqtt_data = hass.data[DATA_MQTT]

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 from utils.

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


Search "nodered|mqtt" (377 hits in 1 file of 1 searched)
    Line   1: 2024-01-04 15:38:57.502 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration nodered which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
    Line  71: 2024-01-04 15:39:08.460 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 2: {'file_upload', 'schedule', 'zone', 'blueprint', 'my', 'image_upload', 'stream', 'tts', 'counter', 'hardware', 'analytics', 'radio_browser', 'scene', 'tag', 'sun', 'hacs', 'energy', 'panel_iframe', 'input_select', 'diagnostics', 'mobile_app', 'device_automation', 'application_credentials', 'samsungtv_smart', 'esphome', 'media_source', 'met', 'nodered', 'auth', 'history', 'local_todo', 'assist_pipeline', 'ffmpeg', 'search', 'input_boolean', 'person', 'persistent_notification', 'conversation', 'lovelace', 'default_config', 'input_datetime', 'automation', 'input_button', 'logbook', 'mqtt', 'rest', 'system_health', 'wled', 'map', 'homeassistant_alerts', 'script', 'calendar', 'trace', 'wake_word', 'input_text', 'lifx', 'repairs', 'config', 'stt', 'input_number', 'timer', 'upnp', 'google_translate', 'onboarding'}
    Line  83: 2024-01-04 15:39:08.672 INFO (MainThread) [homeassistant.setup] Setting up nodered
    Line  84: 2024-01-04 15:39:08.672 INFO (MainThread) [homeassistant.setup] Setup of domain nodered took 0.0 seconds
    Line 109: 2024-01-04 15:39:09.025 INFO (MainThread) [custom_components.nodered] 
    Line 186: 2024-01-04 15:39:12.841 INFO (MainThread) [homeassistant.setup] Setting up mqtt
    Line 187: 2024-01-04 15:39:12.842 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds
    Line 191: 2024-01-04 15:39:13.792 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 196:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 197:     mqtt_data = get_mqtt_data(hass)
    Line 199:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 200:     mqtt_data = hass.data[DATA_MQTT]
    Line 202: KeyError: 'mqtt'
    Line 203: 2024-01-04 15:39:13.797 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 9e10a48b4b9789c5
    Line 204: 2024-01-04 15:39:13.797 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 209:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 210:     mqtt_data = get_mqtt_data(hass)
    Line 212:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 213:     mqtt_data = hass.data[DATA_MQTT]
    Line 215: KeyError: 'mqtt'
    Line 216: 2024-01-04 15:39:13.800 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 6b4c5766a118f97b
    Line 217: 2024-01-04 15:39:13.801 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 222:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 223:     mqtt_data = get_mqtt_data(hass)
    Line 225:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 226:     mqtt_data = hass.data[DATA_MQTT]
    Line 228: KeyError: 'mqtt'
    Line 229: 2024-01-04 15:39:13.804 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: b38645d21688fcb7
    Line 230: 2024-01-04 15:39:13.804 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 235:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 236:     mqtt_data = get_mqtt_data(hass)
    Line 238:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 239:     mqtt_data = hass.data[DATA_MQTT]
    Line 241: KeyError: 'mqtt'
    Line 242: 2024-01-04 15:39:13.808 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 7c1fd30f5af6f23b
    Line 243: 2024-01-04 15:39:13.809 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 248:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 249:     mqtt_data = get_mqtt_data(hass)
    Line 251:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 252:     mqtt_data = hass.data[DATA_MQTT]
    Line 254: KeyError: 'mqtt'
    Line 255: 2024-01-04 15:39:13.812 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 179a45b7b0cb39d3
    Line 256: 2024-01-04 15:39:13.812 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 261:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 262:     mqtt_data = get_mqtt_data(hass)
    Line 264:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 265:     mqtt_data = hass.data[DATA_MQTT]
    Line 267: KeyError: 'mqtt'
    Line 268: 2024-01-04 15:39:13.815 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 5b1f991cc1a95f09
    Line 269: 2024-01-04 15:39:13.815 ERROR (MainThread) [custom_components.nodered.websocket] Error setting up trigger
    Line 274:   File "/usr/src/homeassistant/homeassistant/components/mqtt/device_trigger.py", line 329, in async_attach_trigger
    Line 275:     mqtt_data = get_mqtt_data(hass)
    Line 277:   File "/usr/src/homeassistant/homeassistant/components/mqtt/util.py", line 179, in get_mqtt_data
    Line 278:     mqtt_data = hass.data[DATA_MQTT]
    Line 280: KeyError: 'mqtt'
    Line 281: 2024-01-04 15:39:13.819 INFO (MainThread) [custom_components.nodered.websocket] Device trigger created: 32e67496ee6ee423
    Line 286: 2024-01-04 15:39:14.111 INFO (Thread-2 (_thread_main)) [homeassistant.components.mqtt.client] Connected to MQTT server localhost:1883 (0)
    Line 406: 2024-01-04 15:39:18.471 INFO (MainThread) [homeassistant.components.scene] Setting up mqtt.scene
    Line 407: 2024-01-04 15:39:18.473 INFO (MainThread) [homeassistant.components.sensor] Setting up mqtt.sensor
    Line 408: 2024-01-04 15:39:19.078 INFO (MainThread) [homeassistant.components.camera] Setting up mqtt.camera
    Line 409: 2024-01-04 15:39:19.091 INFO (MainThread) [homeassistant.components.select] Setting up mqtt.select
    Line 410: 2024-01-04 15:39:19.091 INFO (MainThread) [homeassistant.components.alarm_control_panel] Setting up mqtt.alarm_control_panel
    Line 411: 2024-01-04 15:39:19.093 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up mqtt.binary_sensor
    Line 412: 2024-01-04 15:39:19.094 INFO (MainThread) [homeassistant.components.button] Setting up mqtt.button
    Line 413: 2024-01-04 15:39:19.094 INFO (MainThread) [homeassistant.components.climate] Setting up mqtt.climate
    Line 414: 2024-01-04 15:39:19.095 INFO (MainThread) [homeassistant.components.device_tracker] Setting up mqtt.device_tracker
    Line 415: 2024-01-04 15:39:19.095 INFO (MainThread) [homeassistant.components.event] Setting up mqtt.event
    Line 416: 2024-01-04 15:39:19.096 INFO (MainThread) [homeassistant.components.fan] Setting up mqtt.fan
    Line 417: 2024-01-04 15:39:19.097 INFO (MainThread) [homeassistant.components.humidifier] Setting up mqtt.humidifier
    Line 418: 2024-01-04 15:39:19.100 INFO (MainThread) [homeassistant.components.cover] Setting up mqtt.cover
    Line 419: 2024-01-04 15:39:19.101 INFO (MainThread) [homeassistant.components.lawn_mower] Setting up mqtt.lawn_mower
    Line 420: 2024-01-04 15:39:19.103 INFO (MainThread) [homeassistant.components.lock] Setting up mqtt.lock
    Line 421: 2024-01-04 15:39:19.106 INFO (MainThread) [homeassistant.components.light] Setting up mqtt.light
    Line 422: 2024-01-04 15:39:19.106 INFO (MainThread) [homeassistant.components.number] Setting up mqtt.number
    Line 423: 2024-01-04 15:39:19.107 INFO (MainThread) [homeassistant.components.update] Setting up mqtt.update
    Line 424: 2024-01-04 15:39:19.107 INFO (MainThread) [homeassistant.components.text] Setting up mqtt.text
    Line 425: 2024-01-04 15:39:19.108 INFO (MainThread) [homeassistant.components.siren] Setting up mqtt.siren
    Line 426: 2024-01-04 15:39:19.108 INFO (MainThread) [homeassistant.components.water_heater] Setting up mqtt.water_heater
    Line 427: 2024-01-04 15:39:19.108 INFO (MainThread) [homeassistant.components.valve] Setting up mqtt.valve
    Line 428: 2024-01-04 15:39:19.109 INFO (MainThread) [homeassistant.components.vacuum] Setting up mqtt.vacuum
    Line 430: 2024-01-04 15:39:19.110 INFO (MainThread) [homeassistant.components.image] Setting up mqtt.image
    Line 432: 2024-01-04 15:39:19.129 INFO (MainThread) [homeassistant.components.switch] Setting up mqtt.switch
    Line 470: 2024-01-04 15:39:20.203 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: light 0x84b4dbfffe217a3f light from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 471: 2024-01-04 15:39:20.222 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: light 0xbc026efffeef9d07 light from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 472: 2024-01-04 15:39:20.224 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: light 0x5cc7c1fffe479a36 light from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 473: 2024-01-04 15:39:20.249 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x84b4dbfffe217a3f effect from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 474: 2024-01-04 15:39:20.259 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x84b4dbfffe217a3f power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 475: 2024-01-04 15:39:20.280 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0xbc026efffeef9d07 effect from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 476: 2024-01-04 15:39:20.282 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0xbc026efffeef9d07 power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 477: 2024-01-04 15:39:20.299 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x5cc7c1fffe479a36 effect from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 478: 2024-01-04 15:39:20.307 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x5cc7c1fffe479a36 power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 479: 2024-01-04 15:39:20.319 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x70b3d52b600330d6 power_outage_memory from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 480: 2024-01-04 15:39:20.328 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 0x70b3d52b600330d6 indicator_mode from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 481: 2024-01-04 15:39:20.348 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: select 1221051039810110150109113116116_0x00124b0024ca7d41 log_level from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 482: 2024-01-04 15:39:20.350 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x84b4dbfffe217a3f power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 483: 2024-01-04 15:39:20.386 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x84b4dbfffe217a3f color_options from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 484: 2024-01-04 15:39:20.395 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x84b4dbfffe217a3f linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 485: 2024-01-04 15:39:20.423 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x84b4dbfffe217a3f last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 486: 2024-01-04 15:39:20.425 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x84b4dbfffe217a3f update_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 487: 2024-01-04 15:39:20.426 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xbc026efffeef9d07 power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 488: 2024-01-04 15:39:20.430 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xbc026efffeef9d07 color_options from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 489: 2024-01-04 15:39:20.432 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xbc026efffeef9d07 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 490: 2024-01-04 15:39:20.433 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xbc026efffeef9d07 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 491: 2024-01-04 15:39:20.435 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xbc026efffeef9d07 update_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 492: 2024-01-04 15:39:20.436 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xb43522fffebe83b8 battery from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 493: 2024-01-04 15:39:20.475 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xb43522fffebe83b8 action from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 494: 2024-01-04 15:39:20.502 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xb43522fffebe83b8 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 495: 2024-01-04 15:39:20.510 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xb43522fffebe83b8 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 496: 2024-01-04 15:39:20.517 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xb43522fffebe83b8 update_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 497: 2024-01-04 15:39:20.519 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c1387b4cc8b035 battery from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 498: 2024-01-04 15:39:20.519 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c1387b4cc8b035 action from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 499: 2024-01-04 15:39:20.520 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c1387b4cc8b035 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 500: 2024-01-04 15:39:20.522 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c1387b4cc8b035 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 501: 2024-01-04 15:39:20.522 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x5cc7c1fffe479a36 power_on_behavior from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 502: 2024-01-04 15:39:20.523 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x5cc7c1fffe479a36 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 503: 2024-01-04 15:39:20.549 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x5cc7c1fffe479a36 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 504: 2024-01-04 15:39:20.550 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x5cc7c1fffe479a36 update_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 505: 2024-01-04 15:39:20.551 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13880324ceda2 battery from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 506: 2024-01-04 15:39:20.552 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13880324ceda2 action from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 507: 2024-01-04 15:39:20.553 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13880324ceda2 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 508: 2024-01-04 15:39:20.554 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13880324ceda2 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 509: 2024-01-04 15:39:20.555 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 power_outage_memory from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 510: 2024-01-04 15:39:20.556 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 indicator_mode from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 511: 2024-01-04 15:39:20.584 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 power from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 512: 2024-01-04 15:39:20.585 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 current from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 513: 2024-01-04 15:39:20.593 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 voltage from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 514: 2024-01-04 15:39:20.594 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 energy from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 515: 2024-01-04 15:39:20.595 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 516: 2024-01-04 15:39:20.595 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 517: 2024-01-04 15:39:20.596 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0x70b3d52b600330d6 update_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 518: 2024-01-04 15:39:20.598 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13801c57dcfea battery from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 519: 2024-01-04 15:39:20.602 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13801c57dcfea action from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 520: 2024-01-04 15:39:20.603 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13801c57dcfea linkquality from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 521: 2024-01-04 15:39:20.629 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 0xa4c13801c57dcfea last_seen from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 522: 2024-01-04 15:39:20.651 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 1221051039810110150109113116116_0x00124b0024ca7d41 version from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 523: 2024-01-04 15:39:20.652 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 1221051039810110150109113116116_0x00124b0024ca7d41 coordinator_version from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 524: 2024-01-04 15:39:20.653 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 1221051039810110150109113116116_0x00124b0024ca7d41 network_map from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 525: 2024-01-04 15:39:20.657 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: sensor 1221051039810110150109113116116_0x00124b0024ca7d41 permit_join_timeout from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 526: 2024-01-04 15:39:20.663 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0x84b4dbfffe217a3f update_available from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 527: 2024-01-04 15:39:20.695 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0xbc026efffeef9d07 update_available from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 528: 2024-01-04 15:39:20.733 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0xb43522fffebe83b8 update_available from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 529: 2024-01-04 15:39:20.741 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0x5cc7c1fffe479a36 update_available from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 530: 2024-01-04 15:39:20.742 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 0x70b3d52b600330d6 update_available from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 531: 2024-01-04 15:39:20.745 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 1221051039810110150109113116116_0x00124b0024ca7d41 connection_state from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 532: 2024-01-04 15:39:20.746 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor 1221051039810110150109113116116_0x00124b0024ca7d41 restart_required from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 533: 2024-01-04 15:39:20.768 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: update 0x84b4dbfffe217a3f update from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 534: 2024-01-04 15:39:20.788 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: update 0xbc026efffeef9d07 update from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 535: 2024-01-04 15:39:20.800 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: update 0xb43522fffebe83b8 update from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 536: 2024-01-04 15:39:20.802 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: update 0x5cc7c1fffe479a36 update from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 537: 2024-01-04 15:39:20.834 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: update 0x70b3d52b600330d6 update from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 538: 2024-01-04 15:39:20.836 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xb43522fffebe83b8 action_on from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 539: 2024-01-04 15:39:20.838 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xb43522fffebe83b8 action_off from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 540: 2024-01-04 15:39:20.839 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xb43522fffebe83b8 action_brightness_move_down from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 541: 2024-01-04 15:39:20.855 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xb43522fffebe83b8 action_brightness_stop from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 542: 2024-01-04 15:39:20.856 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xb43522fffebe83b8 action_brightness_move_up from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 543: 2024-01-04 15:39:20.862 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c1387b4cc8b035 action_single from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 544: 2024-01-04 15:39:20.863 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c1387b4cc8b035 action_double from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 545: 2024-01-04 15:39:20.871 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c1387b4cc8b035 action_hold from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 546: 2024-01-04 15:39:20.879 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13880324ceda2 action_single from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 547: 2024-01-04 15:39:20.882 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13880324ceda2 action_double from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 548: 2024-01-04 15:39:20.888 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13880324ceda2 action_hold from external application Zigbee2MQTT, version: 1.33.1, support URL: https://www.zigbee2mqtt.io
    Line 549: 2024-01-04 15:39:20.889 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13801c57dcfea action_single from external application Zigbee2MQTT, version: 1.33.2, support URL: https://www.zigbee2mqtt.io
    Line 550: 2024-01-04 15:39:20.891 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13801c57dcfea action_double from external application Zigbee2MQTT, version: 1.33.2, support URL: https://www.zigbee2mqtt.io
    Line 551: 2024-01-04 15:39:20.897 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0xa4c13801c57dcfea action_hold from external application Zigbee2MQTT, version: 1.33.2, support URL: https://www.zigbee2mqtt.io
    Line 552: 2024-01-04 15:39:20.899 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: switch 0x70b3d52b600330d6 switch from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 553: 2024-01-04 15:39:20.901 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: switch 1221051039810110150109113116116_0x00124b0024ca7d41 permit_join from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 554: 2024-01-04 15:39:20.903 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: lock 0x70b3d52b600330d6 child_lock from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 555: 2024-01-04 15:39:20.905 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: button 1221051039810110150109113116116_0x00124b0024ca7d41 restart from external application Zigbee2MQTT, version: 1.35.0, support URL: https://www.zigbee2mqtt.io
    Line 556: 2024-01-04 15:39:20.940 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xb43522fffebe83b8 action_on') has been initialized
    Line 557: 2024-01-04 15:39:20.943 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xb43522fffebe83b8 action_off') has been initialized
    Line 558: 2024-01-04 15:39:20.945 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xb43522fffebe83b8 action_brightness_move_down') has been initialized
    Line 559: 2024-01-04 15:39:20.951 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xb43522fffebe83b8 action_brightness_stop') has been initialized
    Line 560: 2024-01-04 15:39:20.954 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xb43522fffebe83b8 action_brightness_move_up') has been initialized
    Line 561: 2024-01-04 15:39:20.959 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c1387b4cc8b035 action_single') has been initialized
    Line 562: 2024-01-04 15:39:20.962 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c1387b4cc8b035 action_double') has been initialized
    Line 563: 2024-01-04 15:39:20.965 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c1387b4cc8b035 action_hold') has been initialized
    Line 564: 2024-01-04 15:39:20.970 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13880324ceda2 action_single') has been initialized
    Line 565: 2024-01-04 15:39:20.972 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13880324ceda2 action_double') has been initialized
    Line 566: 2024-01-04 15:39:20.977 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13880324ceda2 action_hold') has been initialized
    Line 567: 2024-01-04 15:39:20.980 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13801c57dcfea action_single') has been initialized
    Line 568: 2024-01-04 15:39:20.981 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13801c57dcfea action_double') has been initialized
    Line 569: 2024-01-04 15:39:20.983 INFO (MainThread) [homeassistant.components.mqtt.mixins] Device trigger ('device_automation', '0xa4c13801c57dcfea action_hold') has been initialized
zvirja commented 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 😢

zachowj commented 6 months ago

Are you using a device node with an MQTT device trigger?

zvirja commented 6 months ago

Yeah, I have a couple of Zigbee devices.

The node itself is a pink Device trigger - it the underlying device itself comes from MQTT

zvirja commented 6 months ago

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!

zachowj commented 6 months ago

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.