I have a binary sensor, specifically that detects the presence of a pet, via Reolink camera. When it detects a pet it often means I get something like 2 or 3 events per minutes. So if the cat/pet is actually on camera for 5 minutes I might get 10-15 events (off-> on for ~seconds). I want to treat this as one single event.
How can I go about doing this? I essentially want an “on” event to not be set to “off” if it sees another “on” event within X minutes.
First, check your device and/or integration to see if it has a a way to change the cool down period.
Otherwise, template binary sensors have a configuration variable delay_off that allows you accomplish that. Note that the advance features are only available through YAML configuration, they are not available through the Helpers menu.
You could use an automation and a toggle helper/input boolean to do basically the same thing by assigning durations to the triggers. But that may be overkill…
Can you clarify what you are trying to do where the frequent detections by the sensor is causing a problem?
I’m trying to count how many times my cats visit the litterbox. So if the cat goes to the litterbox, hangs around and then uses it, 4 minutes might have gone by but I got 10 events. Right now, I have a counter that gets incremented each time there is an event, but I’m getting like 100 events over a few days when the cats really have only visited it a dozen times or so.
Okay, there are a couple way to throttle an automation by using conditions. For this case I would probably use something like the following Template condition:
alias: Check if last state was stable for at least 5 minutes
condition: template
value_template: |
{{ (trigger.to_state.last_changed - trigger.from_state.last_changed)
>= as_timedelta('00:05:00') }}
If you want to go the sensor route you can do something along the lines of this
# configuration.yaml (or split templates file)
template:
- binary_sensor:
- name: Pet Present (debounced)
unique_id: pet_present_debounced
device_class: occupancy
# Replace with your actual pet detection entity:
state: "{{ is_state('binary_sensor.reolink_pet', 'on') }}"
# Hold "on" for X minutes after last detection
delay_off:
minutes: 5 # ← change to your desired X
#This keeps the sensor on until it has been off for the full hold time. Any new “on” within that window resets the timer.