I would like to create a template binary sensor that is on when a camera’s motion sensor entity is ‘on’ AND a light’s entity did not just turn on (or off) within the last 1 second. This is to avoid false triggers when the light turns on. Unfortunately, I am unable to refine the settings in the camera itself to avoid those false triggers. So to create a new binary sensor that simply disregards that brief period when the light last updates seems to be the best path forward.
When I use this code in the developer tools, it works fine. The binary sensor is on only when the camera’s motion sensor entity is on, but not when the light itself just turned on or off within the last second.
{{
is_state('binary_sensor.side_door_camera_motion_0','on') and
now() > states.light.mudroom_light.last_changed + timedelta( seconds = 1)
}}
but when I use this in a template sensor, it does not work. I think it may have something to do with the way now() works when a template sensor triggers. But I can’t figure it out. Here is the template sensor I have tried:
template:
- binary_sensor:
- name: Side Door Camera Motion Human
state: >-
# ignore camera motion when mudroom light is turned off or on
{{
is_state('binary_sensor.side_door_camera_motion_0','on') and
now() > states.light.mudroom_light.last_changed + timedelta( seconds = 1 )
}}
I’ve played around with using a trigger based sensor, but I can’t make anything work. Any thoughts?