Notify if a contact sensor has been in state open for too long

Hi!

i have a number of contact sensors for my doors and windows. I would like to run a general automation that checks if any sensor has been in state open for more than two hours and if so, notifies me on my phone that a window might have been forgotten open.

There are a few quirks with this, I want the automation to check all sensors using wildcards it captures eventual new contact sensors added to the house. The other quirk is that it needs to track and notify me about them individually.

Any ideas on blueprints I can start with and build out from there?

2 Likes

That’s pretty simple to do with an automation.

  • Select ‘state’ as a trigger and add the sensors that you want to monitor.
  • Set the state as “on” (“opened” when configured via the UI).
  • Set the time they should be open.
  • Call the notification service with the name of the sensor that triggered the notification.

Here is a yaml example you can past in a new automation and modify to suit your needs:

description: ""
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.SENSOR_1
      - binary_sensor.SENSOR_2
      - binary_sensor.SENSOR_3
    to: "on"
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: notify.notify
    data:
      title: A window is open!
      message: "Sensor: {{ trigger.from_state.attributes.friendly_name }}"
    enabled: true

https://github.com/SirGoodenough/HA_Blueprints/blob/c05d6fb431c1d84cb145c7d6dd5ffe5a60b1d9e2/Automations/door_open_tts_cloud_say_and_Piper_announcer_Piper_OR_nabu_casa_required.md.