Monitor multiple temps with alert all in one Automation?

I have 3 temperature sensors in freezers that I want to monitor in case something goes wrong. I’d like to check them once an hour and if any one of the sensors is warmer than -10C or unavailable then I want an email alert telling me which one(s) caused the alert.

I’ve found a few examples but they are a few years old and don’t seem to work for me…

Hopefully someone could help me out?

alias: Email Freezer Temps YAML
description: ""
trigger:
  - platform: time_pattern
    minutes: "00"
condition:
  - condition: numeric_state
    entity_id: sensor.ibs_th2_p01b_09a6_temperature
    above: -10
  - condition: numeric_state
    entity_id: sensor.ibs_th2_p01b_06c1_temperature
    above: -10
  - condition: numeric_state
    entity_id: sensor.ibs_th2_p01b_15b8_temperature
    above: -10
action:
  - service: notify.o365_email_o365tommy
    metadata: {}
    data:
      message: Freezer Test
      data: >-
        The {{ trigger.to_state.name }} is too warm or not available.
mode: single

Is this a ChatGPT special?

HA Docs - Automation Triggers - Time Pattern

But I don’t actually think that is really what you want… because the rest of the automation doesn’t make sense.

Even after fixing the extra 0, the automation:

  1. Will run at the top of every hour…
  2. If, and only if, all three sensors are above -10…
  3. Then, it won’t do anything because there is an internally invalid template string as a value for a configuration key that requires a dictionary. O365 custom integration docs.

Please clarify what your goal is so we can help you reach it.

1 Like

Your starting point is wrong, and you are kind of answering your own question here:

Monitor multiple temps with alert all in one Automation?

This actually translates as:
“Use multiple triggers to check the temperature “

Why bring in checking once every hour??

You should end up with 3 triggers checking if the temperature is above -10 and no conditions.

Why? If you forget to shut the door at 12:01, you’ll have an hour of defrosting. Much better to trigger off the live data.

alias: Email Freezer Temps YAML
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.ibs_th2_p01b_09a6_temperature
      - sensor.ibs_th2_p01b_06c1_temperature
      - sensor.ibs_th2_p01b_15b8_temperature
    above: -10
    id: too warm
  - platform: state
    entity_id:
      - sensor.ibs_th2_p01b_09a6_temperature
      - sensor.ibs_th2_p01b_06c1_temperature
      - sensor.ibs_th2_p01b_15b8_temperature
    to:
      - unknown
      - unavailable
    id: not available
action:
  - service: notify.o365_email_o365tommy
    data:
      title: Freezer Test
      message: The {{ trigger.to_state.name }} is {{ trigger.id }}.
mode: single

If you find that this is too lively and triggers e.g. when you’re reloading the freezer with the door open for a few minutes, you can add e.g. for: "00:05:00" to the numeric_state trigger to only fire if the temperature is exceeded for 5 minutes.

2 Likes

Thanks for the replies people. It’s obvious I don’t have much exposure to doing many automations. My normal approach is to find examples in the forums/reddit and go from there and unfortunately in this case this was not even a ChatGPT attempt but my own uneducated initial attempts :slight_smile:

My thought on the “hourly” was that I just didn’t want to be spammed by emails if the conditions are met. But now I do see that having the 3 temperature checks in my “conditions” was also a rookie mistake as all 3 would have to be met.

@Troon thanks for taking the time to put together that example!

1 Like

You can add a condition to “throttle” responses (here, to 3,600s == 1 hour):

condition:
  - "{{ now()|as_timestamp - this.attributes.last_triggered|as_timestamp(0) > 3600 }}"

Cheers @Troon !
Should I be concerned about this warning? I did try and put double quotes around unknown and available like I see in the documentation examples but it doesn’t seem to stick?

I also seem to have some issues when I test the automation manually… Doesn’t like something to do with the o365 email…

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘to_state’

The warning is fine to ignore: the UI is gradually improving but still has gaps versus YAML. You can see from the “title” that it understands the meaning. If it bothers you, you could duplicate it into one trigger for unknown and one for unavailable.

You can’t test automations manually when the trigger variable is used (docs).

1 Like

I’m reading that triggers for a numeric state are for when my freezer temp “crosses” the threshold I set and then will not fire again until it moves out of that threshold and then meets it again.

If that is the case then how does the “for” option work for this trigger? I’m guessing it will only trigger one the temp moves past my threshold and is there for X time and the trigger will not fire again until the freezer goes to it’s expected temp and then crosses the threshold again?

1 Like

for what it is worth here is how I tackled the same issue (have 3 fridges and 1 freezer with sensors inside)

  1. created a group sensor with all four fridge sensors
  2. use the below to identify the name of the fridge/freezer in error - to put that name in my home assistant message
  3. used the below to identify how many fridges may be in error - to use this count in my dashboard. also in my dashboard I can turn the fridge icon red using the group fridge sensor or the ones below.
  4. trigger my alert message on when the group temp is over x or when the count goes above 0.

the one flaw in my approach is I treat the freezer temp the same as fridge temp threshold, 45, in my count over 45 sensor below.
I welcome any suggestions to make this better.

#identify fridge sensors over 45
- platform: template
  sensors:
      fridge_sensor_name:
        friendly_name: "Fridge Temp over 45"
        value_template: >-
          {% if states('sensor.fridge_temperature') | float > 45 %}
              1-Up Fridge
          {% elif states('sensor.garage_fridge_temperature') | float > 45 %}
              2-Garage Fridge
          {% elif states('sensor.garage_freezer_temperature') | float > 15 %}
              3-Garage Freezer
          {% elif states('sensor.down_fridge_temperature') | float > 45 %}
              4-Down Fridge 
          {% else %}
              No Fridges over 45
          {% endif %} 
#counts number of fridge-freezer sensors over 45
- sensor:
    - name: "fridge_count_over_45"
      state: >
          {{ states.sensor
            | selectattr('object_id', 'search', '(fridge_temperature|freezer_temperature)')
            | map(attribute='state')
            | map('float', 0)
            | select('>', 45)
            | list
            | count }}

Wow… i think Troon’s is a lot less complicated :laughing:

But like the tweak to use the count to change the number on dashboard red :wink: