Simple lightshow?

I have automated the lights on my house’s facade with ESPHome. There are 8 lights installed and I have the following code:

switch:
  - platform: gpio
    pin:
      number: 13
      inverted: yes
    name: "Facade Light 1"
    id: facadelight1
  - platform: gpio
    pin:
      number: 12
      inverted: yes
    name: "Facade Light 2"
    id: facadelight2
  - platform: gpio
    pin:
      number: 14
      inverted: yes
    name: "Facade Light 3"
    id: facadelight3
  - platform: gpio
    pin:
      number: 9
      inverted: yes
    name: "Facade Light 4 (Door Left)"
    id: facadelight4
  - platform: gpio
    pin:
      number: 0
      inverted: yes
    name: "Facade Light 5 (Door Right)"
    id: facadelight5
  - platform: gpio
    pin:
      number: 4
      inverted: yes
    name: "Facade Light 6"
    id: facadelight6
  - platform: gpio
    pin:
      number: 5
      inverted: yes
    name: "Facade Light 7"
    id: facadelight7
  - platform: gpio
    pin:
      number: 10
      inverted: yes
    name: "Facade Light 8"
    id: facadelight8
  - platform: template
    optimistic: true
    name: "Door Lights"
    turn_on_action:
      - switch.turn_on: facadelight4
      - switch.turn_on: facadelight5
    turn_off_action:
      - switch.turn_off: facadelight4
      - switch.turn_off: facadelight5
  - platform: template
    optimistic: true
    name: "Door to Sides"
    turn_on_action:
      - switch.turn_on: facadelight4
      - switch.turn_on: facadelight5
      - delay: 70ms
      - switch.turn_on: facadelight3
      - switch.turn_on: facadelight6
      - delay: 70ms
      - switch.turn_on: facadelight2
      - switch.turn_on: facadelight7
      - delay: 70ms
      - switch.turn_on: facadelight1
      - switch.turn_on: facadelight8
    turn_off_action:
      - switch.turn_off: facadelight1
      - switch.turn_off: facadelight8
      - delay: 70ms
      - switch.turn_off: facadelight2
      - switch.turn_off: facadelight7
      - delay: 70ms
      - switch.turn_off: facadelight3
      - switch.turn_off: facadelight6
      - delay: 70ms
      - switch.turn_off: facadelight4
      - switch.turn_off: facadelight5

“Door to sides” switches on the lights starting from the middle (where the door is) to the sides of the house with a slight delay between each pair of lights. It looks very nice. Also “Door Lights” is tied to a sensor on the door.

I was wondering, is there a way to create a looping light show? Say turn on one random light for half a second while turning all others off. I’m interesting how can I run a piece of code in a loop.

It’s Christmas :christmas_tree: so I’m curious yet again how I could do something like this. :slight_smile: