Wait Template Assistance

I need some help with a wait template. As part of an automation I want to wait until the state of 2 different entities each reach a particular state. Any help is appreciated

Going to need a little more information.

What entities?

What states?

I was assuming you’d just use examples and I’d fill in the entities and states

New entity

binary_sensor.front_door_sensor_4aafe7ff_ias_zone

Here’s the automation. I want to add another trigger for the door sensor, and wait for both the motion sensor to clear and door sensor closed before moving on.

alias: Porch Motion Sensor
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 1e0770ec7afb2c2453eb41b5a6cb7000
    entity_id: binary_sensor.third_reality_inc_3rms16bz_814fe7ff_ias_zone
    domain: binary_sensor
condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
action:
  - service: scene.create
    data:
      snapshot_entities:
        - light.wiz_bulb_12
        - light.wiz_bulb_21
        - light.wiz_bulb_22
        - light.wiz_bulb_23
        - light.wiz_bulb_24
      scene_id: porch_motion_sensor_snapshot
  - service: scene.turn_on
    target:
      entity_id: scene.porch_motion_light
    metadata: {}
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: 1e0770ec7afb2c2453eb41b5a6cb7000
        entity_id: binary_sensor.third_reality_inc_3rms16bz_814fe7ff_ias_zone
        domain: binary_sensor
    timeout:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - service: scene.turn_on
    data:
      transition: 4
    target:
      entity_id: scene.porch_motion_sensor_snapshot
mode: single

The problem with that assumption is that I did not know if they were binary entities, or numeric, or text. And the template would be different for each.

You are currently using a wait_for_trigger. The issue there is that triggers are always OR logic and you want AND logic so, as you requested, you have to use a wait template. Like this:

  - wait_template: >
      {{ is_state('binary_sensor.third_reality_inc_3rms16bz_814fe7ff_ias_zone', 'off') and
         is_state('binary_sensor.front_door_sensor_4aafe7ff_ias_zone', 'off') }}
    timeout:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0

That worked, thank you!!

1 Like