Amadi
(Amadeusz)
March 17, 2023, 3:31pm
1
I know it’s probably the basic thing even but I’m searching the answer for hours and I still dont know why it doesn’t work for me…
The case is deadly simple: I want to prevent automation to trigger if my motion sensor state has changed in last 60 sec or sooner.
My condition:
condition: template
value_template: >
{{ (as_timestamp(now()) - as_timestamp(states.binary_sensor.czujnik_ruchu1_occupancy.last_changed)) > 60 }}
I checked many times, my sensor binary_sensor.czujnik_ruchu1_occupancy
is correcty changing the state from “off” to “on”
Without this condition automation is trigger correctly.
What Im doing wrong ?
123
(Taras)
March 17, 2023, 4:41pm
2
Is your automation using a State Trigger to detect changes to binary_sensor.czujnik_ruchu1_occupancy
? If it does then this Template Condition should do what you want:
condition: template
value_template: >
{{ now() - trigger.from_state.last_changed > timedelta(minutes=1) }}
Amadi
(Amadeusz)
March 17, 2023, 9:23pm
3
I think you forget one bracket but thank you! It works!
condition:
- condition: template
value_template: |
{{ (now() - trigger.from_state.last_changed) > timedelta(minutes=1) }}
123
(Taras)
March 17, 2023, 9:40pm
4
For future reference, it isn’t necessary to enclose the subtraction in parentheses.
The following example demonstrates the result is the same with and without the parentheses.