šŸ“² Contact Sensor (Door or Window) Left Open Notification

Thanks for the report. German is perfectly fine for me :slight_smile:
Can you go through the different tabs and does it say somewhere which service it is trying to run? Or is it just empty. Can you also try to reproduce it and describe when exactly this happens. Thanks in advance!

Iā€™ll add it to my to do list!

1 Like

Hard to say what triggers the error. For me it seems the error happens when the script tries to make a second Iteration ā†’ see screenshot below

Today HaustĆ¼re worked perfetct with no error while GartentĆ¼re has shown the same error again todayā€¦
HaustĆ¼re


vs GartentĆ¼re


In the different tabs I could not find any more information about the service it trys to runā€¦ is there any special tab to look into?

1 Like

Good blueprint, but i am also one of those that needs multiple entity support. Doing that single entity over and over wont work for me either. I pretty much have this running now with actionable notifications and clickAction as well so it would be more of the same single use work that I already have in place

Great job though and it looks well put together!

The only difference I spot is that the tag in the failing iteration ends with ā€œ,ā€ which the first one does not. Can you send the YAML config of your blueprint you get to via editing the blueprint and then clicking the three dot menu and in German it says ā€œAls YAML bearbeitenā€. This could probably help best at investigating the problem further.

:rocket: Update 2024.04.23 has been released

See the changelog in the initial post for details.

@schlomm, @gyle, @chris400, @hazio, @aelsharawi, @mefistofelis and @danktankk: Your request about supporting binary_sensor group has been implemented. As of now input_boolean that are grouped like described here are not supported.

@chris400 Version number has been added. Thanks for the idea!

If you notice something not working as expected please let me know!

2 Likes

here is my YAML config

Blueprint config

alias: NOTIFICATION GartentĆ¼re offen
description: Nach 10 Minuten erfolgt eine Notification, dass die GartentĆ¼re offen ist
use_blueprint:
  path: Raukze/contact-sensor-left-open-notification.yaml
  input:
    trigger_entity: binary_sensor.tursensor_werkstatt_contact
    friendly_name: GartentĆ¼re
    notify_services_string: "notify.telegram_roland, "
    notification_title: NOTIFICATION {{ friendly_name }}
    notification_message: >-
      {{ friendly_name }} steht offen {{ as_timestamp(now()) |
      timestamp_custom('%T', True) }}.

and

automation config

mode: restart
max_exceeded: silent
variables:
  friendly_name: GartentĆ¼re
  trigger_entity: binary_sensor.tursensor_werkstatt_contact
  issue_state: 'on'
  duration_issue_state:
    minutes: 10
  condition_send_notification: []
  delete_notification: true
  duration_from_issue_state:
    seconds: 5
  notify_services_string: 'notify.telegram_roland, '
  notification_click_url: /lovelace/ROOM
  notification_title: NOTIFICATION {{ friendly_name }}
  notification_message: >-
    {{ friendly_name }} steht offen {{ as_timestamp(now()) |
    timestamp_custom('%T', True) }}.
  repeat_notification: false
  time_between_repeat_notification:
    minutes: 10
  notification_icon_warning: alert
  notification_color: red
  notification_interruption_level: active
  custom_action_issue_state: []
  custom_action_from_issue_state: []
trigger:
  - platform: state
    entity_id: binary_sensor.tursensor_werkstatt_contact
    to: 'on'
    for:
      minutes: 10
    id: send_notification
  - platform: state
    entity_id: binary_sensor.tursensor_werkstatt_contact
    from: 'on'
    for:
      seconds: 5
    id: delete_notification
