Sequential light on based on other light state

hi,
I’m trying to figure out how to cycle turn on multiple lights with one switch based on state of this light.
something like :

if light A is off then turn on light A 
else
if light A is on turn on light B
else
if light B is on turn on light C

i can do this with an automation for each action, but i guess there is a more elegant way to do it with template condition in one automation.

can you point me out the good direction ?

trigger:
  platform: state 
  entity_id: YOUR_SWITCH
  # to: AS_REQUIRED 
  # from: AS_REQUIRED
action:
  service: light.turn_on
  data:
    entity_id: >
      {% if is_state('light.a', 'off') %} light.a
      {% elif is_state('light.b', 'on') %} light.c
      {% else %} light.b {% endif %} 

thanks a lot Marc !
i will try it

1 Like

the light turn on works perfectly,

i tried to do the same for light.turn_off but the light C does not switch off

action:
  service: light.turn_off
entity_id: >
  {% if is_state('light.c ', 'on') %} light.c
  {% elif is_state('light.b', 'on') %} light.b
  {% else %} light.a {% endif %}

what is wrong ?

Your indentation is incorrect. Also I don’t know if you can use a template in entity_id without using the data key and using entity_id within that.

Other than that, the template looks fine to me.

oh yes !
i missed a space
both light.turn_on and light.turn_off are working now
thanks a lot Marc

1 Like