Create an automation with multiple actions, each depend on a condition

Hi,

I am looking for a way to create an automation that have multiple actions.
But I want for each action to evaluate a state of a sensor, and only if true, continue execute the action and if not, move on to the next action.

So far looked at condition in the action section, but in case of failed condition, no more actions will be processed.
Also checked ‘choose’, but its not working either because once I get a hit on an option, only it will be executed, and stop processing other actions.

Is there’s a way to do it?

thanks in advance guys.

What I’ve done in the past is using a list of actions that execute scripts - and the conditions are evaluated as part of the script.

The action section of your automation would look like this:

action:
 - service: script.1234567
   data: {}
 - service: script.1234568
   data: {}

Your sequence in the script - which I see as just being an automation without a trigger - might then look like this:

  - condition: state
    entity_id: light.kitchen
    state: "on"
  - service: fan.turn_on
    data:
      percentage: 75
    target:
      entity_id: fan.kitchen

It might get tricky with multiple conditions for each action and as soon as you get into race conditions for the executions - but my stuff was simple enough to not have to worry about this.

1 Like

If then works great.

I used to do the script method, bit switched to if/then

1 Like

If your actions are not mutually exclusive you need to use multiple Choose or If/Then action

2 Likes

Choose can definitely be made to do this. So can the if then action. Don’t use the optional else, just the if for each action.

Share your config.

2 Likes
action:
  - if: "{{ is_state('switch.kitchen', 'on') }}"
    then:
      - service: light.turn_on
        target:
          entity_id: light.cabinet
  - if: "{{ states('sensor.temperature') | int(0) > 25 }}"
    then:
      - service: switch.turn_on
        target:
          entity_id: switch.ventilator
  - if: "{{ states('sensor.light_level') | int(0) < 55 }}"
    then:
      - service: switch.turn_on
        target:
          entity_id: switch.whatever
3 Likes

@123 , @tom_l , @Didgeridrew , @Markus99 , Thanks! it worked great!

@chairstacker , thank you for the clever idea, i think i need it for another automation i have.

You guys are the best.

1 Like