Automation stops if 1 action fails

An automation can have multiple actions and if one action fails for any reason , the remaining actions are not executed … which can be very ennoying.

This is already a known issue , for example :

In the HA documentation , this is not covered as a limitation … Automation actions - Home Assistant

The issue is that there is nothing in the “action” part of an automation , to exit of the blocking action in order that the automation continue , in such case.

I may have missed existing solution for this , but is there at least an existing workaround ?

Thank you

Writing your automations and sensors so that they don’t fail.

You can also put your dodgy actions in a script and call that with the script.turn_on service. See https://www.home-assistant.io/integrations/script/#waiting-for-script-to-complete

Yes and it’s all explained in the 2 year-old thread you linked to (which tom_l summarized for you).

If you provide an example of an automation that is causing you difficulties, we can help you improve it.

Thank you @tom_I and @Taras for your answers.

Please find the last example that I encountered yesterday .

An automation is triggered by alarm mode ( away in my example) in order to have several actions .

action:
  - choose:
      - conditions:
          - '{{ on_alarm == ''armed_away'' }}'
        sequence:
          - domain: mobile_app
            type: notify
            device_id: d957d8cbeda5fd04ddebc66cc1c22f6b
            message: 'house mode {{ on_alarm }} '
          - service: media_player.media_stop
            target:
              entity_id: media_player.sonos_salon
          - service: switch.turn_on
            target:
              entity_id: switch.ds418_home_mode
          - service: light.turn_off
            target:
              entity_id: light.ikea_tradfri_driver_30w
          - service: light.turn_on
            target:
              entity_id: light.ikea_tradfri_driver_30w
          - service: switch.turn_off
            target:
              entity_id:
                - switch.freebox_wifi
                - switch.ikea_tradfri_control_outlet
                - switch.lumi_lumi_plug_maeu01_3a581900_on_off
                - switch.metered_wall_plug_switch
          - service: script.sonos_say
            data:
              sonos_entity: media_player.sonos_salon
              volume: 0.2
              tts_message: alarme mise en mode absence de la maison
              delay: '00:00:05'

 

One of the actions is to activate the surveillance station in my Synoly NAS using the switch “switch.ds418_home_mode” to activate the cameras in Surveillance Station , as described in the DSM integration … Synology DSM - Home Assistant

This automation used to work flawless but the state of the “switch.ds418_home_mode” became “unavailable” during the night due to a short power failure because the NAS is set to restart by WoL only.

=> The action “switch.turn_on” did not execute and the automation did not complete

How do you want the automation’s action to behave if the state of switch.ds418_home_mode is unavailable? Do you want it to simply skip the switch.turn_on action and continue to the next action?

         ...
          - service: media_player.media_stop
            target:
              entity_id: media_player.sonos_salon
          - choose:
              - conditions: "{{ states('switch.ds418_home_mode') != 'unavailable' }}"
                sequence:
                  - service: switch.turn_on
                    target:
                      entity_id: switch.ds418_home_mode
            default:
              - service: notify.persistent_notification
                data:
                  title: 'Warning - Problem with switch'
                  message: 'Could not turn on switch.ds418_home_mode because it is unavailable.'
          - service: light.turn_off
            target:
              entity_id: light.ikea_tradfri_driver_30w
          ...

Thanks for your reply .

I would say it is better to skip the action than to stop the automation , so Yes to skip and continue to the next action in this particular case

OK then implement the suggested changes in my previous post. If the switch’s state is not unavailable it will be turned on. If it is unavailable it will report it via a persistent notification and then continue to the next action. The “choose/default” serves as an “if/else”.

@ 123 Taras,

Yes for sure the “choose/default” solution will work for this automation when generated outside blueprint but in my case this is an automation generated by blueprint :
So this has to be changed a bit for compatibility to the blueprint ( not sure and not tested ):

From

  
- service: switch.turn_on
  target: !input "switches_on"
 

To :


# add variables from input selector :
  switch_name: !input "switches_on"

# action part for all switches to turn on

- choose:
       - conditions: "{{ states('switch_name') != 'unavailable' }}"
         sequence:
             - service: switch.turn_on
               target:
                   entity_id: !input "switches_on"
  default:
    - service: notify.persistent_notification
      data:
                title: 'Warning - Problem with switch'
                message: 'Could not turn on {{ switch_name }} because it is unavailable.

Please have a look ?
Thank you

I don’t recall you mentioning that this automation is produced by a blueprint (until now).

OK, so your choice is to either modify the blueprint or each individual automation it produces.