ESPHOME Temperature Sensor Notifications

Just getting started with Home Assistant and I have things working but not 100% how I would like them to work.

I have 12 Temperature\Humidity Sensors using ESP32 and DHT22 setup with ESPHome.

My goal is to have alerts if the temp goes too high and would like that to repeat every day until corrected. Another alert once temp drops below the high temp with just a single notification.

An online/offline alert that is similar to above that an alert when it goes offline that repeats daily until fixed and a single alert that it’s back online.

All triggers would require a change that stayed the same for 10 minutes to eliminate false notifications. Specifically for the online/offline alerts as some of these sensors are connected over VPN.

So far I have 4 automations trying to achieve this. It’s kinda working but I get random alerts that a sensor is back online without getting one that said it went offline. As well as random alerts that the temp is back to normal but I didn’t get one that said it was high.

I do however get one if I unplug for 10 minutes or heat the sensor up, and get one that it has reconnected or returned to normal. So not sure why the random ones happen.

Attaching config for the 4 alerts.

Thanks

alias: Temperature is back to normal
description: ''
triggers:
  - entity_id:
      - sensor.home_test_1_temperature
      - sensor.home_test_2_temperature
    for:
      hours: 0
      minutes: 10
      seconds: 0
    below: 74.9
    trigger: numeric_state
conditions: []
actions:
  - data:
      title: Temperature has returned to normal at {{ area_name(trigger.entity_id) }}
      message: |
        {{ trigger.to_state.name }} is currently {{trigger.to_state.state }}F.
    action: notify.persistent_notification
  - device_id: 616ce30e32bb2a988ad7d543b1c0eafd
    domain: mobile_app
    type: notify
    message: '{{ trigger.to_state.name }} is currently {{trigger.to_state.state }}F.'
    title: Temperature has returned to normal at {{ area_name(trigger.entity_id) }}
mode: single

alias: High Temperature Alert
description: ""
triggers:
  - entity_id:
      - sensor.home_test_1_temperature
      - sensor.home_test_2_temperature
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: 75
    trigger: numeric_state
conditions: []
actions:
  - data:
      title: High Temperature Alert at {{ area_name(trigger.entity_id) }}
      message: |
        {{ trigger.to_state.name }} is currently {{trigger.to_state.state }}F.
    action: notify.persistent_notification
  - device_id: 616ce30e32bb2a988ad7d543b1c0eafd
    domain: mobile_app
    type: notify
    message: "{{ trigger.to_state.name }} is currently {{trigger.to_state.state }}F."
    title: High Temperature Alert at {{ area_name(trigger.entity_id) }}
mode: single

alias: Device Offline Alert
description: ""
triggers:
  - alias: When entities go offline
    entity_id:
      - sensor.home_test_1_temperature
      - sensor.home_test_2_temperature
    to: unavailable
    id: Devices Offline
    for:
      hours: 0
      minutes: 10
      seconds: 0
    trigger: state
conditions: []
actions:
  - data:
      title: Device Offline at {{ area_name(trigger.entity_id) }}
      message: |
        {{ trigger.to_state.name }} is currently Offline.
    action: notify.persistent_notification
  - device_id: 616ce30e32bb2a988ad7d543b1c0eafd
    domain: mobile_app
    type: notify
    message: "{{ trigger.to_state.name }} is currently Offline."
    title: Device Offline at {{ area_name(trigger.entity_id) }}
mode: single
alias: Device Online Alert
description: ""
triggers:
  - alias: When entities go online
    entity_id:
      - sensor.home_test_1_temperature
      - sensor.home_test_2_temperature
    from: unavailable
    id: Devices Offline
    for:
      hours: 0
      minutes: 10
      seconds: 0
    trigger: state
conditions: []
actions:
  - data:
      title: Device Online at {{ area_name(trigger.entity_id) }}
      message: |
        {{ trigger.to_state.name }} is currently Online.
    action: notify.persistent_notification
  - device_id: 616ce30e32bb2a988ad7d543b1c0eafd
    domain: mobile_app
    type: notify
    message: " {{ trigger.to_state.name }} is currently Online."
    title: Device Online at {{ area_name(trigger.entity_id) }}
mode: single

You’re probably getting “false” online notifications because your device went offline for less than 10 minutes. When that happens, you don’t get a notification when a device is offline because that automation is cancelled if the device comes back on in less than 10 minutes. The state of the device was still set to unavailable, so when it does come back the automation to alert you that a device came online is triggered.

The way you have things setup, it’s going to be difficult to add the “and have it repeat daily until it’s fixed” logic. You could add a timed trigger and then a condition that requires at least one of the sensors to be above the temperature, but at that point you trigger entity is time and not an entity, so none of the other trigger stuff will work in the actions.

If you’re OK with a notification that says something generic, you could just make another automation that triggers daily, checks all the temps, and they tells you the previous problem still existed. That would be the easiest thing (and account for a day more than one of the sensors is showing above the threshold temp).

Thanks for the info I think I get the additional automation to run daily to see if anything requires sending a notification.

Upon further reading it seems adding an input_boolean to be set to on when a sensor is offline and then check that input_boolean is on before an online notification is sent and then set it to off.

Since the automations will have currently 12 entities, I would think I would need that many input_boolean helpers. Not sure how I can trigger a specific one from one automation or do I need to create individual automations for each entity?

Thanks

You can use a little trick to have one automation do something to the right input boolean, but you have to name the input boolean the same as the entity. So sensor.outdoor needs a corresponding input_boolean.outdoor. With that you can do something like this:

  trigger:
  - platform: state
    entity_id:
    - sensor.outdoor
    - sensor.another_room
    to: 'unavailable'
  condition: []
  action:
    - data: {}
      target:
        entity_id: input_boolean.{{trigger.to_state.entity_id[7:]}}
      action: input_boolean.turn_on

The [7:] takes the array of characters (which is what a string is) and gives you back everything from position 7 (remember that 0 is the first position) to the end. It basically gives you back the entity name without sensor..