High sensor notification to take manual action - e.g. for CO2 & PM2.5

Having several ESPhome nodes with sensors, I wanted to use HA to notify me when sensor values er increased. This is especially useful for values which cannot be automated and require human intervention (e.g. CO2, PM2.5/PM10 for ventilation or in worst case evacuation ;)).

Thanks for help to @finity, @123 and @pedolsky for help :slight_smile: (see here and here).

Goal

  • Get notification of any sensor above configurable threshold
  • Get regular reminder of high value
  • Get reminder when sensor is below configured threshold again

Example


Example of automation trigger with 1000ppm high and 900ppm safe level

Blueprint
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Implementation

The blueprint allows selection of the sensor to watch, and high and safe thresholds. The automation is triggered when the sensor crosses the high threshold (numeric_state on trigger_level_high). Until the sensor is below the safe threshold (via wait_for_trigger with numeric_state on trigger_level_low), an hourly notification is sent. With each notification the actual sensor value is sent.

Source

blueprint:
  name: High sensor value notification
  description: Notify users of high sensor values (e.g. CO2, temp, PM2.5), and again when value drops below acceptable level
  domain: automation
  input:
    trigger_sensor:
      name: Trigger sensor
      description: E.g. CO2, PM2.5, temperature
      selector:
        entity:
          domain: sensor
    trigger_level_high:
      name: Trigger level high
      description: Notify above this level
      selector:
        number:
          mode: box
          min: -50
          max: 1250
    trigger_level_low:
      name: Trigger level low
      description: Notify again below this level
      selector:
        number:
          mode: box
          min: -50
          max: 1250

alias: High sensor value notification+
description: Notify when high sensor values are detected somewhere
trigger:
  - platform: numeric_state
    entity_id: !input "trigger_sensor"
    above: !input "trigger_level_high"
variables:
  trigger_sensor_var: !input "trigger_sensor"
  trigger_level_high_var: !input "trigger_level_high"
  trigger_level_low_var: !input "trigger_level_low"
condition: []
action:
  - repeat:
      until:
        - condition: numeric_state
          entity_id: !input "trigger_sensor"
          below: !input 'trigger_level_low'
      sequence:
        - service: notify.notify
          data:
            message: >-
              High reading of {{state_attr(trigger_sensor_var, 'friendly_name')}} 
              at {{ states(trigger_sensor_var) }}{{state_attr(trigger_sensor_var, 'unit_of_measurement')  }}
        - wait_for_trigger:
            - platform: numeric_state
              entity_id: !input "trigger_sensor"
              below: !input 'trigger_level_low'
          timeout:
            minutes: 60
          continue_on_timeout: false
        - service: notify.notify
          data:
            message: >-
              Reading of {{state_attr(trigger_sensor_var, 'friendly_name')}} back to normal
              at {{ states(trigger_sensor_var) }}{{state_attr(trigger_sensor_var, 'unit_of_measurement')  }}
mode: single
4 Likes

This blueprint has been really useful for my freezer sensors, but Iā€™m trying to add a water level alert which would require a decimal place (height in meters)

Is there any easy way to make this work with say 3 decimal places?

Thanks!