[SOLVED] Automation trigger with if elif

I would like the outcome of an automation to be selected based on a time condition. The trigger is a motion sensor. Something like this:

if (time is after 22 and before 06) run script 1
  script 1 --> turn_on light, brightness_pct: 1, delay 00:01, turn_off light
elif (time is after 06 and before 19) run script 2
  script 2 --> turn_on light, brightness_pct: 40, transition: 1800
elif (time is after 19 and before 22) run script 3
  script 3 --> turn_on light, brigtness_pct: 10, transition: 1800

But Iā€™m unsure how to do it in HA. Do I need three separate automations or can this be combined?

service: script.turn_on
data_template:
  entity_id: >
    {% if((now().hour <= 6) or (now().hour >= 22))}%}
      script.script1
    {% elif (now().hour <= 19) %}
      script.script2
    {%else%}
      script.script3
    {% endif %}
3 Likes

Great! Thanks a lot :smiley: