Wait until any door opens

I have an automation that I want to do certain things upon an alarm state change, the alarm is the trigger, but I want to do certain things only after any door or window has been opened after the trigger.

In actions, I have the option to wait for numeric state trigger, or wait for a template. With some google help I build a template that counts the number of open doors, windows and garages:

{{ states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'door') | list | count  +
 states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'window') | list | count + 
 states.binary_sensor | selectattr('state', 'eq', 'on') | selectattr('attributes.device_class', 'eq', 'garage_door') | list | count }}

That template works. What I cant figure out is how to wait until the result of that template increases, or even changes?

You could create an automation with a numeric state trigger with the ‘above’ value set at 0.

Post your automation; indicate where in the automation you want it to wait.

I dont want above zero, a window could have been left open before the alarm state changed, I want above whatever it was previously.

Anyway, I have a crude solution, I just created a template sensor based on the number of open doors, and I can trigger on a change in that number. Cant really limit that to an increase, but this is good enough for now.

Not sure this will be much help

alias: Lichten automatisch aan
description: ""
trigger:
  - platform: device
    device_id: 107868bb574a17eefdc111cfa93f209c
    domain: alarm_control_panel
    entity_id: alarm_control_panel.alarmo
    type: disarmed
condition:
  - condition: numeric_state
    entity_id: zone.home
    above: 0
  - condition: numeric_state
    entity_id: sensor.kostal_total_vermogen
    below: 500
action:
  - wait_for_trigger:
      - platform: state
        entity_id:
          - sensor.aantal_open_deuren_ramen
    timeout:
      hours: 2
      minutes: 0
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false
  - service: switch.turn_on
    data: {}
    target:
      device_id:
        - 1420a4965e010ea253bfaa049d25bea5
        - 2259132da51769b8d9f9a997a9c494d8
        - c3b34ae84bfe3e2262132ba27bc12d1d
  - type: turn_on
    device_id: 4ff049af0a87d8a7c9e8dca2dd30c9c4
    entity_id: light.ikea_light
    domain: light
  - type: turn_on
    device_id: 9d7088c131a55bf648ccf591feb8be75
    entity_id: light.kerstverlichting
    domain: light
mode: single

sensor.aantal_open_deuren_ramen is the number of open windows/doors.

...
action:
  - variables:
      qty: "{{ states('sensor.aantal_open_deuren_ramen') | int(0) }}"
  - wait_for_trigger:
      - platform: template
        value_template: "{{ states('sensor.aantal_open_deuren_ramen') | int(0) > qty }}"
    timeout:
      hours: 2
      minutes: 0
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false
...

1 Like