After seeing the suggestion made by @Bartem (see next post below), go with that! Significantly simpler than what I proposed!
{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.catflap.last_changed) > 5}}
I’ll leave my original post as-is for anyone wishing to … use a more complicated approach. ![:slightly_smiling_face: :slightly_smiling_face:](https://community.home-assistant.io/images/emoji/twitter/slightly_smiling_face.png?v=9)
If you want to ‘debounce’ a motion sensor (or any other binary_sensor) you basically want a ‘latching’ effect.
The first time the sensor changes to on
, it is considered to be ‘latched’ for a fixed period of time (say 10 seconds). During this latching period, all subsequent state-changes are effectively ignored.
It’s easy to implement this latching effect. You’ll need a timer, input_boolean, and a simple automation.
Timer
Create a timer and set its duration to the amount of time you wish to ‘latch’ the binary_sensor (i.e. after the first state-change to on
, your automation will ignore all subsequent state-changes for X seconds).
timer:
back_door_motion_latch:
duration: '00:00:10'
Input_Boolean
Create an input_boolean. It’s purpose is to simply indicate when latching is in effect. This will be used by your automation (in a condition).
input_boolean:
back_door_motion_latch:
initial: off
Your Automation
The following is your automation, slightly modified. The main differences are:
- a condition to check the state of
input_boolean.back_door_motion_latch
- a service to start the timer
The first time the sensor changes to on
, it turns on input_boolean.back_door_motion_latch
and start timer.back_door_motion_latch
. Add your desired services below them.
The next time the sensor changes to on
(within 10 seconds of the first time), the automation will be triggered but it won’t get past the second condition, so the action won’t be executed.
- alias: 'Your automation'
trigger:
- entity_id: binary_sensor.back_door_motion
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: input_boolean.housekeeper_mode
state: 'off'
- condition: state
entity_id: input_boolean.back_door_motion_latch
state: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.back_door_motion_latch
- service: timer.start
entity_id: timer.back_door_motion_latch
# add the rest of your services
Timer Automation
Create this simple automation. After the timer expires, it turns off input_boolean.back_door_motion_latch
thereby cancelling the latching effect.
- alias: 'Motion Latch timer finished'
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.back_door_motion_latch
action:
- service: input_boolean.turn_off
entity_id: input_boolean.back_door_motion_latch