WTH - my automation crashed again!

A have tens of automations. And lot of my automations has more than one action. Look at this simple example:

 condition:
    - condition: state
      entity_id: raining
      state: 'on'
  action:
    - service: log-server
      data:
        message: 'it is raining - closing window'
    - service: close-window
    - service: tts.google_say
      entity_id: media_player.xxx
      data_template:    
        message: 'it is raining - closing window'

And imagine my log server is standalone machine and it is OFF for some reason. WTH! It is raining and window is still open! Why? Because first of three actions failed -> all actions failed!

I need some “safe run” actions, some “java-like try/catch” system. I think every single action should have “urgency” parameter. If i set action as “necessary” it will behave as now. If i set “optional” it will continue to run next action if it failed.

HA automations is powerful tool but with behavior i described is much degraded and unreliable.

My example should looks like this:

 condition:
    - condition: state
      entity_id: raining
      state: 'on'
  action:
    - service: log-server
      urgency: optional
      data:
        message: 'it is raining - closing window'
    - service: close-window
      urgency: necessary
    - service: tts.google_say
      urgency: optional
      entity_id: media_player.xxx
      data_template:    
        message: 'it is raining - closing window'

If you don’t need to finish first action before next one (and ignore logging in this case) isn’t it better to just create another automation to close the window? Lets say the logging takes some time then do you really like to wait with window closing until it finished or start closing window ASAP?

Besides that, I see some automations where strict order and one by one actions could be still needed and I don’t have any suggestion for that either.

Two automations? https://en.wikipedia.org/wiki/Don't_repeat_yourself
If automation has 10 conditions and 2 actions, if I do your concept i will have 2 automations with same 10 conditions and 1 action. I think copy/paste is not good solution so it is not acceptable solution.

It depends. Right now, one automation is one set of sequential actions. For parallel action you have to do multiple automations. I totally agree that this is anti-DRY pattern.

However, I don’t think that it is intuitive to add “urgency”-like option to the sequence.

I would propose just one run_parallel: true flag or something like action_parallel instead of action if things should not run in strict order. And if you still have some actions that needs to be run in correct order, then put them into the script and call this script from action_parallel. How does this sound?

I think my original post is wider. Parallel run is workaround to achieve error-isolation of every action. For my example it is maybe ok, I don’t need exact order of TTS message and window close action. BUT! I have automations where order is still needed and error-proof is needed too.

Yeah, I agree that there could be automations that can be easier to set up if such feature exists. Of course then it would be good to have a documentation about possible error causes for every possible actions too.

I personally think the name urgency could a little bit misleading. Maybe something like ignore_errors: True or continue_with_errors: True which is optional parameter and False by default would do the trick - if it is enough to have only two possible behaviors …

I think this is where scripts step in.

I would setup a “log this” script that takes one variable, and have the script log the must received variable. Now you can call that script in any automation and continue regardless of status.

2 Likes