Why does this automation no longer fire on the error event?

Logger: homeassistant.components.tradfri
Source: components/tradfri/__init__.py:129 
Integration: IKEA TRÅDFRI (documentation, issues) 
First occurred: 12:49:18 (4 occurrences) 
Last logged: 12:51:49

Keep-alive failed

is happening, and the automation is:

  - alias: Reload Tradfri integration
    id: reload_tradfri_integration
    mode: restart
    trigger:
      - platform: event
        event_type: system_log_event
        event_data:
          level: WARNING
        id: observation
      - platform: event
        event_type: system_log_event
        event_data:
          level: ERROR
        id: failed
    condition:
#       or:
#         - >
#           {{trigger.event.data.name == 'tradfri.base_class' and 'Observation failed for'
#             in trigger.event.data.message[0]}}
      - >
        {{trigger.event.data.name == 'tradfri' and 'Keep-alive failed'
         in trigger.event.data.message[0]}}
#         - >
#           {{trigger.event.data.name == 'coap' and
#               'Error received in UDP connection under DTLS' in trigger.event.data.message[0]}}
    action:
      - service: system_log.write
        data:
          message: >
            Ikea Tradfri '{{trigger.id}}' on {{trigger.event.data.name}} issue logged, reloading integration
          level: warning
          logger: homeassistant.components.tradfri
      - service: script.reload_tradfri_integration
      - service: system_log.write
        data:
          message: >
            Ikea Tradfri integration was reloaded because of {{trigger.id}}
          level: warning
          logger: homeassistant.components.tradfri
      - service: persistent_notification.create
        data:
          title: >
            {{trigger.event.data.level}}: Tradfri reloaded
          message: >
            {{now().timestamp()|timestamp_custom('%X')}}: Ikea Tradfri integration was
              reloaded because of {{trigger.id}}:
              Message: {{trigger.event.data.message[0]}},
              Logger: {{trigger.event.data.name}},
              Source: {{trigger.event.data.source}},
              Level: {{trigger.event.data.level}}

              Full data: {{trigger.event}}

this did work before, so unless system internals have changed, something I can not get my finger behind this.

new post now, because the linked post above is rather old…

I commented the other triggers, because I want to rule out this issue first.

it must be something in the condition, as that wont pass:

Is it possible that the value is not a list but a string?

I believe we have seen this elsewhere in Home Assistant, where the received value can sometimes be a string or a list.

wouldn’t that be odd? I mean, in the older thread I linked to, we concluded it had to be a list.
It’s so hard to test, I have to wait for it to happen again, and, even though the error happens too often since 3 months, its always a long wait if you actually wait for it :wink:

was finally able to ‘force’ a Tradfri error:

event_type: system_log_event
data:
  name: homeassistant
  message:
    - "Error doing job: Task exception was never retrieved"
  level: ERROR
  source:
    - components/tradfri/light.py
    - 93
  timestamp: 1678741082.479729
  exception: |
    Traceback (most recent call last):
      File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 182, in _handle_refresh_interval
        await self._async_refresh(log_failures=True, scheduled=True)
      File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 330, in _async_refresh
        self.async_update_listeners()
      File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 135, in async_update_listeners
        update_callback()
      File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 70, in _handle_coordinator_update
        self._refresh()
      File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 93, in _refresh
        self._device_data = self.coordinator.data.light_control.lights[0]
      File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 84, in light_control
        return LightControl(self)
      File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 40, in __init__
        if ATTR_LIGHT_DIMMER in self.raw[0]:
      File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 71, in raw
        return self._device.raw[ATTR_LIGHT_CONTROL]
    KeyError: '3311'
  count: 1
  first_occurred: 1678741082.479729
origin: LOCAL
time_fired: "2023-03-13T20:58:02.481408+00:00"
context:
  id: 01GVEC84BHYXF5048YRMEWHGQN
  parent_id: null
  user_id: null

not yet the one I was hoping for, but this is one to trigger of too, just as the following:

event_type: system_log_event
data:
  name: homeassistant.util.logging
  message:
    - >
      Exception in set_hub_available when dispatching 'tradfri.gw_status':
      (True,)

      Traceback (most recent call last):
        File "/usr/src/homeassistant/homeassistant/components/tradfri/coordinator.py", line 47, in set_hub_available
          await self.async_request_refresh()
        File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 189, in async_request_refresh
          await self._debounced_refresh.async_call()
        File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 82, in async_call
          await task
        File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 215, in async_refresh
          await self._async_refresh(log_failures=True)
        File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 330, in _async_refresh
          self.async_update_listeners()
        File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 135, in async_update_listeners
          update_callback()
        File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 70, in _handle_coordinator_update
          self._refresh()
        File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 93, in _refresh
          self._device_data = self.coordinator.data.light_control.lights[0]
        File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 84, in light_control
          return LightControl(self)
        File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 40, in __init__
          if ATTR_LIGHT_DIMMER in self.raw[0]:
        File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 71, in raw
          return self._device.raw[ATTR_LIGHT_CONTROL]
      KeyError: '3311'
  level: ERROR
  source:
    - util/logging.py
    - 156
  timestamp: 1678741272.5193412
  exception: ""
  count: 1
  first_occurred: 1678741272.5193412
origin: LOCAL
time_fired: "2023-03-13T21:01:12.522833+00:00"
context:
  id: 01GVECDXYAKNNEWNWYH1V93NX2
  parent_id: null
  user_id: null

and finally the keep-alive error:

event_type: system_log_event
data:
  name: homeassistant.components.tradfri
  message:
    - Keep-alive failed
  level: ERROR
  source:
    - components/tradfri/__init__.py
    - 129
  timestamp: 1678741405.5089765
  exception: ""
  count: 1
  first_occurred: 1678741405.5089765
origin: LOCAL
time_fired: "2023-03-13T21:03:25.521227+00:00"
context:
  id: 01GVECHZTHY80TQY64TPK2B01V
  parent_id: null
  user_id: null

and look what happened:

now that I changed the condition to:

      - >
        {{'Keep-alive failed' in trigger.event.data.message[0]}}

which means:

      - >
        {{trigger.event.data.name == 'tradfri' and 'Keep-alive failed'
         in trigger.event.data.message[0]}}

was incorrect…

and, given the screenshot above, would that mean that the trigger.event.data.name is in fact homeassistant.components.tradfri, so the condition template needs to be:

        {{trigger.event.data.name == 'homeassistant.components.tradfri' and 
          'Keep-alive failed' in trigger.event.data.message[0]}}

now how could the former have ever worked??

well, yes, I can at least confirm the above condition to work:

I’ll have to adapt the other triggers too, if at all, because the errors have changed themselves, and. dont see these occur anymore.

otoh: Tradfri light, various frequent errors: KeyError: '3311', NoneType' object does not support item assignment · Issue #85254 · home-assistant/core · GitHub

trouble has returned since January, after an extended long period of being robust since the linked post above