Automation - how to catch an automation error and alert based on it

I’ve tried a few techniques to catch automation errors or failures to run. Ideally what I want is when an automation fails due to an integration not working, or an entity not responding, the automation crashes out silently.
I can’t seem to find an event that triggers when the automations fail or error out. I’ve tried this:

alias: alert-on-errors
description: ""
trigger:
  - platform: event
    event_type: system_log_event
  - platform: event
    event_type: automation_reloaded
  - platform: event
    event_type: automation_failed
  - platform: event
    event_type: integration_discovered
  - platform: event
    event_type: platform_discovered
  - platform: event
    event_type: call_service_not_found
  - platform: event
    event_type: service_executed
condition: []
action:
  - service: persistent_notification.create
    data:
      title: FAULT in HA found
      message: "{{ trigger.event.data.message }} Event: {{ trigger.event.event_type }}"
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0

But the errors aren’t an event so it doesn’t trigger.
Any way to catch these automation errors?

I have an integration that sometimes goes down (Speedtest). I solved it by this automation. Is that perhaps something you could re-use?


alias: Reload Speedtest if we have stale readings
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now() - states.sensor.speedtest_ping.last_updated >
      timedelta(minutes=180) }}
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id: sensor.speedtest_ping
  - service: notify.mobile_app_iphone_13
    data:
      message: speedtest reload
      title: speedtest
mode: single

thanks, unfortunately not, this needs to be a more global catch for automations that fail rather than testing a sensor state condition as I have too many to handle like that.

I don’t believe it exists.

You can double-check by going to Developer Tools → Events and see what’s listed in Active Listeners.

Yes, it isn’t a function unfortunately.

I’ve created a feature request for this - Event type for automation error

2 Likes

Did you find how?.. Looking for this just thought about changing a helper’s value at the automation start, and then setting a known value at end… and have another automation to check for that helper if it was returned to the known state after first automation expected run time…