One triger multiple conditions and multiple actions / scripts

Hey.
Is it possible to create a script with multiple conditions and multiple actions? I mean something like.

do A
do B
if conditions do C
do D
if …

and so on?
Currently I have to create a new automation each time I want HA to do two things with the same trigger but different conditions.

Cheers Malte

Likely possible with templates. You can call services with templates and tailor the action based on the state of a sensor/device.

Did you start with a configuration already? If yes, we can give you some more concrete ideas.

Ah I think that will work. THX for the idear, I try it.

@BendedArrow Not really.

I would get the action in the automation to call several scripts in order w, each script with its own condition.

Hi - I know this is an older thread but hoping someone is still watching it. I’m looking to do something similar where I have one trigger with multiple conditions and each condition would run a separate script if true. I have Google Calendar integrated and when an item named “Holiday Lights Red White Blue” is in todays calendar it triggers an input boolean on and then an automation fires later in the day based on the boolean being on.

For example, I currently have this working automation:

  - alias: "Holiday Lights On"
    hide_entity: false
    initial_state: true
    trigger:
      platform: sun
      event: sunset
      offset: '-00:19:00'
    condition:
      - condition: state
        entity_id: input_boolean.holiday_lights_redwhiteblue
        state: 'on'
    action:
      - service: script.holidaylights_redwhiteblue

and now looking to add other holidays to it

        entity_id: input_boolean.holiday_lights_christmas
        state: 'on'
    action:
      - service: script.holidaylights_christmas

As you can see there will only ever be one true condition and the others will be false at a time. I should also note that I already have all the calendar integrations setup and booleans for Christmas, Halloween and so on I just cant get the automation to trigger the correct script based on which boolean is switched on.

Im still very new to Home Assistant (maybe a month since first install) and any help would be greatly appreciated. Thank you.

A more efficient way to do this would be to use an input_select instead of the booleans…

input_select:
  holiday_lights:
    name: Holiday lights
    options:
      - 'None' 
      - 'RedWhiteBlue' 
      - 'Christmas' 
      - 'Halloween'

Set the input_select via whatever means you currently use to set the boolean, then your automation is…

- alias: "Holiday Lights On"
  hide_entity: false
  initial_state: true
  trigger:
    platform: sun
    event: sunset
    offset: '-00:19:00'
  condition:
    condition: template
    value_template: "{{ not is_state('input_select.holiday_lights' , 'none') }}" 
  action:
    service_template: "script.holiday_lights_{{ states('input_select.holiday_lights') }}" 

This way if the input_select is on None, the automation doesn’t run, if it has any other selection it runs the corresponding script.

I love it I just learned something new. I will give it a try and read up some more on input_select. Thank you so much!

1 Like

Thank you again for your input on this everything seems to be working as it should!

I should note that the input_select options are case sensitive. I couldn’t get the automatons to work correctly until I changed the input options to all lower case which matches the script names called in the service template section and also the none option called in the value template section.

1 Like

No worries :+1: