Wait template doesn't wait

Hi, trying to get a wait template to work. As far I can can see, the following should work, but it doesn’t. When I look in the log it says the script is already running, implying that the wait template did not wait and proceeded to run the script again before it ended. Any ideas why my wait template isn’t waiting?

Automation:
- service: script.1557312839102
- wait_template: “{{ is_state(‘light.balcony_led’, ‘off’)}}”
- service: script.1557312839102

Script (the last command switches the LED strip off):

'1557312839102':
  alias: Balcony LED Cycle
  sequence:
  - data:
      event: balcony_white_strobe
    service: ifttt.trigger
  - delay: 00:00:05
  - data:
      event: balcony_strobe_flash
    service: ifttt.trigger
  - delay: 00:15:00
  - data:
      event: balcony_white_strobe
    service: ifttt.trigger
  - delay: 00:00:05
  - data:
      event: balcony_jumping_change
    service: ifttt.trigger
  - delay: 00:15:00
  - data:
      event: balcony_white_strobe
    service: ifttt.trigger
  - delay: 00:00:05
  - data:
      event: balcony_cross_fade
    service: ifttt.trigger
  - delay: 00:15:00
  - data:
      entity_id: light.balcony_led
    service: light.turn_off

If the automation re-triggers while the wait template is active the wait state is cancelled and execution of the actions continues. This is by design.

1 Like

Thanks for that. I did a wait template on the script and that worked. That’s for the feedback.

@tom_l Good to know as I’m having similar issues. What determines how long the wait template is active? I’ve got automation actions that only fire after my mobile phone is in a state of ‘charging’ but even if its state changes to ‘discharging’ minutes later and the automation is triggered again, the wait_template is ignored as I’m assuming based on your comments that it is still active?

Is there way to reset a wait template?

For those looking for an alternative method, I switched my automation around so rather than using a wait_template to wait for my phone to start charging, I use this as the trigger now but added a condition that tests to see if the stair lights were turned off in the last 5 minutes which is far more reliable.

  - alias: Detect Pete in Bed
    trigger:
      - platform: state
        entity_id: sensor.nokia_7_1_app_battery_state
        from: 'discharging'
        to: 'charging'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'person.pete'
          state: 'home'
        - condition: state
          entity_id: media_player.sony_bravia_tv
          state: 'off'
        - condition: time
          after: '21:00:00'
          before: '02:00:00'
        - condition: template
          value_template: "{{ (as_timestamp(now()) - as_timestamp((states.light.stair_lights.last_updated)) <300)}}"