since a few days I try to create a template within an alert integration to mark the notifications as critical due to dependency.
My goal is to achieve a regular app notification when a door has been opened (this already works properly). But I also want to receive a critical notification when the door is open for longer than X Minutes or when i‘m not at home.
I created a template with a simple logic: if door is open → critcal:1; else → critical: 0
(The duration check will be added later when this is solvable)
But this is not working and it drives me nuts. I tried various things including typecasts to int, use boolean values, different formatting, use the sound: section as a whole as a template but it is never working. I also tried {% if true %} to exclude more possible error influences without any success.
This is my alert shortened to the necessary:
alert:
door_open:
name: "Door open"
entity_id: binary_sensor.front_door
state: "on"
repeat:
- 5
skip_first: false
title: "Front door opened"
message: "Front door was opened"
done_message: "Front door has been closed"
notifiers:
- mobile_app_iphone
data:
push:
sound:
name: "default"
critical: >
{%- if is_state('binary_sensor.front_door', 'on') -%}
{{ int(1) }}
{% else -%}
{{ int(0) }}
{% endif %}
volume: 0.0
Last night, out of sheer frustration, i create a test automation with this template approach that would send a notification and it worked without a problem! (config see below)
It looks to me as if the template is not renderd inside the alert integration. Or I’m missing something.
IMO it should be possible to use differnet sounds like a door closed and door opened voice output which are provided by the companion app.
according to the documentation, templates are not allowed for the data key
(well, it doesn’t explicitly state that they are allowed, like for message and done_message for example)
I stumbled over this one as well. I was just curious because most vales under the data key are borrowed from the semi optimal documented notify integration and in another context (automation) I could manipulate the critical value with a template.
I solved this problem (critical alert vs normal alert) by creating 2 alerts on the same sensor. The sensor is then tri-state (off, day, night). One alert triggers on the day state, the other on the night state.
thank you for your reply.
This is an interesting approach and kind of relieving that I’m not the only one with this problem. But this does not feel right. It’s so unnecessary redundant (not your fault) everything in me strives to do it like this.
What if I want:
different sounds for opening and closing? This makes it three alerts.
critical opening message and non-critical done_messages? This won’t be possible this way. Only if the done_message part is not configured and provided by another alert which would add up to four alerts.
immediate critical notifications when my wife is home alone?
all of the above but with multiple doors? This multiplies the number of alerts
There are so much scenarios which could be handled by a template which sadly is not supported in this case
Yep, I agree I wish it were more flexible. I also wished for different notification channels for trigger and done, but didn’t find any way to implement it. I also wish you could reload the alerts without totally restarting HA.
I’m guessing you would have to rewrite the alert functionality.
as templates are not mentioned as being allowed for that field, it’s not an issue. It is an inconsistency with the service call, but to have it changes you should create a feature request.
However, the alert integration is in a kind of read-only stage and no development is done on the integration.
As soon as all notify integrations are moved to notify entities (like already done for the file integration) it will be easy to create a bleuprint with all functionality of the alert integration, and more flexibility (especially since you now can take over control of a blueprint)
It will be done in a phased approach per integration. File was rather easy as there were not a lot of options, things like mobile app will be more difficult.