Need help with automation using repeat triggered by input boolean

Hello!
So I’m trying to make a “disco-mode” automation. I’m using an input boolean to trigger the automation. When the automation is turned on it should turn off some lights, disable circadian lighting, start an effect on my led-strip, and start a repeat-loop changing the colors of my zigbee-bulbs one at a time to a random color. When it is turned off it should turn on circadian lighting (which makes all the lights white again), turn back on some lights and change the effect of the led strip.
The automation works as expected when I turn it on. Turning it off stops the color-changing of the zigbee-bulbs, but nothing else. If I remove the repeat-part the automation works as expected.
I anyone can help me out it would be greatly appreciated.

alias: DISCOMODUS
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.discomodus
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.discomodus
            state: "off"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.circadian_lighting_circadian_lighting
          - service: light.turn_on
            data: {}
            target:
              entity_id:
                - light.taklampe_stue
                - light.bokhyllelys
                - light.lysspisebord
          - service: light.turn_on
            data:
              effect: Solid@;!;
            target:
              entity_id: light.hyllelys_2
      - conditions:
          - condition: state
            entity_id: input_boolean.discomodus
            state: "on"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.circadian_lighting_circadian_lighting
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.taklampe_stue
                - light.bokhyllelys
                - light.lysspisebord
          - service: light.turn_on
            data:
              effect: Rainbow@!,Size;1,2,3;!
            target:
              entity_id: light.hyllelys_2
          - repeat:
              until:
                - condition: state
                  entity_id: input_boolean.discomodus
                  state: "off"
              sequence:
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.kjokkenspot_1
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.kjokkenspot_2
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.kjokkenspot_3
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.tv_lys_1
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.tv_lys_2
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
                - service: light.turn_on
                  data:
                    hs_color: |
                      [ {{ range(10,300) | random }},  100 ]
                  target:
                    entity_id: light.tv_lys_3
mode: single

I was running your automation with Philips Hue lights and everything went fine. Have you already tried a different delay time? Do the lamps in question change colour randomly when the service call is executed without repeat?

Hey! Thanks for your reply. I’ve tried different delay times, and it makes no difference. I finally got it to work by splitting it in two separate automations, one which runs the repeat cycle until the switch is turned off, and a separate automation to turn on circadian lighting and the other lights.
I still can’t figure out why the original automation didn’t work, and I would prefer to have only one automation. But it works now, and my 4-year old is very pleased!

1 Like