📲 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)