Hello,
I have a lengthy non-looping script that I’d like to shorten, if possible.
I am manually:
setting light 1 color
iterating a dropdown with red, white, blue as values
set light 2 color… up to light 5
If it weren’t for iterating that dropdown I’d just use multiple - entityid: entries like this:
action:
- service: light.turn_on
data:
color_name: white
brightness: "250"
transition: 2
target:
entity_id:
- light.bar_light_1
- light.bar_light_2
- light.bar_light_3 .etc.
mode: single
I was trying to nest a for_each in there with
-light.bar_light_1, 2, 3…
But it doesn’t like the way I am trying to nest repeat, for_each in the existing while that checks for the toggle to be on…
Here is what I have. Maybe someone can learn this out so I can add/remove lights easily, instead of copy/pasting a block of code, making it more clumsy and ugly.
Thanks in advance.
patriotic_lamp_posts_running:
sequence:
- repeat:
while:
- condition: state
entity_id: input_boolean.patriotic_lamp_posts
state: "on"
sequence:
- service: light.turn_on
data:
entity_id: light.lamp_post_1
color_name: "{{ states('input_select.patriotic_colors_2') }}"
transition: 1.0
- service: input_select.select_next
entity_id: input_select.patriotic_colors_2
- service: light.turn_on
data:
entity_id: light.lamp_post_2
color_name: "{{ states('input_select.patriotic_colors_2') }}"
transition: 1.0
- service: input_select.select_next
entity_id: input_select.patriotic_colors_2
- service: light.turn_on
data:
entity_id: light.lamp_post_3
color_name: "{{ states('input_select.patriotic_colors_2') }}"
transition: 1.0
- service: input_select.select_next
entity_id: input_select.patriotic_colors_2
- service: light.turn_on
data:
entity_id: light.lamp_post_4
color_name: "{{ states('input_select.patriotic_colors_2') }}"
transition: 1.0
- service: input_select.select_next
entity_id: input_select.patriotic_colors_2
- service: light.turn_on
data:
entity_id: light.lamp_post_5
color_name: "{{ states('input_select.patriotic_colors_2') }}"
transition: 1.0
- service: input_select.select_next
entity_id: input_select.patriotic_colors_2
- delay: "00:00:05"