Handling Automation/Script Errors

Is there a way to handle errors in automations and scripts, either inline or globally?

By inline, I mean to arrange the steps to account for errors. It seems that the script stops when it hits an error, but it would be nice to have it continue and check if the previous step failed.

Alternately, I could see handling them globally, i.e. having an event you can use to trigger another automation to send a notification that any automation has failed.

I’m capturing motion and sending a camera snapshot, but occasionally the snapshot fails, which means I don’t even get notified of the motion alert.

1 Like

possibly. Best would be to share your automation, then depending on where/when it fails maybe a filter can be applied…

This is a sensor that monitors Home Assistant’s log for the occurrence of ERROR messages.

1 Like
  alias: Camera Motion Notifications
  trigger:
  - entity_id: binary_sensor.front_door_motion
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.front_door_last_snapshot
        value: 'front_door_{{ now().strftime("%Y-%m-%d_%H-%M-%S") }}.jpg'
    - data:
        entity_id: camera.front_door_camera
        filename: /config/www/cam/{{ states.input_text.front_door_last_snapshot.state }}
      service: camera.snapshot
    - condition: state
      entity_id: group.family
      state: not_home    
    - service: notify.push_notify
      data_template:
        title: Front Door motion
        message: Front Door motion when no one was home
        data:
          image: https://<<URL>>/local/cam/{{ states.input_text.front_door_last_snapshot.state }}
          url: https://<<URL>>/local/cam/{{ states.input_text.front_door_last_snapshot.state }}

I’ll give that a shot. There are quite a few errors in my log that I don’t care so much about, but I suppose I can filter those out.

It only reports the most recent ERROR message. That’s what the tail -1 does in this command string:

grep ERROR /config/home-assistant.log | tail -1 | cut -c-255

My point was more that there are lots of errors in my log that I don’t care about. Like:

Error doing job: Task exception was never retrieved (<== not sure what that is even)
Error connecting to Ecobee. Possible connectivity outage. (<== I don’t automate Echobee currently)