I am trying to turn on a boolean when I am leaving home for 30 minutes, but I cant figure this out.
This is what I have so far but it is not triggering.
- platform: template
value_template: "{{ (states.device_tracker.mytracker.state != 'home' and ((as_timestamp(now()) - as_timestamp(states.device_tracker.gmytracker.last_changed)) / 60 )| int > 30) }}"
Being ahead, I want to explain that using the simple state trigger cant work:
- platform: state
entity_id: device_tracker.mytracker
to: 'not_home'
for:
minutes: 10
The reason this will not work, is because I can be in less that 10 minutes in another zone. That will not trigger the boolean as the state will not be “not_home” for 30 minutes.
Thats why I am using this template and this argument “!=” so this will limit the trigger for just when the state is NOT home, no matter what the state is…
but couldn’t you do a similar thing only in reverse:
- platform: state
entity_id: device_tracker.mytracker
from: 'home'
for:
minutes: 10
but if that doesn’t work then you will not be able to use as_timestamp(now()) in your template because it doesn’t cause the template to update on a change. you have to use a date/time sensor:
if you notice, I changed the single quotes with double because I use them at the beginning and the end of the template. Could this be a problem?
EDIT:
Forget what I said. It works correctly! I just had to wait one more minute! Thank you very much for the template. I just used 1 minute to test the trigger, but I will go for the real deal now. I think it will still work. I will come back if not. Thank you again!
I’m kind of trying to do the opposite. I want to run an automation after I’ve entered a zone for X minutes. I have a working automation right, now but with 6 triggers, one for each zone. I was going to do
from: not_home
for:
minutes: X
but realized that does not work. Would the template above work the same way if I just changed it like so
Would someone mind deconstructing it? I can never manage to make it be ‘true’ in the template editor, despite the fact marj’s life360sensor has recently updated.