action:
  - variables:
      notify_services_list: '{{ notify_services_string.split('','') }}'
      number_of_notify_services: '{{ notify_services_list | count }}'
      notification_tag: >-
        {{ trigger_entity[-20:] }}-{{ friendly_name[-20:] }}-{{
        notify_services_string[-20:] }}
  - choose:
      - conditions:
          - condition: trigger
            id: send_notification
          - condition: []
        sequence:
          - repeat:
              sequence:
                - parallel:
                    - repeat:
                        count: '{{ number_of_notify_services }}'
                        sequence:
                          - service: '{{ notify_services_list[repeat.index-1] }}'
                            data:
                              message: >-
                                {{ friendly_name }} steht offen {{
                                as_timestamp(now()) | timestamp_custom('%T',
                                True) }}.
                              title: NOTIFICATION {{ friendly_name }}
                              data:
                                clickAction: /lovelace/ROOM
                                url: /lovelace/ROOM
                                tag: '{{ notification_tag }}'
                                color: red
                                notification_icon: mdi:{{ notification_icon_warning }}
                                push:
                                  interruption-level: active
                                persistent: false
                                sticky: false
                    - choose: []
                      default: []
                - if:
                    - '{{ repeat_notification }}'
                  then:
                    - delay: '{{ time_between_repeat_notification }}'
              until:
                - '{{ not repeat_notification }}'
      - conditions:
          - condition: trigger
            id: delete_notification
          - '{{ delete_notification }}'
        sequence:
          - parallel:
              - repeat:
                  count: '{{ number_of_notify_services }}'
                  sequence:
                    - service: '{{ notify_services_list[repeat.index-1] }}'
                      data:
                        message: clear_notification
                        data:
                          tag: '{{ notification_tag }}'
              - choose: []
                default: []
id: '1713561691878'
alias: NOTIFICATION GartentĆ¼re offen
description: Nach 10 Minuten erfolgt eine Notification, dass die GartentĆ¼re offen ist

The value should just be notify.telegram_roland without the comma and space characters. This might be the issue.

Thx for your help :+1:, I just changed it. Hope this fixed it :grinning:

Hello Malte
Sorry but I canā€™t make it works.
And I donā€™t see why:

My yaml
mode: single
max_exceeded: silent
variables:
  custom_friendly_name: ''
  trigger_entity: binary_sensor.porte_et_fenetres
  issue_state: 'on'
  duration_issue_state:
    hours: 0
    minutes: 0
    seconds: 10
    days: 0
  condition_send_notification:
    - condition: state
      entity_id: person.corinne
      state: not_home
    - condition: state
      entity_id: person.philippe
      state: not_home
  delete_notification: false
  duration_from_issue_state:
    seconds: 5
  notify_services_string: notify.notify
  notification_click_url: /lovelace/ROOM
  notification_title: The {{ friendly_name }} was left open
  repeat_notification: true
  time_between_repeat_notification:
    hours: 0
    minutes: 1
    seconds: 0
    days: 0
  notification_icon_warning: alert
  notification_color: red
  notification_interruption_level: active
  custom_action_issue_state: []
  custom_action_from_issue_state: []
trigger:
  - platform: state
    entity_id: binary_sensor.porte_et_fenetres
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      days: 0
    id: send_notification
  - platform: state
    entity_id: binary_sensor.porte_et_fenetres
    from: 'on'
    for:
      seconds: 5
    id: delete_notification
action:
  - variables:
      notify_services_list: '{{ notify_services_string.split('','') }}'
      number_of_notify_services: '{{ notify_services_list | count }}'
      notification_tag: >-
        {{ trigger_entity[-20:] }}-{{ custom_friendly_name[-20:] }}-{{
        notify_services_string[-20:] }}
      initially_triggered_at: '{{ now() }}'
  - choose:
      - conditions:
          - condition: trigger
            id: send_notification
          - condition:
              - condition: state
                entity_id: person.corinne
                state: not_home
              - condition: state
                entity_id: person.philippe
                state: not_home
        sequence:
          - repeat:
              sequence:
                - variables:
                    friendly_name: |
                      {% if custom_friendly_name != '' %}
                        {{ custom_friendly_name }}
                      {% else %}
                        {% set expanded_trigger_entity_list = expand(trigger_entity) | selectattr('state', 'eq', issue_state) | map(attribute='name') | join(', ') %}
                        {{ ' & '.join(expanded_trigger_entity_list.rsplit(', ', 1)) }}
                      {% endif %}
                - parallel:
                    - repeat:
                        count: '{{ number_of_notify_services }}'
                        sequence:
                          - service: '{{ notify_services_list[repeat.index-1] }}'
                            data:
                              message: >-
                                The {{ friendly_name }} was left open at {{
                                as_timestamp(initially_triggered_at) |
                                timestamp_custom('%T', True) }}.
                              title: The {{ friendly_name }} was left open
                              data:
                                clickAction: /lovelace/ROOM
                                url: /lovelace/ROOM
                                tag: '{{ notification_tag }}'
                                color: red
                                notification_icon: mdi:{{ notification_icon_warning }}
                                push:
                                  interruption-level: active
                                persistent: true
                                sticky: true
                    - choose: []
                      default: []
                - if:
                    - '{{ repeat_notification }}'
                  then:
                    - delay: '{{ time_between_repeat_notification }}'
              until:
                - '{{ not repeat_notification }}'
      - conditions:
          - condition: trigger
            id: delete_notification
          - '{{ delete_notification }}'
        sequence:
          - parallel:
              - repeat:
                  count: '{{ number_of_notify_services }}'
                  sequence:
                    - service: '{{ notify_services_list[repeat.index-1] }}'
                      data:
                        message: clear_notification
                        data:
                          tag: '{{ notification_tag }}'
              - choose: []
                default: []
