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.