Notification if Door or Window is left open

This blueprint will run whenever a binary sensor is left on (or off) for a configurable amount of time. The most common use case for this is to get notified when a door or window is left open, but it can also be used for motion sensors or any other binary sensor. This blueprint is easy to set up, but also highly configurable, making use of many of the HomeAssistant companion apps’ notification features.

As this is my first blueprint, there may be bugs in the code, so let me know if you spot any, and I’ll try to fix them ASAP. Thanks in advance!

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Contact Sensor Left Open Notification
  description: "Notifies you when a door or window is left open. 

    For more information on setting the click url, please visit the companion docs:
    https://companion.home-assistant.io/docs/notifications/notifications-basic/#opening-a-url

    If you'd like to notify multiple people, use a notify group: 
    https://www.home-assistant.io/integrations/notify.group/

    "
  domain: automation
  input:
    entity:
      name: Entity
      description: The entity that will trigger the automation. This must be a binary sensor. (ie. binary_sensor.fridge)
      selector:
        entity:
          domain: binary_sensor
    friendly_name:
      name: Device Friendly Name
      description: What should we call the entity in the notification? (ie. Fridge)
      default: ""
      selector:
        text:
    issue_state:
      name: Issue State
      description: The state that triggers the automation. Because this is a binary sensor, it can only be on or off. Use the developer tools to find the correct setting.
      default: "on"
      selector:
        select:
          options:
            - "on"
            - "off"
    seconds:
      name: Seconds before alert
      description: The amount of time in seconds that the device can be in the issue state before an alert is triggered.
      default: "150"
      selector:
        number:
          min: 1
          max: 3600
          mode: box
          unit_of_measurement: seconds
    notify_service:
      name: Notify Service
      description: The service that will be called to deliver the notification. (ie. notify.mobile_app_my_phone)
      default: "notify.mobile_app_YOURDEVICE"
      selector:
        text:
    click_url:
      name: Click URL
      description: Where the user will be taken if they tap the notification. (ie. /lovelace/kitchen)
      default: "/lovelace/ROOM"
      selector:
        text:
    title:
      name: Notification Title
      description: The title of the notification. 
      default: "The {{friendly_name}} was left open"
      selector:
        text:
    message:
      name: Notification Message
      description: The message of the notification.
      default: "The {{friendly_name}} was left open at {{now().hour}}:{{now().minute}}:{{now().second}}."
      selector:
        text:
    notification_icon_warning:
      name: Notification Icon (Android Only)
      description: The icon that is shown when the issue is reported. (ie. mdi:fridge-alert)
      default: "alert"
      selector:
        select:
          options:
            - alert
            - alert-circle
            - door
            - door-open
            - motion-sensor
            - fridge
            - fridge-alert
            - home
            - home-alert
            - home-assistant
    notification_color:
      name: Notification Color (Android Only)
      description: The color of the notification.
      default: "red"
      selector:
        select:
          options:
            - "red"
            - "orange"
            - "yellow"
            - "green"
            - "blue"
            - "purple"
    interruption_level:
      name: Interruption Level (iOS Only)
      description: The intrusiveness of the notification recieved. This also determines whether the notification will be delivered while the device is in a focus mode.
      default: "active"
      selector:
        select:
          options:
            - passive
            - active
            - time-sensitive
            - critical
variables:
  friendly_name: !input friendly_name
  entity: !input entity
  click_url: !input click_url
  notification_icon_warning: !input notification_icon_warning

trigger:
  platform: state
  entity_id: !input entity
  to: !input issue_state
  for:
    hours: 0
    minutes: 0
    seconds: !input seconds
action:
- service: !input notify_service
  data:
    message: !input message
    title: !input title
    data:
      clickAction: !input click_url
      url: !input click_url
      tag: !input entity
      color: !input notification_color
      notification_icon: 'mdi:{{ notification_icon_warning }}'
      push:
        interruption-level: !input interruption_level
7 Likes

So, others in this forum may be more nice to look into details of your code.
I wont and this is merely because you stated ‘first blueprint’ …so my response is more conceptual…why not use regular ‘automations’ for this? The GUI has lots or sufficiently powerful options to do the same…not knowing if you already investigated that and rejected of course.

2 Likes

The standard automation feature is fully capable of doing this same thing. My goal with this blueprint was to make the process quicker and more streamlined, especially for new users. Specifically, the UI editor only allows for specifying the title and message of the notification. This blueprint allows notification color, icon, interruption level, and click URL to be specified without messing with the companion docs or data.

Agree with bits/pieces but you can also use the gui as a starting point and use yaml to go-beyond…or (in my exceptional case) turn to nodered. What I (and this is ‘me’) like of gui -automation is the more tangible control but I agree it has limitations.
Maybe others are more advanced to help but my main message is to not make it too complex or overengineer things. When you start adding more complexity…in the end it could become unreadable in case of issues… or in other words: a technical solution might not be the right solution.

Yeah, I’m still a fairly beginner user, so I personally prefer to use as little yaml as possible, though I am getting increasingly comfortable with it. I’ve been thinking of switching to Node Red, but I like the simplicity of having all of my automations in one place using the built in automations feature.

I agree that keeping things simple is important, but I also believe that some complexity is needed for the best experience and organization. For example, having a door icon in the status bar draws my attention much better than a generic HA notification. Same with the red color. It’s a balance between simplicity and functionality.

Thanks for making this! I’ve been trying to find something like this but would like it for all doors being open after x time and before y time. Basically let me know if someone opens a door between 10:30PM and 6AM. Thoughts?

This is how I’d do it. No blueprint required.



1 Like

Your automation is not what this thread was talking about. Yours will check to see if the door is opened during a time period. They are looking for one that will tell if the is open.

Is there any way to get this to check a group i have 4 doors and 12 windows on binary sensors. I do not want 16 automations there must be away in HA or NR to check all and report back which ones are open. Like if your leaving home or at night ??

1 Like

Have you tried making a binary sensor group (settings > devices & services > helpers > +create helper > binary sensor group) and then using that with this blueprint? Because it works exactly like you’d expect it to.

Note the notification portion of the blueprint is broken, but the binary sensor, triggering and event work fine.

A blueprint is the right solution for this problem as it’s a reusable component. There are many conceptual ways to solve any one problem, and a blueprint is the best way for this one.