Working with "wait_template" in a script

I have script that turns on some lights when a door is opened, the automation for it looks like this:

- alias: Plafondlamplamp aan bij nacht
  trigger:
    platform: state
    entity_id: binary_sensor.deursensortrap_sensor
    to: 'on'
  action:
     service: script.woonkamer_aan_bij_nacht

and the script looks like this:

woonkamer_aan_bij_nacht:
  sequence:
  - service: homeassistant.turn_on
    entity_id: light.dimmerwoonkamer_level
    data:
      brightness: 110
  - delay:
      seconds: 60
  - service: homeassistant.turn_off
    entity_id: light.dimmerwoonkamer_level

As you can see, I’m currently using a delay of 60 seconds to turn the lights back off. Instead of that, I would like to turn the lights off when the door is opened for the second time.

I thought I would be able to use wait_template with a small delay (to wait for the closing of the door the first time), so I changed my script into this:

woonkamer_aan_bij_nacht:
  sequence:
  - service: homeassistant.turn_on
    entity_id: light.dimmerwoonkamer_level
    data:
      brightness: 110
  - delay:
      seconds: 5
  - wait_template: "{{ is_state('states.binary_sensor.deursensortrap_sensor','on') }}"
    timeout: '00:01:00'
    continue_on_timeout: 'false'
  - service: homeassistant.turn_off
    entity_id: light.dimmerwoonkamer_level

Unfortunately, I seem to be doing something wrong, because I’m getting this error:

2018-10-24 20:58:19 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [wait_template] is an invalid option for [script]. Check: script->script->woonkamer_aan_bij_nacht->sequence->2->wait_template. (See /home/pi/.homeassistant/configuration.yaml, line 728). Please check the docs at https://home-assistant.io/components/script/

any idea where I’m going wrong?

What version of homeassistant are you running?

Also your template is wrong, the word states and the dot need removing from the entity_id, should be…

  - wait_template: "{{ is_state('binary_sensor.deursensortrap_sensor','on') }}"
    timeout: '00:01:00'
    continue_on_timeout: 'false'

ah, I think you already helped me spot the problem, turns out I’m on 0.57.1 while the newest version is 0.81. It could very well be that “wait_template” was jot yet available in 0.57.1.

Now I just need to find the courage to upgrade :wink:

1 Like

There will be a LOT of breaking changes in that time. Best thing to do is just bite the bullet, set aside some time to get it sorted, do the upgrade and work through the error messages one by one :slight_smile: