Trying to make a continuous (conditional) loop

I’ve done some research and coded what I feel should be a valid way for a continuous loop to happen in my system. Every time it runs it checks the condition of whether a particular sensor is “on”. See below:

reminder_babygate:
  sequence:
    - condition: state
      entity_id: binary_sensor.baby_gate_102
      state: 'on'
    - service: tts.google_say
      data:
        entity_id: group.google_home
        message: baby gate open
    - service: script.delay_babygate
delay_babygate:
  sequence:
    - delay:
        seconds: 10
    - service: script.reminder_babygate

As you can see, it’s actually 2 scripts running together, since it’s my understanding that you can no longer have a script call itself.

What actually happens here is the reminder_baby script gate only gets called up to 2 times, then terminates, even if the senor continues in the “on” state. Any ideas why this is happening here?

I imagine you are running into the reason that scripts can’t call themselves, you’ve just found a way to do it that isn’t being trapped. I can think of some ways to do it with an input boolean an three automations and a script. Or I can think of a quick and easy way to do it in appdaemon.

Yeah, I’d totally accept that explanation if it weren’t for other examples such as (How can repeat this automation?) where people claim to have it working. Am I doing anything different than the example there that could be throwing mine off?

So just to be clear, there isn’t any supported/official method to simulate a while loop in HA/yaml?

I might have to look into AppDaemon you speak of…

Well, just an FYI, I was able to accomplish something similar by using a single periodically-triggered automation:

    alias: Baby Gate Reminder
  trigger:
    platform: time
    seconds: '/30'
  condition:
    condition: state
    entity_id: binary_sensor.baby_gate_102
    state: 'on'
    for:
      seconds: 20
  action:
    service: tts.google_say
    data:
      entity_id: group.google_home
      message: baby gate open

I know it could be a little late but i was trying to do something similar.
If you check your logs you will have an entry like delay_babygate is already running.
The answer is to put a delay in reminder_babygate before calling the delay script so you end up with this…

reminder_babygate:
  sequence:
    - condition: state
      entity_id: binary_sensor.baby_gate_102
      state: 'on'
    - service: tts.google_say
      data:
        entity_id: group.google_home
        message: baby gate open
    - delay:
        seconds: 5
    - service: script.delay_babygate
delay_babygate:
  sequence:
    - delay:
        seconds: 10
    - service: script.reminder_babygate

Hey,

How often you need to call the script? One alternative is to create a automation with a time trigger (https://www.home-assistant.io/docs/automation/trigger/).