Simple script, delay being ignored

[Postscript: This was solved as having nothing to do with DELAY - see below]

I think I am doing something dumb but just not seeing it. I was mostly playing with lights to see how they look flashing, different delays, to do something with landscape for Halloween. I had a simple script and one light changing colors, with a delay in between each color change.

What happens seems bizarre. The loop appears to run for the appropriate amount of time (sum of delays times 3) then the light turns off, but the color transitions run MANY more times, changing the entire time at what appears to be full speed, flashing through the requested colors. Almost as though there were two parallel loops, one without delay but constrained by the other’s total time.

Am I missing something obvious? sequence steps are… well, sequential, right?

I tried two different format for delay, no change. Probably have some indentation wrong or similar, but…

I’m sorry if this is scripting 101, but my head is tired from banging against this particular wall.

Linwood

PS. This is not intended to be final but rather was just testing to see how the light looked, I’m sure there is a better way to do this overall, but now I really want to understand this loop and why delay does not work.

halloween: 
  alias: Halloween
  sequence: 
    - repeat: 
        count: 3
        sequence: 
          - service: light.turn_on
            target: 
                entity_id: light.flood8 
            data: 
              brightness: 255
              transition: 0 
              rgb_color: 
                - 0
                - 0
                - 255
          - delay: '00:00:05'
    
          - service: light.turn_on
            target: 
                entity_id: light.flood8 
            data: 
              brightness: 255
              transition: 0 
              rgb_color: 
                - 0
                - 255
                - 0
          - delay: '00:00:00.1'
    
          - service: light.turn_on
            target: 
                entity_id: light.flood8 
            data: 
              brightness: 255
              transition: 0 
              rgb_color: 
                - 0
                - 0
                - 255
          - delay: 
                seconds: 10
          
          - service: light.turn_on
            target: 
                entity_id: light.flood8 
            data: 
              brightness: 255
              transition: 0 
              rgb_color: 
                - 255
                - 0
                - 0
          - delay: '00:00:00.1'

    - service: light.turn_off
      target: 
        entity_id: light.flood8
        
  mode: single 

What you have:

repeat x3

  • Light → blue
  • delay 5 sec
  • Light → green
  • delay 100ms
  • Light → blue
  • delay 10s
  • Light → red
  • delay 100ms
  • Light → off

The green and red states highlighted above are going to be barely visible at 100ms each.

Right. That’s what I want to experiment with, to produce brief flashes.

But that is not my fundamental question. My questions is why does this produce dozens of light changes before it ends, with no change in delay between them. Lots and lots of changes, not 3 iterations.

I wonder if you are confusing your lights by sending requests too rapidly. Try increasing the 100ms delays to 3 or 4 seconds, just to see what happens.

Sigh… I was definitely looking in the wrong place.

Earlier in the day I pulled down a color loop blueprint and was experimenting with it. I had an automation for it, and had stopped it, but somehow it was getting re-activated. I am a bit unsure how, but it became obvious when I stopped my script (above) and just turned the light on and it went nuts.

Script gone, delay working as expected.

It’s hard to debug a program when it’s not the program actually running. :anguished:

Sorry for the confusing question and thank you for taking the time to help.

1 Like