Hi!
I’m triying to achieve a sensor template to know if a device has not been on a specific state for 3 minutes, but with no luck.
{{ (states.sensor.device.state != 'room1' and ((as_timestamp(now()) - as_timestamp(states.sensor.device.last_changed)) / 60 )| int > 3) }}
1 Like
{{ (not is_state('sensor.device', 'room1')) and
(now() > states.sensor.device.last_changed + timedelta(minutes=3)) }}
EDIT: Removed unnecessary filter as suggested by Taras
2 Likes
123
(Taras)
April 5, 2022, 9:30pm
3
For future reference, when comparing two timezone-aware datetime objects, it’s not necessary to convert either of them to local timezone to ensure a proper comparison.
2 Likes
Working like a charm! Thanks a lot!