Binary State False Positive Handling

Hi all, first post! I use Frigate with object recognition to determine, for example, when a car is in my driveway. The binary sensor goes from ‘cleared’ to ‘detected’ when a car is detected in my driveway zone. The problem i have is that, while a car is sitting in my driveway and is generally ‘detected,’ the object recognition sometimes falls below the threshold for probability that the object is, in fact, a car… at this point, the state goes to ‘cleared’ for a brief moment, before going back to ‘detected’.

I have an automation to notify me when a car enters the driveway, but this notification is triggered randomly as it briefly goes to a ‘cleared’ state and back to ‘detected’ when a car is sitting in the driveway. I can set the automation to ensure that the ‘detected’ state lasts at least 5 seconds before triggering, but i don’t see a way to ensure that the automation does not trigger if the ‘cleared’ state was not a false positive ‘cleared’ - for example, I’d like an IF condition that the ‘cleared’ state lasted longer than 5 seconds before the ‘detected’ state can trigger the automation.

in summary: car is sitting in driveway for one hour. ‘Detected’ state for an hour (automation triggered an hour ago). ‘Cleared’ state for one second (false positive object recognition probability hiccup). ‘Detected’ state again… automation triggers again undesirably. Fix: need to ensure ‘Cleared’ state lasted X seconds for automation to run…

Any ideas?

Create a template condition, use this template:

{{ now() - trigger.from_state.last_changed > timedelta(seconds=10) }}

The automation will only continue past this condition if the previous state of the sensor (‘cleared’) had remained in that state for over 10 seconds

that’s awesome, thanks… will test it but it seems to be exactly what i was looking for, thanks again!

Hello,

To address the issue of the automation triggering undesirably due to brief state changes from ‘detected’ to ‘cleared’ and back to ‘detected’, you can use a combination of Home Assistant automation and template sensors to manage the state more effectively. Here’s a step-by-step approach to achieve your goal:

Create a Helper Sensor
First, create a helper sensor to track the duration of the ‘cleared’ state.
Navigate to Configuration > Helpers and click on + Add Helper.
Choose Timer.
Name the timer something like car_cleared_duration.
Modify the Automation to Start the Timer
You’ll need to set up an automation to start the timer when the state changes to ‘cleared’. This will help you track how long the state remains ‘cleared’. alias: Start Timer on Clearedtrigger: - platform: state entity_id: binary_sensor.your_car_detection_sensor from: ‘detected’ to: 'cleared’action: - service: timer.start target: entity_id: timer.car_cleared_duration data: duration: ‘00:00:05’ #%20Set%20duration%20to%205%20seconds%20or%20your%20preferred%20threshold 3. Modify the Automation to Trigger Notification costco ess
Next, adjust the automation to check the duration of the ‘cleared’ state before sending the notification. Here’s an example of how you can structure it: alias: Notify When Car Detected
trigger:

  • platform: state
    entity_id: binary_sensor.your_car_detection_sensor
    to: ‘detected’
    condition:
  • condition: state
    entity_id: timer.car_cleared_duration
    state: ‘idle’
  • condition: template
    value_template: >
    {% set cleared_duration = state_attr(‘timer.car_cleared_duration’, ‘remaining’) %}
    {{ cleared_duration is none or cleared_duration | int > 5 }}
    action:
  • service: notify.notify
    data:
    message: “Car detected in the driveway!”

Hope that helps!