I have a CO2 sensor that periodically has a high reading which triggers a notification. What can I add to my code that will only notify if a condition continues for say 5 minutes?
There are a few ways. The most basic is to simply add a for:
key to your trigger so that the sensor has to be in that state (or comparative state) for 5 minutes:
trigger:
- platform: numeric_state
entity_id: sensor.co2
above: 5
for: "00:05:00"
Option 2: Create a state-based Template binary sensor with a delay_on
:
template:
- binary_sensor:
- name: CO2 delayed
delay_on: "00:05:00"
state: >
{{ states('sensor.co2') | float(0) > 5 }}
availability: >
{{ states('sensor.co2') | is_number }}
Option 3: Create a Filter sensor that returns a rolling average of you CO2 sensor, then base your trigger off that sensor.
sensor:
- platform: filter
name: "Filtered CO2"
entity_id: sensor.co2
filters:
- filter: time_simple_moving_average
window_size: "00:05"
precision: 2
Outstanding. Thanks much! Do I need the for: in the trigger and condition area?
trigger:
trigger:
- platform: numeric_state
entity_id: sensor.mh_z19_co2_value
above: 1000
for: "00:05:00"
- platform: homeassistant
event: start
condition:
- condition: numeric_state
entity_id: sensor.mh_z19_co2_value
above: 1000
IIRC, the Numeric state condition does not accept a for
key… for that kind of restart-resiliency you may need to set a timer or input datetime based system.
Ok. Thank you. Ended up using option #3.