If I paste this directly into the template editor, it evaluates as true or false exactly as I would expect: it renders as true when the last time motion was detected was less than 180 seconds ago; false otherwise.
I get a binary sensor that evaluates as ‘off’ from the time I restart HA until the first time the hue motion sensor detects motion. Then it stays permanently on.
Likewise, if I use the similar evaluation as a condition (now using <180 because I want the ‘true’ state in reverse for this condition):
presumably you could also use time_pattern and seconds: ‘/30’ if you need it quicker.
but do you need that improved accuracy ?
if you need it to the second you need to trigger a timer on the sensor going dark (for: 180) then action what you want.
Good to know, thanks! I ended up solving my problem by using an input boolean instead of a binary sensor. I had an automation turn the boolean on if the motion sensor remained “off” for a period of time; and another automation turn the boolean off after a one second delay, any time the sensor.
I’m using three minutes because that’s what I always intended, and I don’t know how I managed to think 180 seconds = 3 minutes.
- id: prolonged_stillness
alias: 'Toggle if 3 minutes no motion'
trigger:
- platform: state
entity_id: binary_sensor.hue_motion_sensor_1_motion
to: 'off'
for: '00:03:00'
action:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.recent_motion
- id: reset_motion
alias: 'Switch boolean after motion'
trigger:
- platform: state
entity_id: binary_sensor.hue_motion_sensor_1_motion
to: 'on'
action:
- delay:
seconds: 1
- service: input_boolean.turn_on
data:
entity_id: input_boolean.recent_motion
I’ll see how I go with this, but keep your solution up my sleeve in case I end up liking it better.