I updated my blueprint to distinguish between an initial-delay and a subsequential delay. With regards to the bonus: Unfortunately, there seems to be an issue with regards to define expressions in the notify_message input as they are not resolved.
For example:
notify_message: "Alert is triggered for entity: {{entity_name}}"
…is not resolved and thus the mobile notifications is displayed as: “Alert is triggered for entity:”
As long as that problem exists, I cannot add a dynamic expression such as alert_triggerd_since
Nice blueprint!
Would it be possible to make the device notification optional? I’d like a message on my google home only, no message on my phone. With service calls I can do the google home part.
Awesome blueprint! Will try to migrate few of my basic and hopefully advanced alerts and manual automations to this one.
As @CentralCommand already noted in his first post I see some disavantages (which are partly based on the general limitations of blueprints), mainly currently:
Automation doesn´t survive HA restarts
Very limited trigger condition. The need for creating template sensors basically kicks me back to the YAML and reload/HA reboot world which I was trying to leave cause that´s almost as annoying as the current official alert integration which lacks UI support.
I´ll give it a try but likely more for simple scenarios (“when door is open”) as more complex ones (“door A or window B or C or D is open after sunset and before xx o’clock”) seem to be a bit too much because of #2.
Is there any way to get multiple devices get notified?
I updated the blueprint like this and can select multiple devices (I’m not sure this is the right way)
notify_device:
name: Device to notify
description: Device needs to run the official Home Assistant app to receive
notifications.
selector:
target:
device:
integration: mobile_app
But I’m fairly certain that the sequence won’t take multiple, not sure how to structure that?
you’ll need to use a notify group instead of a list of devices. Then make an input option to use the group if its present instead of the device
i also updated the delays to minutes instead of seconds as the max was for an hr and I wanted to monitor states of say if a fridge has not cycle its compressor or became unavailable for longer than 3 hrs
blueprint:
name: Nagging Alerting Notification Automation
description: >
Trigger an alert based on the state of a given sensor.
The Alert is send to a mobile app device and repeats as long as the sensor is in the given state.
An additonal action can be specified. This might be useful to tts the message.
domain: automation
source_url: https://gist.github.com/pavax/08705e383bdd3b58ea7b75a1f01c7e54
input:
sensor_entity:
name: Sensor Entity
description: "Sensor that triggers an alert"
default:
selector:
entity:
alert_state:
name: Sensor Alert state
description: "Sensor state that triggers the alert notification"
default: "on"
initial_delay:
name: Initial Alert Delay
description: "Time to wait until an alert notification will be send (inital)"
default: 120
selector:
number:
min: 0
max: 1440
unit_of_measurement: minutes
repeat_delay:
name: Repeat Alert Delay
description: "Time to wait until an alert notification will be send (subsequently)"
default: 120
selector:
number:
min: 0
max: 1440
unit_of_measurement: minutes
max_alerts:
name: Max Alert Notifications
description: "How often should the alert get triggered while the alert is active"
default: 3
selector:
number:
min: 0
max: 100
unit_of_measurement: count
notify_device:
name: Device to notify
description: "Device needs to run the official Home Assistant app to receive notifications."
default: false
selector:
device:
integration: mobile_app
notify_group:
name: Notification Group
description: The name of the notification group to call.
default: ""
notify_message:
name: Notifcation Message (Optional)
description: 'Default: "Alert {{ entity_name }} triggered"'
default: "Alert {{ entity_name }} triggered"
resolved_message:
name: Message when the alert is resolved (Optional)
description: 'Default: "Alert {{ entity_name }} resolved"'
default: "Alert {{ entity_name }} resolved"
alert_action:
name: Alert Action (Optional)
description: "Action to run while the alert is active. You can reuse the {{ notify_message }} variable"
default: []
selector:
action:
resolved_action:
name: Resolved Action (Optional)
description: "Action to run after an alert was resolved. You can reuse the {{ resolved_message }} variable"
default: []
selector:
action:
dismiss_entity:
name: Dismiss Alert (Optional)
description: "Input Boolean to dismiss an alert"
default:
selector:
entity:
domain: input_boolean
condition_entity:
name: Condition Entity (Optional)
description: "Condition Entity before an alert gets triggered"
default:
selector:
entity:
condition_entity_state:
name: Condition Entity state (Optional)
description: "State of the condition entity"
default: "on"
mode: restart
max_exceeded: silent
variables:
sensor_entity: !input sensor_entity
entity_name: "{{ state_attr(sensor_entity,'friendly_name') }}"
notify_message: !input notify_message
resolved_message: !input resolved_message
alert_action: !input alert_action
alert_state: !input alert_state
dismiss_entity: !input dismiss_entity
resolved_action: !input resolved_action
send_notification: "false"
initial_delay: !input initial_delay
repeat_delay: !input repeat_delay
condition_entity: !input condition_entity
condition_entity_state: !input condition_entity_state
group_target: !input notify_group
trigger:
- platform: state
entity_id: !input sensor_entity
to: !input alert_state
- platform: homeassistant
event: start
condition:
- condition: template
value_template: "{{ is_state(sensor_entity, alert_state) }}"
- condition: template
value_template: "{{ condition_entity == None or is_state(condition_entity, condition_entity_state) }}"
action:
- choose:
- conditions: "{{ dismiss_entity != None }}"
sequence:
- service: input_boolean.turn_on
data:
entity_id: !input dismiss_entity
# Initial Wait
- wait_for_trigger:
- platform: template
value_template: "{{ not is_state(sensor_entity, alert_state)}}"
- platform: template
value_template: "{{ dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
timeout:
minutes: !input initial_delay
# None = alert was not resolved or dimissed in the specified wait-time thus we need to send notifications.
- variables:
send_notification: "{{ wait.trigger == None }}"
- repeat:
count: !input max_alerts
sequence:
- variables:
repeat_count: "{{ repeat.index }}"
# Break conditions (aka. stop the loop)
- condition: template
value_template: "{{ is_state(sensor_entity, alert_state)}}"
- condition: template
value_template: "{{ dismiss_entity == None or is_state(dismiss_entity, 'on') }}"
- choose:
- conditions: "{{ not group_target }}"
sequence:
# Notification Actions
- domain: mobile_app
type: notify
device_id: !input notify_device
# Bug: Expressions defined in the notify_message are not resolved within the scope of the sequence
message: !input notify_message
- choose:
- conditions: "{{ alert_action is defined and alert_action|length > 0 }}"
sequence: !input alert_action
- conditions: "{{ group_target is defined }}"
sequence:
- service: "notify.{{ group_target }}"
data:
message: !input notify_message
- choose:
- conditions: "{{ alert_action is defined and alert_action|length > 0 }}"
sequence: !input alert_action
# Wait
- wait_for_trigger:
- platform: template
value_template: "{{ not is_state(sensor_entity, alert_state)}}"
- platform: template
value_template: "{{ dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
timeout:
minutes: !input repeat_delay
# Repeat finished
- choose:
# If Alert was dismissed
- conditions: "{{ send_notification and dismiss_entity != None and not is_state(dismiss_entity, 'on') }}"
sequence:
- service: system_log.write
data:
message: "Alert {{ entity_name }} dismissed"
level: warning
# If Alert was resolved
- conditions: "{{ send_notification and not is_state(sensor_entity, alert_state) }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- domain: mobile_app
type: notify
device_id: !input notify_device
message: !input resolved_message
- choose:
- conditions: "{{ resolved_action is defined and resolved_action|length > 0 }}"
sequence: !input resolved_action
- conditions: "{{ group_target is defined }}"
sequence:
- service: "notify.{{ group_target }}"
data:
message: !input resolved_message
- choose:
- conditions: "{{ resolved_action is defined and resolved_action|length > 0 }}"
sequence: !input resolved_action
- choose:
- conditions: "{{ dismiss_entity != None }}"
sequence:
- service: input_boolean.turn_off
data:
entity_id: !input dismiss_entity
Thank you very much @pavax, I discover yesterday the great alert integration and today your blueprints that make it much more easier to use, great work !
Thanks @pavax for this nice blueprints.
Two ideas:
allow to set a “clickAction”. Use case: gate open, when you click on the notification you can go directly to the according dashboard. The freezer is open, you receive the notification and you go directly to the dashboard with camara on the kichen
Allow also notificacions on google home (text to speach)
I’ve seen that I can actually make a text to speach notification by using the “Alert Action”. In my use case I would like a different timeout for the “Alert Action” and the notification (for eg, first notify on speakers and later on cellphone).
@pavax thank you for your work, out of 4-5 similar blueprints, this was the one that I understood and could implement, thank you!
But I just spent 3 hours trying this… please can anyone help?
Besides the notifications, I also have a light that flashes red until you close the door. But, I’ve tried remembering and restoring the state of the light after flashing, but I can’t do that. So I tried a more simpler approach, I want to make 2 similar automations, one for when the light is on, and one for when light is off, buuuut I’ve tried so many options using the ConditionEntity and ConditionEntityState, but nothing seems to work, any ideas?
Just found this as I’ve been trying to figure out alerts for my garage door open. MANY THANKS ! I’m looking how to cancel this remotely via the HA app on my iPhone. I’m not familiar with the input_Boolean.
Has anyone else seen a Template Variable Warning in the logs from this blueprint when using the default notification messages? If so, have you found a solution? It seems like inputting my own message that doesn’t dynamically insert the entity name solves it, but I haven’t yet found how to make it more versatile.
Logger: homeassistant.helpers.template
Source: helpers/template.py:157
First occurred: 13:52:44 (48 occurrences)
Last logged: 19:53:56
Template variable warning: ‘entity_name’ is undefined when rendering ‘Alert {{ entity_name }} triggered’
Template variable warning: ‘entity_name’ is undefined when rendering ‘Alert {{ entity_name }} resolved’
Just found this blue print after leaving a garage door open all night. At the moment just have a simple, if open for 5 mins close. Because 99% of the time it opened to get the car out only.
I like the idea of a nagging alert. I also had been playing with actionable notifications. Is it possible to combine the two?
Alert me every 60 seconds say, with an alert that gives the user the option to close the door?
Can someone please explain how to use the dismiss_entity properly? I was thinking it would allow one to silence the notification tempoarily or something, but I’m not clear on what the proper setup would look like to accomplish this with this blueprint.