📲 Contact Sensor (Door or Window) Left Open Notification

Another addition now I know why it is executed twice. The error message (friendly_name is undefined) always appears when a window is closed. I just tested it again and when I closed the window the message appeared in the log.

@Malte, I have ask Gemini nan get this result:

The error message “friendly_name is undefined” occurs in the blueprint because the friendly_name variable is used before it’s defined. This happens when the condition to delete the notification is met (trigger id: delete_notification).

Let’s see how the code works:

  1. Trigger: The blueprint defines two triggers:

    • send_notification: This trigger fires when the trigger_entity changes to the issue_state (e.g., door/window is left open) and stays in that state for the duration_issue_state (e.g., 10 minutes).
    • delete_notification: This trigger fires when the trigger_entity changes from the issue_state (e.g., door/window is closed).
  2. Variables: The code defines a variable friendly_name inside a conditional statement within the repeat loop triggered by send_notification. This means the friendly_name variable is only defined if the condition_send_notification is met.

  3. Notification Deletion: When the delete_notification trigger fires, the code tries to use the friendly_name variable to construct the notification message. However, since the delete_notification doesn’t trigger the condition_send_notification, the friendly_name variable remains undefined.

Here’s how to fix the error:

There are two ways to fix this error:

  1. Move the friendly_name definition outside the conditional statement:
variables:
  custom_friendly_name: !input friendly_name
  # ... other variables

sequence:
  - repeat:
    # ... your loop here
      variables:
        friendly_name: "{% if custom_friendly_name != '' %}\n  {{ custom_friendly_name }}\n{% else %}..."

This way, the friendly_name variable is defined before it’s used in both notification creation and deletion.

  1. Use a default value for friendly_name:
variables:
  custom_friendly_name: !input friendly_name
  # ... other variables

sequence:
  - repeat:
    # ... your loop here
      variables:
        friendly_name: "{{ custom_friendly_name | default('Unknown') }}"

This way, if custom_friendly_name is undefined, it will default to “Unknown” to avoid the error.

Both approaches will ensure that the friendly_name variable is always defined and prevent the error message.

Hi great work, but is it possible to get the notification if a window has been opened for ex. 10 min?
I only get a notification 10 min after i have closed the window, and that is not doing any good for me at least.

Hi, works great, thanks for that, that’s exactly what I need.

Sorry for my stupid question, but I’m not that good at Home Assistant yet. Where exactly do I have to enter the first code and how?

Thank you for your help.

I think the programmer of the blueprint would have to adjust this.

silly newbie question.

how do i install this blueprint?

also is the below reference the updated blueprint or the original outdated one?

inspired by the fantastic work of @Neekster (check it out here ).

thanks

Is it possible to trigger again, if a second sensor of the group turns on?

Hi @Malte any plans to support groups?

Hey all… looks like @Malte has abandoned this. Anyone know a good alternative?

I’d really like to have…

Channels
Groups (might be overly optimistic on this)

1 Like

Hi,

I tried this code and it works perfectly but in the HA logs i found some warnings :

HA Log :
2025-04-17 11:34:19.140 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'friendly_name' is undefined when rendering '{{ friendly_name }} ouverte depuis longtemps'

Script :

alias: Porte d'entrée ouverte depuis longtemps
description: ""
use_blueprint:
  path: Raukze/contact-sensor-left-open-notification.yaml
  input:
    trigger_entity: binary_sensor.door_main_entrance_opening
    notify_services_string: notify.mobile_app_honor
    notification_icon_warning: door-open
    friendly_name: Porte
    notification_title: "{{ friendly_name }} ouverte depuis longtemps"
    notification_message: >-
      {{ friendly_name }} est ouverte depuis longtemps, pensez à la fermer !
      Elle est ouverte depuis {{ as_timestamp(initially_triggered_at) |
      timestamp_custom('%T', True) }}.
    notification_click_url: /dashboard-home/0
    delete_notification: false

I missed something ?

Thank you

1 Like

This one looks pretty decent:

Advanced Mobile Device Notifier Blueprint

very different, that one you posted is just for general mobile notifications with not many features. I use this BP for repeating notification and Blacky’s BPs, they do a lot more than the one you posted. If I can get Blacky to integrate repeating, his would be the only one needed

Hello!

I have a question about the conditions. The conditions are checked during the initial notifications, but not for repeated notifications. Is it possible to adjust it so that the conditions are checked before each notification?

Not sure but is it enoupf to change the following code?

  • if:
    • ‘{{ repeat_notification }}’
      then:
    • delay: ‘{{ time_between_repeat_notification }}’

to

  • if:
    • ‘{{ repeat_notification }}’
      then:
    • delay: ‘{{ time_between_repeat_notification }}’
    • condition: !input condition_send_notification

Hi all,
and thanks to @Malte for your great automation. As there were a few things missing like auto detection of devices to notify I was so free and forked it, add missing stuff for me. If it helps someone please find blueprint at:

Diff can be found at: Revisions · Home Assistant Blueprint: Contact Sensor Left Open Notification · GitHub

Hello simon,

I want to test it, but I get an error while importing:

mapping values are not allowed here in “”, line 322, column 27: data: ^

What is ‘auto detection of devices’?

I used this BP for a while then recoded it to do a lot more…

1 Like

Issue fixed @Timo25

I dont want to deal with defining which device to notify and also dont want to deal with the automation when we get a new phone.

The automation includes to notify all devices “tracked” for respective “People” with the companion app. First it notfies people at “home” and second, if the door/window is still open it notifies all other. All this is done without user interaction and specifing additional notifiers. just with “device_trackers”.

Hi, is it possible to dismiss the notification for a couple of hours or for the rest of the day? If so, how can I implement it?

I was seeing the following error each time one of the sensors were triggered in the home assistant logs (Template variable warning: ‘friendly_name’ is undefined when rendering ‘The {{ friendly_name }} was left open’.). While the automation itself was working fine I am a stickler for not logging extra errors that are not needed. I modified the YAML to prevent this from happening and tested the automation again to confirm that no further errors are being logged. If anyone was interested in using this updated code let me know. I am unsure of how to attach the file in my message.

1 Like