Automation Action on Fail

I was wondering if it were possible to have automations be able to run different actions based on if it passes the condition or not. This would be ala if-else side of things. The trigger would still set off the automation, but it would be able to run different things on if the criteria comes back true or false. Here’s an example of what I’m talking about.

- alias: Turn off away mode
  trigger:
    platform: state
    entity_id: group.residents
    to: 'home'
  condition:
    condition: and
    conditions:
      - condition: time
        after: '00:06:30'
      - condition: time
        before: '22:00:00'
  action:
    service: homeassistant.turn_on
    entity_id: script.home_mode
  action_failed:
    service: homeassistant.turn_on
    entity_id: script.home_mode_night

I have no clue how easy or difficult this would be, but it would sure make automations a little less cluttered. You would need half as many automations in some instances than before. And it still keeps things somewhat simple, so it’s not difficult for people to set up.

We don’t have if/else per se in HA. There are 2 options:

  1. Use AppDaemon (I have no idea how this works but it should work)

  2. Use multiple scripts like this:
    Script 1 -> Call Script2, Call Script3
    Script 2 -> Check if condition -> Do things
    Script 3 -> Check negative if condition (aka else) -> Do other things

I would prefer if possible the second version (as mentioned I don’t use AppDaemon yet and this only uses HA built-in stuff) BUT it has it’s limitations as it is not TRULY a if/else if you are not carefull BOTH actions (Do things AND Do other things) could be called. Also it get’s fairly complicated if you want to use multiple of those.

~Cheers

In this situation, you could use a template for your entity_id and pick the script based on if/else logic in templates. Use your condition values as the template rules.

1 Like

Haven’t thought about that. Nice idea!

~Cheers