Hi,
I put a window sensor on my cat flap. In order to know whether the cats go in or out, I created an automation which checks whether motion sensors placed in front of my flatdoor have been triggered right before the cat flap was activated or not.
However, I realized when both of my cats go outside right after another, the first cat triggers the motion sensors, so the second cat is marked as going in. To fix this, I created an additional condition which also checks whether the cat flap has been activated between 1 and 20 seconds beforehand (I did not want to start with 0 seconds as I was not sure whether the current activation would also count here). I tried two possible templates which both generally work.
One checks whether the sensor has been triggered:
{{ (as_timestamp(now()) - as_timestamp(states.binary_sensor.katzenklappensensor_contact.last_changed)) < 20 and (as_timestamp(now()) - as_timestamp(states.binary_sensor.katzenklappensensor_contact.last_changed)) > 1 }}
The other checks whether the automation has been tiggered:
{{ (as_timestamp(now()) -
as_timestamp(state_attr("automation.catcounter_automation",
"last_triggered")) < 20) and (as_timestamp(now()) -
as_timestamp(state_attr("automation.catcounter_automation",
"last_triggered")) > 1) }}
Either both of them work as expected when clicking on âtestâ (a cat flap activation between 1 and 20 seconds leads to the condition being true). However, when I put one of them to use in the automation, the second cat flap activation leads to the result âfalseâ (which then becomes true, because I negated it on purpose). Which I do not understand. Am I dumb? Help would be appreciated a lot. Thanks!
Here is my full condition list:
if:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.wohnungstur_bewegungsmelder_occupancy
state: 'on'
- condition: state
entity_id: camera.motion_frontend
state: recording
- condition: not
conditions:
- condition: template
value_template: >-
{{ (as_timestamp(now()) -
as_timestamp(states.binary_sensor.katzenklappensensor_contact.last_changed))
< 20 and (as_timestamp(now()) -
as_timestamp(states.binary_sensor.katzenklappensensor_contact.last_changed))
> 2 }}
enabled: true
This is the tracing output:
if/condition/1
Executed: December 9, 2022 at 23:51:18
Result:result: true
if/condition/1/conditions/0
Executed: December 9, 2022 at 23:51:18
Result:result: false entities: - binary_sensor.katzenklappensensor_contact