Wait Template Time

I’m trying to create a template that will move on at a certain time. This is for an away mode. Essentially, I want the script to START depending on the amount of light from a sensor, but I don’t want lights to start turning off until it’s around the time I usually go to bed. I’m doing this from a script…Anyone know how to do this? This is what I have, but I don’t think it would actually work…

vacation:
  alias: Vacation
  sequence:
    - delay: 00:05:00
    - service: switch.turn_on
      data:
        entity_id: switch.office_light
    - delay: 00:02:12
    - service: light.turn_on
      data:
        entity_id: light.dining_room_lamp
        brightness: 250
#### this one ####
    - wait_template: {% if is_state('now().hour', '23') and if is_state('now().minute', '45') %}
    - service: light.turn_on
      data:
        entity_id: light.bedroom_light
    - delay: 00:21:23
    - service: light.turn_off
      data:
        entity_id: group.all_lights
    - service: switch.turn_off
      data:
        entity_id: group.all_switches

Figured it out!

Sensor:

- platform: worldclock
  name: time
  time_zone: !secret time_zone

template:

- wait_template: "{{ states.sensor.time.state == '22:00' }}"
4 Likes

Awesome! thank you very much! it works! Spent hours trying to figure this out. This is awesome. I couldn’t get the timeout function to work with it though. But I am ok with this

1 Like

Hi, thanks for your help on this. I can’t get this to work.

I’m trying to perform a simple automation that turns on a light at night and off at the morning. I know that this can be made using two different automations, but I’d like to perform this using a single one if possible.

The wait template you posted

- wait_template: "{{ states.sensor.time.state == '22:00' }}"

Is not working for me as it shows:

Message malformed: extra keys not allowed @ data['action'][1]['wait_template']

Any ideas why?

It’s been a while since I’ve messed with this and this code could be obsolete now… but I would try hashing it out in the Dev Tools template section. That’s where I work through all of my templates now.