Currently the alert component only allows for the same basic preset message to be sent to a list of targets at specific intervals, without payload or other type of customization possible.
Here are a few use case I’d like to see alert support:
- Ability to add other notification data to the service call, such as a tag and/or actions for html5. These would be alert specific which means the notify.group workaround suggested in the documentation doesn’t apply (or at least isn’t easily doable).
E.g. the object_id of the alert could be set as the tag, so that a dismiss callback action can be taken directly from the notification to turn_off the alert. - Ability to notify only once (or never, or a finite amount of times). For example I might want to get a couple phone calls, but stop after that. This could be indicated by a value of
0
as the last entry of therepeat
list. - Support templating for the notification data, in particular message. This would allow people to for example include information such as the amount of time the alert has been ongoing, or the value that originally triggered the alert (e.g. battery level or sensor’s temperature). This has been suggested before.
- Conditions for the notifications. This has been suggested before, and usually discarded with the workaround of including the condition inside the alert trigger. However this isn’t quite correct and doesn’t always work.
The advantage of an alert is that it can be acknowledged and turned off until turned back on or when the condition occurs again. Folding the “notification condition” into the trigger will cause the alert to behave like if it “forgot” it was turned off even though the relevant condition didn’t change.
It might be easier to picture with an example: let’s imagine a fictional “beep” alert for a low battery on a sensor. I only want this beep to happen if someone is present. I also want to disable the beep once I know about it. If I include the presence test with the battery level test as a trigger, the alert will start beeping again as soon as I leave and come back, even though the battery level has stayed low.
Such conditions could also be used to support dynamic repeat interval, by basically setting a low repeat interval and preventing the notification if the conditions aren’t right. - Last but not least, customization of all the above for each notification target. The idea is that a single alert needs to provide the information differently for each notification channel. This could probably be accomplished with a clever combination of multiple alerts and groups to toggle and present them together, but why not support this natively.
Also, we may want to have a different list of notifiers (or at least different payload data) for the done notification (e.g. to dismiss the html5 notifications when that’s supported)
An example of all those things combined would be: I want to send an html5 notification every minute (so that it stays active until the alert is turned off) containing up to date information about the trigger (e.g. battery level or temperature), play an audio message on the speakers every 10 minutes if people are present (the message might be formulated differently than the push notification), place a call after 10 and 30 minutes if no-one is present.
A possible configuration would look like:
garage_door:
name: Garage Door Alert
entity_id: binary_sensor.garage_door
notifiers:
- service: html5
repeat: 1
data:
title: "Garage Door Open"
data:
tag: "garage_door"
actions:
- action: acknowledge
title: Dismiss
- action: close
title: Close door
data_template:
message: "Garage door has been open for {{ relative_time(state.binary_sensor.garage_door.last_changed) }}"
- service: google_assistant
repeat: 10
skip_first: True
condition:
- condition: state
entity_id: group.all_presence_devices
state: home
data_template:
message: "Warning! Garage door has been open for {{ relative_time(state.binary_sensor.garage_door.last_changed) }}."
- service: twillio
repeat:
- 10
- 30
- 0
skip_first: True
condition:
- condition: state
entity_id: device_tracker.phone
state: not_home
data:
target:
- "+12135550123"
data_template:
message: "This is a warning from Home Assistant! The garage door has been open for {{ relative_time(state.binary_sensor.garage_door.last_changed) }}."
done_notifiers:
- service: html5
data:
title: "Garage Door Open"
message: "Garage door is now closed"
dismiss: True
data:
tag: "garage_door"