Yet not another door/window/sensor open warning notification with auto close and reminder

Hi there,

just want to share my blueprint with you. Feel free to share thoughts, faults and improvements. :slight_smile:

What does it do?

It creates a notification based on a defined state of a sensor, e.g. a window or a door. The notification disappear when the door/window/sensor leave its defined state.

New

  • periodical notification with adjusable duration
  • actionable notification to stop periodical notification
  • BREAKING CHANGE: check your custom messages and title. use entity_name and active_state variables instead of the old trigger variables. Entity ID is stored in a variable called sensor

What can you tweak?

  • sensors that should be monitored
  • trigger states of the sensors
  • the time the sensors must be in the defined state before the notification will be send
  • the notification device or group
  • notification message, title and icon

Updates

  • open blueprint for any entity with any state (not only binary_sensors)
  • add option for home assistant persistent notification

Links

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

Source

My blueprints
Scene based theatre mode
Simple scene toggle
Yet not another door/window/sensor open warning notification with auto close
Zone notification extended
Advanced scheduled heating control with calibration and window detection
More intelligent vaccum robot scheduling

4 Likes

Thanks for that blueprint. Installed it, created an automation and it is working.

1 Like

Would like an option to acknowledge the open door event and stop alerts until next trigger.

I don’t know what you mean. The automation pushes exactly one notification for each sensor if open. Do you want only one notification for the whole bunch of defined sensors if one hits the defined trigger state?

would it also be possible to integrate the HomeAssistant persistent.notification service?
Right now, it is required to enter a device that should receive the notification - but I would also like to use the internal notification system (if HomeAssistant is not running on a Mobile Device)

service: notify.persistent_notification
data:
  title: A window is Open!
  message: "{{ states('sensor.door') }}"
1 Like

I added the option and refactored the code in last commit. Feel free to test and give feedback. :wink:

1 Like

thanks :slight_smile:
But the “device” for the notification is still set as required - which is bad if you don’t have a mobile device :slight_smile:

If you use the notification provide, device is not required.
if you use the device, notification provider is not required.
One of both needs to be used, but both can be used.

Hope, this does make sense?

Maybe similar to the low battery notification - in this case, you can set an action (which can be a notification or any other thing you can imagine)

Also I did a short test, since I’ve noticed that the blueprint can also be saved as an automation without adding a device.
Unfortunately, the Notification was not triggered in my test - because the blueprint config does not include any notification config:

id: '1666121314816'
alias: Persistent entity state notification
description: ''
use_blueprint:
  path: panhans/entity_state_persistent_norification.yaml
  input:
    sensor_entity:
      - binary_sensor.turkontakt_terrassentur_state
    ha_notification: true
    for_time_m: 1

while here’s my config:

automation config yaml:

variables:
  active_state: 'on'
  message: 'Keep in mind: {{ trigger.from_state.attributes.friendly_name }} is open'
  title: '{{ trigger.from_state.attributes.friendly_name }} is open'
  sensor_entity:
    - binary_sensor.turkontakt_terrassentur_state
  group_target: ''
  ha_notification: true
trigger:
  - platform: state
    entity_id:
      - binary_sensor.turkontakt_terrassentur_state
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.turkontakt_terrassentur_state
    from: 'on'
