How to avoid an endless loop?

I made automation for switching on the light on the movement. The light is turned on in two stages first turns on the power, then checked if the controller is not in the status of unavailable then in a loop sent commands to turn on, in a loop because the controller may show the status off, but in fact has not yet turned on.
And the question to avoid infinite loop how to limit the loop operation by say 1 minute or other time, I tried to put timeout: 00:01:00 but this command inside the repeat: block is not supported.

- id: '173023888736411'
  alias: Vanna_move_on
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - binary_sensor.dvizhenie_vanna
    from: 'off'
    to: 'on'
  conditions: []
  actions:
  - action: light.turn_on
    metadata: {}
    target:
      entity_id: light.led_vanna_stena
    data: {}
  - wait_template: |
      {% if  states('light.led_stena_vanna2') != 'unavailable' %}
      True
      {%endif%}
    timeout: 00:01:00
  - repeat:
      sequence:
      - action: light.turn_on
        target:
          entity_id:
          - light.led_stena_vanna2
      while:
      - condition: template
        value_template: | 
          {% if  states('light.led_stena_vanna2') == 'off' %}
          True
          {%endif%}

Hi

I have no idea what you are trying to do. I think you are making things more complicated than they really are…

Well to put that code into pseudo code, I get…

When a sensor changes from off to on
  Turn on light A
  If light B is available
    Say True
    If not available wait 1 minute.
  repeat
    turn on light B
    While light B is off
      Say True

I don’t get it…
Why are you saying true?
If you turned light B on, why do you expect it to ignore you and start yelling true at it?

Maybe I’m having a bad day, but I really don’t understand.
Did ChatGPT help you with this?

wait: Script Syntax - Home Assistant.
while: Script Syntax - Home Assistant.

If we translate this code into pseudo-code, we get

If light B is available we stop waiting for it and proceed to turning it on
1 minute is a timeout, not a delay, after 1 minute we stop waiting, i.e. 1 minute is the maximum waiting time.

True I use to stop waiting

I’m having a really hard time following. What the two stages. Why would it not be available?

Do you have a smart bulb behind a smart switch?

I have a light bulb connected to a controller that takes wifi commands through the cloud and it’s constantly glitching.

A, get a better light
B, there is no B

2 Likes

What you’re looking for is called wait for a trigger: (set a 1 min timeout)

wait for trigger syntax:

And - get a better light. (no really coding around the nuance of unreliable device is annoying at best - sometimes different is a valid option.)

4 Likes