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.
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:
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).
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.
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:
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.
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.
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
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
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?
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:
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”.
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.