id: '1715173036123'
alias: šŸšŖ Contact Sensor Left Open Notification by Malte
description: ''
trace:
  stored_traces: 20

Every try leads to this issue.
An idea of what I am doin wrong?

Looking at the screenshot of the execution attempt, Iā€™m wondering if you triggered the automation manually or if the sensor status change actually triggered the automation? To me it looks like a manual trigger, which definitely doesnā€™t work but is intentional.

Okey. Thanks for having replied. Iā€™m going to test it IRL. :smiley:

Iā€™m pretty new to Home Assistant so forgive me if thereā€™s an obvious answer to this, but Iā€™ve configured an automation using the blueprint and when I manually run it Iā€™m not getting a notification and am seeing the below error in my logs.

Template variable warning: ā€˜friendly_nameā€™ is undefined when rendering ā€˜The {{ friendly_name }} was left openā€™

Iā€™ve used the default settings in the blueprint and updated the Entity ID for my DW sensor group (Door & Window Sensors) and updated my device id for my phone (notify.mobile_app_pixel_7).

What am I missing?

Thanks for trying out my blueprint. Manual trigger does not work due to the implementation of the blueprint. Easiest way to try or debug is to just set the intervals to a couple of seconds or just 0 and the notification should arrive immediately when the state of the sensor changes. Hope that my answer is helpful!

1 Like

This blueprint is great! Itā€™s replacing a custom written AppDaemon app I had for this purpose. Thanks for sharing it.

Thereā€™s one thing I donā€™t see how to set up. Triggering on contact sensors works fine. But, is there a way it can trigger when people become away, or a zone state changes? For example, letā€™s say:

  1. I open a window before bed.
  2. I leave the next morning for work, and forget to close the window.
  3. ???

For my custom automations, I have a separate automation that triggers on a Person group becoming not_home, and then checking the state of doors and windows. Iā€™d love to be able to replace that with this blueprint!

Thanks, Iā€™m glad that the blueprint is helping you! What you are trying to achieve is not possible and neither do I intent to add a custom trigger. Itā€™s not that I donā€™t want to, but put simple the design of the blueprint wonā€™t allow me to add such a feature.

1 Like

Awesome blueprint, thx a lot!
For Android users it could be helpful to add an option to add the following two fields to the data object:

ttl: 0
priority: high

That will make the notifications appear immediately.
See documentation:

I use it for all my notifications and itā€™s a day and night difference in delivery speed.

Hi @Malte
thank you very much for this great blueprint.
Got a question if the following scenario is already supported (and how this can be achieved) or the blueprint may be enhanced to support it.

What I want to achieve is the following:

  • when a window is opened and the outside temperature is below, say, 20 degree Celcius, I want get a notification.

  • however, when a window is opened and the outside temperature is above, say, 20 degree celcius, I donā€™t want a notification yet.
    However if the outside temperature is dropping, the window is still open (so no new trigger), below that temperature I want to get (repeating) notification(s).

Thanks in advance.

Thanks @wfrey! Iā€™m glad that you like it.

Sorry but currently the automation does not trigger when the custom condition changes. Thus this is neither possible currently nor do I intend to add this as a feature because this would add a lot of overhead. Hope you can understand!

Sorry for the late reply. Iā€™ll add that to my todo list.