condition: []
action:
  - if:
      - condition: template
        value_template: '{{ trigger.to_state.state == active_state }}'
    then:
      - if:
          - condition: template
            value_template: '{{ notify_device is defined }}'
        then:
          - domain: mobile_app
            type: notify
            device_id: false
            title: '{{ title }}'
            message: '{{ message }}'
            data:
              ttl: 0
              priority: high
              notification_icon: mdi:home-assistant
              tag: pesn-{{ trigger.entity_id }}
              persistent: true
              sticky: true
      - if:
          - condition: template
            value_template: '{{ group_target is defined  }}'
        then:
          - service: notify.{{ group_target }}
            data:
              title: '{{ title }}'
              message: '{{ message }}'
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:home-assistant
                tag: pesn-{{ trigger.entity_id }}
                persistent: true
                sticky: true
      - if:
          - condition: template
            value_template: '{{ ha_notification }}'
        then:
          - service: persistent_notification.create
            data:
              title: '{{ title }}'
              message: '{{ message }}'
              notification_id: pesn-{{ trigger.entity_id }}
    else:
      - service: notify.notify
        data:
          data:
            tag: pesn-{{ trigger.entity_id }}
            ttl: 0
            priority: high
          message: clear_notification
      - service: persistent_notification.dismiss
        data:
          notification_id: pesn-{{ trigger.entity_id }}
mode: parallel
id: '1666121314816'
alias: Persistent entity state notification
description: ''

In addition to that:
I have tested the blueprint on another installation (where I have the mobile app connected to)…
I have set my mobile device + HomeAssistant notification service - and did not receive a notification - Either on the phone - nor on the HA Installation itself.

id: '1666122430701'
alias: Persistent entity state notification
description: ''
use_blueprint:
  path: panhans/entity_state_persistent_norification.yaml
  input:
    sensor_entity:
      - binary_sensor.hmip_fenster_und_turkontakt_wc
    for_time_m: 1
    notify_device: cf2d3633a3207d334b8d1e87d311ec7c
    ha_notification: true

automation config yaml:

variables:
  active_state: 'on'
  message: 'Keep in mind: {{ trigger.from_state.attributes.friendly_name }} is open'
  title: '{{ trigger.from_state.attributes.friendly_name }} is open'
  sensor_entity:
    - binary_sensor.hmip_fenster_und_turkontakt_wc
  group_target: ''
  ha_notification: true
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hmip_fenster_und_turkontakt_wc
    to: 'on'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.hmip_fenster_und_turkontakt_wc
    from: 'on'
condition: []
action:
  - if:
      - condition: template
        value_template: '{{ trigger.to_state.state == active_state }}'
    then:
      - if:
          - condition: template
            value_template: '{{ notify_device is defined }}'
        then:
          - domain: mobile_app
            type: notify
            device_id: cf2d3633a3207d334b8d1e87d311ec7c
            title: '{{ title }}'
            message: '{{ message }}'
            data:
              ttl: 0
              priority: high
              notification_icon: mdi:home-assistant
              tag: pesn-{{ trigger.entity_id }}
              persistent: true
              sticky: true
      - if:
          - condition: template
            value_template: '{{ group_target is defined  }}'
        then:
          - service: notify.{{ group_target }}
            data:
              title: '{{ title }}'
              message: '{{ message }}'
              data:
                ttl: 0
                priority: high
                notification_icon: mdi:home-assistant
                tag: pesn-{{ trigger.entity_id }}
                persistent: true
                sticky: true
      - if:
          - condition: template
            value_template: '{{ ha_notification }}'
        then:
          - service: persistent_notification.create
            data:
              title: '{{ title }}'
              message: '{{ message }}'
              notification_id: pesn-{{ trigger.entity_id }}
    else:
      - service: notify.notify
        data:
          data:
            tag: pesn-{{ trigger.entity_id }}
            ttl: 0
            priority: high
          message: clear_notification
      - service: persistent_notification.dismiss
        data:
          notification_id: pesn-{{ trigger.entity_id }}
mode: parallel
id: '1666122430701'
alias: Persistent entity state notification
description: ''

Furthermore:
It is only possible to add one device that should receive the notification.
It would be good, if you could also add multiple devices (if you and your partner is using homeassistant on the phone :wink: )

2 Likes

I’ve updated the blueprint. For me the notification in home assistant and device worked with the old versions. If you have troubles watch in the log section under system in your options or press the trace button in your automation configuration page.

all right, I will do more tests :slight_smile:

