Random turn on/off loop

I’m working on a random turn on/off test and it work correctly but how can I loop it?

  - condition: time
    after: '18:00'
    before: 08:00
  action:
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_on
    data: {}
    target:
      entity_id: switch.domo
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_off
    data: {}
    target:
      entity_id: switch.domo
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_on
    data: {}
    target:
      entity_id: light.led
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_off
    data: {}
    target:
      entity_id: light.led
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_on
    data: {}
    target:
      entity_id: light.test
  - delay: '{{ range(5, 10)|random }}'
  - service: homeassistant.turn_off
    data: {}
    target:
      entity_id: light.test

One idea is to create an input_boolean that you toggle at the end of the actions… and you add a state change for that input_boolean as a trigger for that automation… So the automation will be retriggered at the end of the actions… To be tested…

Nice it sould work I’ll try :slight_smile: thank you!