Notify automation/alert template inconsistencies

Hi guys,

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:

  name: "Door open"
  entity_id: binary_sensor.front_door
  state: "on"
    - 5
  skip_first: false
  title: "Front door opened"
  message: "Front door was opened"
  done_message: "Front door has been closed"
    - mobile_app_iphone
        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! :rage: (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.


alias: Test notify template for critical notification
trigger: []
  - service: notify.mobile_app_iphone
      title: Test Message
      message: This is a test message
            name: "default"
            critical: >-
              {% if is_state('binary_sensor.front_door', 'on') %}
              {{ int(1) }}
              {% else %}
              {{ int(0) }}
              {% endif %}
            volume: 0
mode: single

I hope someone has a solution.

Thank you and best!

Not a solution to your issue, but your template can be simplified to:

{{ is_state('binary_sensor.front_door', 'on') | int }}

BTW the logic is reversed in your automation compared to your alert

1 Like

Thank you for the suggestion for improvement :slight_smile:

BTW the logic is reversed in your automation compared to your alert

And also thanks for this hint. I have corrected my post. I tried out various configurations yesterday and played around with different approaches

What is exactly not working? The notification from the alert at all, or only the critical part?

There is another typo in your alert: don_message should be done_message. It could be that the alert is not working because of that.

The problem is the critical part. I receive the notification but it’s not a critical one.

My fault again. I shortened the alert to the necessary and this was a typo. Thank you!

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.

Hi Martin,

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.

I have created a GitHub issue for this:

Maybe you want to give it to thumbs up to raise more attention.

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)

Hi Fes,
that’s interesting that’s for the informations.

Are there any more informations or documentation’s available about this Hugh upcoming change?

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.