well - I have only tested it on my installation without mobile app - and it was working as expected :slight_smile: The notification has been sent successfully - and now, I can start to do all my messeging automations that I’ve already planned to do in the next days :smiley: :smiley:

What a time-saver - THANKS

1 Like

hi :slight_smile:

I have now created several notifications that should be triggered from your blueprint - and… some tests worked well… But now - I don’t receive any notification when I try to test them & I have the following errors in the logs (for each persistent notification)

Logger: homeassistant.components.automation.persistent_door_open_notification
Source: components/automation/__init__.py:253
Integration: Automatisierung (documentation, issues)
First occurred: 21:54:47 (8 occurrences)
Last logged: 22:01:10
Error rendering variables: UndefinedError: 'dict object' has no attribute 'from_state'

How did you trigger the automation? As you can see in the error message the trigger entity has no attribute from_state. If the automation gets triggered by the defined entity everything should work well. Did you triggered it manually in the automation menu maybe?

let me check again - maybe, I have made some other mistakes, because I had a couple of automations which should trigger under different conditions (sometimes, they were fired - sometimes not)

Also, I got some other errors recently, which I did not understand - and I am rebuilding some of them now.

I will come back again, if I have any new information.

Hi, I don’t know what I’m doing wrong but I can’t seem to get it working?

Could you try to set the minutes to 1? Seems the number selector for blueprints has an issue with 0 as input. I’ll try to solve this issue.

Yeah I did that also but nothing.
Even when I press “Run Actions” nothing happens

Apart from notify, what else can I put in there? Can I leave it blank? Tried that but still no dice

Run Action wont trigger the automation, because its based on the trigger entities. You can leave notification group or notification device blank.
I’ve updated the blueprint so 0 values for the time can get handled. So the notification appears immediately. But there is still a home assistant related bug with Zero values for the input_number field.
Try update the blueprint and let it get triggered by the trigger entity. If nothing happens press the trace button in the automation itself or have a look in system > logs for further information.

Hi @panhans,
I might have an idea for improvement - or a bug… depends on how you call it :slight_smile:

  1. I am checking for an entity, which could have three states.
    → open
    → tilted
    → closed

I would like to give a notificiation, when the state is either open or tilted - so, it would be great, if the blue print would allow one or more states that can be true.
Or a configuration “if not in state clsoed”

Then, I want to display the entities state in the message.
Therefore, I’ve tried to use:

Nicht vergessen:
  {{ trigger.from_state.attributes.friendly_name }}
ist immer noch
  {{ trigger.from_state.state }}

(Don’t forget, ENTITY is still STATE)

Right now, the notification will be trieggered, when the state is OPEN.
This is working as expected, BUT:
The message does show:

grafik
(Don’t forget ENTITY is still ‘closed’)

I don’t know, where the closed state does come from… ?!
I’ve tried to change the UI language - but it does not seem to be related to that setting…

Multiple states should be possible, but then the last state change will overwrite previous notifications. Also would be possible to send/delete a notification for each status but I don’t know if there is a use case for this.

For your localization problem you can try this:

Nicht vergessen:
  {{ trigger.from_state.attributes.friendly_name }}
ist immer noch
  {{ iif(trigger.from_state.state == 'on', 'geöffnet', 'geschlossen') }}

For more states simply copy the line and edit it like

Nicht vergessen:
  {{ trigger.from_state.attributes.friendly_name }}
ist immer noch
  {{ iif(trigger.from_state.state == 'open', 'geöffnet', '') }}
  {{ iif(trigger.from_state.state == 'tilted', 'angekippt', '') }}
  {{ iif(trigger.from_state.state == 'closed', 'geschlossen', '') }}

or stack them:

Nicht vergessen:
  {{ trigger.from_state.attributes.friendly_name }}
ist immer noch
  {{ iif(trigger.from_state.state == 'open', 'geöffnet', iif(trigger.from_state.state == 'tilted', 'angekippt', 'geschlossen')) }}
1 Like