Issue with Multiple Alerts

I have an issue which seems to be related to the layout/formatting of my code, but I’ve been unable to find an answer or get it to work.

I’m creating a number of alerts to replace automations with notifications. I put an include line in my configuration file, and created alerts.yaml to house my alerts. The problem is that only the first alert works. The other 2 alerts do not work, even though the sensors are in a state where they should. There are no errors… it’s just like they aren’t there.

Would greatly appreciate some help figuring out why the second and third alerts don’t work. Thank you!

######## Alerts
freezer_high_temp:
  name: "Freezer temp is too high"
  title: Freezer temp is too high!
  message: Current temp of {{ states("sensor.freezer_temp_temperature") }} is above the max of 12.
  done_message: clear_notification
  entity_id: sensor.freezertemphigh
  state: "on"
  repeat: 30
  skip_first: true
  data:
    tag: freezer_high_temp
    push:
      sound:
        name: default
        critical: 1
        volume: 0.25
  notifiers:
    - brian
mini_fridge_high_temp:
  name: "Mini-fridge temp is too high"
  title: Mini-fridge temp is too high!
  message: Current temp of {{ states("sensor.mini_fridge_temp_temperature") }} is above the max of 40.
  done_message: clear_notification
  entity_id: sensor.minifridgehigh
  state: "on"
  repeat: 30
  skip_first: true
  data:
    tag: mini_fridge_high_temp
    push:
      sound:
        name: default
        critical: 1
        volume: 0.25
    notifiers:
      - brian
mini_fridge_low_temp:
  name: "Mini-fridge temp is too low"
  title: Mini-fridge temp is too low!
  message: Current temp of {{ states("sensor.mini_fridge_temp_temperature") }} is below 34.
  done_message: clear_notification
  entity_id: sensor.minifridgelow
  state: "on"
  repeat: 30
  skip_first: true
  data:
    tag: mini_fridge_low_temp
    push:
      sound:
        name: default
        critical: 1
        volume: 0.25
    notifiers:
      - brian

Are they defined?

Yes. The alerts and sensors all show up.

and the alert triggers work (turn to on when sensor meets criteria).

But only the first alert works. The other two do nothing, even though the code is identical for the alert. I’m at a loss, though the fact that you pointed out that the alerts are defined now makes me think that the formatting is fine.

Are you sure your sensors driving the alerts are not binary_sensors?

  entity_id: sensor.freezertemphigh
  state: "on"

  entity_id: sensor.minifridgehigh
  state: "on"

  entity_id: sensor.minifridgelow
  state: "on"

If they’re not, they probably should be…

Interestingly, I tried moving the order of the alerts around, and it makes no difference. Only ‘freezer_high_temp’ works, no matter the order of the three alerts.

I defined the sensors based on an example I found:

    freezertemphigh:
      entity_id: sensor.freezer_temp_temperature
      value_template: >
        {% set freezer_temp = states('sensor.freezer_temp_temperature') %}
        {% if is_number(freezer_temp) and freezer_temp | float > 12 %}
          on
        {% else %}
          off
        {% endif %}
    minifridgehigh:
      entity_id: sensor.mini_fridge_temp_temperature
      value_template: >
        {% set mini_fridge_high_temp = states('sensor.mini_fridge_temp_temperature') %}
        {% if is_number(mini_fridge_high_temp) and mini_fridge_high_temp | float > 40 %}
          on
        {% else %}
          off
        {% endif %}
    minifridgelow:
      entity_id: sensor.mini_fridge_temp_temperature
      value_template: >
        {% set mini_fridge_low_temp = states('sensor.mini_fridge_temp_temperature') %}
        {% if is_number(mini_fridge_low_temp) and mini_fridge_low_temp | float < 34 %}
          on
        {% else %}
          off
        {% endif %}

This may not be the best way to define the sensors (and I’d appreciate any feedback), but the sensors do work. Only the two alerts don’t actually work (they reflect ‘on’ when I manipulate the sensor value as expected… the alert just never goes to my devices.

Poor practice and very old configuration, “pre-loading” the entities used in the templates. Define them as template binary sensors:

template:
  - binary_sensor:
      - name: "freezertemphigh"
        state: "{{ states('sensor.freezer_temp_temperature')|float(0) > 12 }}"
      - name: "minifridgehigh"
        state: "{{ states('sensor.mini_fridge_temp_temperature')|float(0) > 40 }}"
      - name: "minifridgelow"
        state: "{{ states('sensor.mini_fridge_temp_temperature')|float(40) < 34 }}"

You can do this in the UI now, under Helpers:

Are there any errors or warnings in your logs? If the rest of your config is this ancient, there may be other problems lurking.

Thank you! So, I assume that defining them that way, would I put them in the templates.yaml file?

I did figure the issue out after re-reading the alerts documentation… it was an indentation issue after all…

Moving ‘notifiers’ back made the other two alerts work immediately.

Thanks for the help!

1 Like

Yes, minus the template: line which is presumably in your configuration.yaml as:

template: !include templates.yaml

You’ll obviously need to update the alerts with the new binary_sensor entities.

Great! I will make the change and update. Thanks again!