@panhans Iām not sure if its mentioned but beyond the breaking changes for duration this requires Home Assistant Core 2024.6 or greater due to the collapsible section features. Just noting for others trying to upgrade. Iām going to give the custom trigger and custom actions a test (I had a custom TTS component in fork but it wasnāt very extensible)
after upgrading to 2024.7 I had to log out of the browser and back in to force the update (which changed the behavior of collapsed sections in blueprints)
Yes, had the same issue but reloading with renew the cache did it. (Win: SHIFT+F5) (Mac: cmd+shift+R)
Example use case with this blueprint and Custom component (TTS/Alexa)
I did have an issue with the custom component not executing immediately but seemed to execute after the timeout period passed. I created a PR with the working code iām using. Issue
When any door/window is left open for 5 minutes do the following
- Send Notification to Phone
- Send message to script to speak on alexa device
Alexa script uses scenes to capture the current state, set volume to some level, then return to previous state after executing.
Automation YAML
alias: "Door/Window left open Notification "
description: ""
use_blueprint:
path: panhans/persistent-binary-open-notification.yaml
input:
sensor_entity:
- binary_sensor.alarm_panel_1_zone_7
- binary_sensor.alarm_panel_1_zone_5
- binary_sensor.alarm_panel_1_zone_4
- binary_sensor.alarm_panel_1_zone_6
- binary_sensor.alarm_panel_1_zone_1
- binary_sensor.alarm_panel_1_zone_12
- binary_sensor.alarm_panel_1_zone_8
- binary_sensor.alarm_panel_1_zone_9
- binary_sensor.alarm_panel_1_zone_10
- binary_sensor.alarm_panel_2_zone_6
- binary_sensor.alarm_panel_1_zone_11
notify_device: 4ba8cc67d62b8fe0e7975932c497431d
group: Door-Window-left-open
active_state: "on"
title: "{{ entity_name }} {{ state_attr(sensor,'device_class') }} is open"
message: "{{ entity_name }} {{ state_attr(sensor,'device_class') }} is open"
ha_notification: true
notification_color:
- 255
- 0
- 0
custom_condition:
- condition: time
after: "08:00:00"
before: "23:30:00"
custom_action_on:
- service: script.alexa_tts
data:
message: >-
{{ entity_name }} {{ state_attr(sensor,'device_class') }} has been
left open
period:
hours: 0
minutes: 10
seconds: 0
for_time_m:
hours: 0
minutes: 5
seconds: 0
Script Yaml
alias: Alexa TTS
sequence:
- service: scene.create
data:
scene_id: before_alexa_tts
snapshot_entities:
- media_player.ecobee_mainfloor
enabled: true
- service: media_player.volume_set
data:
volume_level: 0.75
enabled: true
target:
device_id: cb9425897ba3ed9541837a62f0d5e5e1
- service: notify.alexa_media
data:
data:
type: tts
target: media_player.ecobee_mainfloor
message: >-
<audio
src="soundbank://soundlibrary/sports/golf/golf_07"/><amazon:emotion
name="disappointed" intensity="high"><amazon:effect name="drc">{{
message }}</amazon:effect></amazon:emotion>
- service: scene.turn_on
data:
entity_id: scene.before_alexa_tts
enabled: true
mode: single
Hi panhams,
the periodic bug is still exists.
I updatet the bluprint to version 2.4.0 and created a new automatition.
(HA core is 2024.7.2)
alias: Test2 Fenster offen
description: ""
use_blueprint:
path: panhans/entity_state_persistent_notification.yaml
input:
sensor_entity:
- input_boolean.test_fenster
for_time_m:
hours: 0
minutes: 2
seconds: 0
notify_group: BachiAppsNotity
title: "{{ entity_name }} ist offen"
message: >-
Achtung: {{ entity_name }} ist schon {{ ((now() - [sensor] | expand |
map(attribute='last_changed') | first).total_seconds() / 60) | int }}
Minuten lang geƶffnet
stop_button_text: Benachrichtigung deaktivieren
period:
hours: 0
minutes: 2
seconds: 0
status_bar_icon: mdi:window-open-variant
notification_color:
- 255
- 255
- 0
channel: Fenster/TĆ¼ren
group: offene Fenster
Here is my tested situation:
17:14:30 turn sensor on
17:16:31 notification received
17:17:10 turn sensor off
17:17:15 turn sensor on
17:18:31 notification received << this should not happend (from first sensor on?)
17:19:11 notification received << this should not happend (from first sensor off?)
17:19:15 notification received
17:20:00 turn sensor off
If i turn off the sensor after the first mobile notify was received and turn on the sensor in a short time, then i get three periodic notifications on my phone.
17:18:31 and 17:19:11 are both pntc_event.
Sry, for that inconvenience. I did some changes to the latest version. My tests look promising. I wait for your feedback.
Hi panhans,
here is my feedback.
I updatet the blueprint to version 2.4.1.
I testet again my tests.
Sorry, the problem is still exists.
Remember, duration and periodic are 2 minutes in my tests.
14:46:00 turn sensor on
14:48:00 notification received >> correct from 1st on
14:49:10 turn sensor off
14:49:15 turn sensor on again
14:50:01 notification received << this should not happend
14:51:15 notification received >> correct from 2nd on
14:52:01 notification received << this should not happend
14:52:14 turn sensor off
After sensor is switch to 1st OFF and then to 2nd ON, periodic notifications from the 1st ON should not be happened.
Do you need the traces from this test?
Hi panhans,
i found a solution for the periodic problem.
I will send you a pull request on github.
Atm I am a little busy but I am looking forward to review your request theses days. Thank you for your effort!!!
After update the blueprint to lasts version I get a problem with my notifications:
Error: UndefinedError: 'dict object' has no attribute 'from_state'
alias: BuzĆ³n de correo. Notificar ha llegado correo
description: ""
use_blueprint:
path: panhans/entity_state_persistent_notification.yaml
input:
sensor_entity:
- binary_sensor.estado_de_buzon_de_correo
for_time_m: 0
notify_group: all_mobile_devices
message: Tienes nuevo correo en el buzĆ³n
title: Tienes correo
period: 10
notification_color:
- 1
- 102
- 142
channel: BuzonCorreo
group: BuzonCorreo
status_bar_icon: mdi:mailbox-up
You manually triggered the automation, didnāt you? For testing purpose you have to set the entity to its state youāre aiming for or set the state in the developer options for your entity manually. Simply triggering the automation will result in this error.
Also check the State Duration and the Periodical Notification selectors. The type changes and so they need to get reconfigured.
You are right. Sorry for the lack of knowledge! Thank you!
Iām having an issue where there is a significant delay, about 10 minutes in triggering my notifications after the initial trigger.
active_state: 'on'
sensor_entity:
- binary_sensor.refrigerator_sensor_contact
group_target: all_ios_phones
ha_notification: true
notify_device: null
period:
hours: 0
minutes: 0
seconds: 0
action_prefix: STOP_{{this.entity_id}}
notification_color:
- 100
- 200
- 240
notification_color_hex: >-
#{{ '%02x%02x%02x' | format(notification_color[0], notification_color[1],
notification_color[2]) }}
led_color:
- 100
- 200
- 240
led_color_hex: '#{{ ''%02x%02x%02x'' | format(led_color[0], led_color[1], led_color[2]) }}'
trigger:
- platform: state
entity_id:
- binary_sensor.refrigerator_sensor_contact
to: 'on'
for:
hours: 0
minutes: 5
seconds: 0
id: 'on'
- platform: state
entity_id:
- binary_sensor.refrigerator_sensor_contact
from: 'on'
id: 'off'
- platform: event
event_type: pntc_event
id: period
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: template
value_template: '{{ trigger.id == ''on'' }}'
- condition: and
conditions: []
- condition: template
value_template: '{{ trigger.id == ''off'' }}'
- condition: and
conditions:
- condition: template
value_template: >-
{{ trigger.id == 'period' and trigger.event.data.automation ==
this.entity_id }}
- condition: and
conditions: []
action:
- variables:
is_period_trigger: '{{ trigger.id == ''period'' }}'
sensor: |
{% if is_period_trigger %}
{{ trigger.event.data.s_entity }}
{% else %}
{{ trigger.from_state.entity_id }}
{% endif %}
entity_name: '{{ state_attr(sensor,''friendly_name'') }}'
tag: '{{ this.entity_id.split(''.'')[1] + sensor.split(''.'')[1] }}'
action_tag: '{{ action_prefix }}_{{ sensor }}'
st_last_changed: |
{% if is_period_trigger %}
{{ trigger.event.data.st_last_changed }}
{% else %}
{{ as_timestamp([sensor] | expand | map(attribute='last_changed') | first) }}
{% endif %}
- if:
- condition: template
value_template: '{{ is_period_trigger or trigger.to_state.state == active_state }}'
then:
- if:
- condition: template
value_template: '{{ notify_device != none }}'
then:
- if:
- condition: template
value_template: '{{ now() != now() + timedelta(**period) }}'
then:
- data:
title: '{{ entity_name }} is open'
message: >-
Close the refrigerator door. Itās been open for over 5
minutes
data:
ttl: 0
priority: high
notification_icon: mdi:home-assistant
tag: '{{ tag }}'
persistent: true
sticky: true
channel: General
group: refrigeratoropen
color: '{{ notification_color_hex }}'
vibrationPattern: 100, 100
ledColor: '{{led_color_hex}}'
actions:
- action: '{{ action_tag }}'
title: Stop notifying
action: >-
notify.mobile_app_{{ device_attr(notify_device, "name") |
slugify }}
else:
- data:
title: '{{ entity_name }} is open'
message: >-
Close the refrigerator door. Itās been open for over 5
minutes
data:
ttl: 0
priority: high
notification_icon: mdi:home-assistant
tag: '{{ tag }}'
persistent: true
sticky: true
channel: General
group: refrigeratoropen
color: '{{ notification_color_hex }}'
vibrationPattern: 100, 100
ledColor: '{{led_color_hex}}'
action: >-
notify.mobile_app_{{ device_attr(notify_device, "name") |
slugify }}
- if:
- condition: template
value_template: '{{ group_target is defined and group_target != '''' }}'
then:
- if:
- condition: template
value_template: '{{ now() != now() + timedelta(**period) }}'
then:
- data:
title: '{{ entity_name }} is open'
message: >-
Close the refrigerator door. Itās been open for over 5
minutes
data:
ttl: 0
priority: high
notification_icon: mdi:home-assistant
tag: '{{ tag }}'
persistent: true
sticky: true
channel: General
group: refrigeratoropen
color: '{{ notification_color_hex }}'
vibrationPattern: 100, 100
ledColor: '{{led_color_hex}}'
actions:
- action: '{{ action_tag }}'
title: Stop notifying
action: notify.{{ group_target }}
else:
- data:
title: '{{ entity_name }} is open'
message: >-
Close the refrigerator door. Itās been open for over 5
minutes
data:
ttl: 0
priority: high
notification_icon: mdi:home-assistant
tag: '{{ tag }}'
persistent: true
sticky: true
channel: General
group: refrigeratoropen
color: '{{ notification_color_hex }}'
vibrationPattern: 100, 100
ledColor: '{{led_color_hex}}'
action: notify.{{ group_target }}
- if:
- condition: template
value_template: '{{ ha_notification }}'
then:
- data:
title: '{{ entity_name }} is open'
message: Close the refrigerator door. Itās been open for over 5 minutes
notification_id: '{{ tag }}'
action: persistent_notification.create
else:
- data:
data:
tag: '{{ tag }}'
ttl: 0
priority: high
message: clear_notification
action: notify.notify
- data:
notification_id: '{{ tag }}'
action: persistent_notification.dismiss
- if:
- condition: template
value_template: '{{ timedelta(hours=0,minutes=0,seconds=0) != timedelta(**period) }}'
- condition: template
value_template: '{{ now() != now() + timedelta(**period) }}'
- condition: template
value_template: '{{ trigger.id != ''off'' }}'
then:
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: '{{ action_tag }}'
timeout:
hours: 0
minutes: 0
seconds: 0
- variables:
s_last_changed: >
{{ as_timestamp([sensor] | expand | map(attribute='last_changed') |
first) }}
- data:
level: debug
message: >
Last Changed {{ s_last_changed }} Last Change Trigger {{
st_last_changed }}
action: system_log.write
- if:
- condition: template
value_template: '{{ states(sensor) == active_state }}'
- condition: template
value_template: '{{ wait.trigger == none }}'
- condition: template
value_template: '{{ st_last_changed == s_last_changed }}'
then:
- event: pntc_event
event_data:
s_entity: '{{ sensor }}'
automation: '{{ this.entity_id }}'
st_last_changed: '{{ s_last_changed }}'
- if:
- condition: template
value_template: '{{ is_period_trigger or trigger.to_state.state == active_state }}'
then:
- variables:
custom_action_on:
- action: tts.cloud_say
metadata: {}
data:
cache: false
message: Close the refrigerator door. Itās been open for over 5 minutes
entity_id: media_player.sonos_first_floor
- if:
- condition: template
value_template: '{{ custom_action_on != none }}'
then:
- choose: []
default:
- action: tts.cloud_say
metadata: {}
data:
cache: false
message: >-
Close the refrigerator door. Itās been open for over 5
minutes
entity_id: media_player.sonos_first_floor
else:
- variables:
custom_action_off: []
- if:
- condition: template
value_template: '{{ custom_action_off != none }}'
then:
- choose: []
default: []
mode: parallel
id: '1722567758433'
alias: 'Appliance: Refrigerator Door Open'
description: ''
Hey, could you trigger your automation and post a trace log of this run? If you need any help just let me know.
I just tried it today again and it looks like it is working now. Thanks!
I digged in a bit deeper today and have a few question / suggestions:
- ist it possible to use a sensor group and expand it instead of adding multiple sensors?
- is it possible to combine the messages for all sensors in one message listing all the sensors?
- can I configure the message title as optional?
- is it possible to add a function to pause the notifications for eg. 30 mins?
Thanks,
Sebastian
One more, could there be a configurable target dashboard tap when clicking on the message?
Iāve been looking for a blueprint like this, thank you.
I have it setup so when any of the doors remain open for x period of time, i get notified + Alexa makes an announcement that door is still open but Iām encountering one issue.
If I choose the āStop Notifyingā option via the message on my iOS, Alexa immediately makes one last announcememt that door is still open.
It does this every time I use the āStop Notifyingā open.
Iām using the āCustom Action Onā option with no āCustom Action Offā
Any suggestions ?
Thanks Manny.
Iām trying to cover a specific scenario: inform me if the door handle is open or tilted and the door contact is closed longer than 5 mins
I tried it with the door handle sensor as trigger, and the door sensor as condition.
This works fine if the condition stays the same.
If I open the door for longer than 5 mins, then close it I donāt receive a notification. Even the door handle is still open.
It seems, that the condition is just checked the first time and not during the periodic notifications.
Can this be added? Check condition for every run and not just at the first run.
Hi Sebastian,
Yes, the trigger is an event thing.
See this:
Automations #1: trigger only fires when it changes from not true to true.