Help understanding nesting repeat, while, for_next

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"

I am answering my own question: (I have 3 ‘bar lights’ and 5 ‘lamp post lights’ in two diff toggles)

patriotic_lamp_posts_on:
  alias: Patriotic Lamp Posts on
  sequence:
    - service: scene.create
      data:
        scene_id: patrioticlampposts
        snapshot_entities:
          - light.lamp_post_1
          - light.lamp_post_2
          - light.lamp_post_3
          - light.lamp_post_4
          - light.lamp_post_5
    - service: script.turn_on
      entity_id: script.patriotic_lamp_posts_running

patriotic_lamp_posts_running:
  sequence:
    - repeat:
        while:
          - condition: state
            entity_id: input_boolean.patriotic_lamp_posts
            state: "on"
        sequence:
          - service: script.turn_on
            entity_id: script.patriotic_lamp_posts_switcher
          - delay: "00:00:05"

patriotic_lamp_posts_switcher:
  sequence:
    - repeat:
        for_each:
          - "light.lamp_post_1"
          - "light.lamp_post_2"
          - "light.lamp_post_3"
          - "light.lamp_post_4"
          - "light.lamp_post_5"
        sequence:
          - service: light.turn_on
            data:
              entity_id: "{{ repeat.item }}"
              color_name: "{{ states('input_select.patriotic_colors_2') }}"
              transition: 1.0
          - service: input_select.select_next
            entity_id: input_select.patriotic_colors_2

patriotic_bar_lights_on:
  alias: Patriotic Bar Lights on
  sequence:
    - service: scene.create
      data:
        scene_id: patrioticbarlights
        snapshot_entities:
          - light.bar_light_1
          - light.bar_light_2
          - light.bar_light_3
    - service: script.turn_on
      entity_id: script.patriotic_bar_lights_running

patriotic_bar_lights_running:
  sequence:
    - repeat:
        while:
          - condition: state
            entity_id: input_boolean.patriotic_bar_lights
            state: "on"
        sequence:
          - service: script.turn_on
            entity_id: script.patriotic_bar_lights_switcher
          - delay: "00:00:10"

patriotic_bar_lights_switcher:
  sequence:
    - service: input_select.select_next
      entity_id: input_select.patrioticcolors
    - repeat:
        for_each:
          - "light.bar_light_1"
          - "light.bar_light_2"
          - "light.bar_light_3"
        sequence:
          - service: light.turn_on
            data:
              entity_id: "{{ repeat.item }}"
              color_name: "{{ states('input_select.patrioticcolors') }}"
              transition: 1.0
          - service: input_select.select_next
            entity_id: input_select.patrioticcolors