Good afternoon. I wanted to create an automation where the trigger was activated 30 seconds after I or my wife left homes, but I’m having difficulty because of the 30 seconds… I don’t know how to do it.
I currently have no 30 seconds and it looks like this:
alias: Alarme auto-on
description: ''
trigger:
- platform: zone
entity_id: device_tracker.a
zone: zone.zona_alarme
event: leave
- platform: zone
entity_id: device_tracker.b
zone: zone.zona_alarme
event: leave
condition:
- condition: state
entity_id: device_tracker.a
state: not_home
- condition: state
entity_id: device_tracker.b
state: not_home
action:
- service: switch.turn_on
target:
entity_id: switch.alarme_418
mode: single
Solution that @tom_l suggest will ensure, that if you return to home within 30 seconds action won’t be triggered. My proposed solution causes to trigger action after 30 seconds AND every time after leaving home, regrdless returing within 30 seconds or not. Your choice.
Very true, but isn’t it general problem of low frequency of position updates from the app? Regardless of being home or driving I see updates being send sometimes every 1~2 minutes only. In this case problem with cell tower triangulation will persist also for your solution? Or am I missing something? I sit possible to force/configure high enough position update frequency?
My solution requires the location state to be stable for a period of time. Yours just waits a period of time where the state could be wandering all over the place.
Thats my point with low frequency of updates. Even in your case if location suddenly changes based on false triangulation to be out of zone and next update comes in 2 minutes automation will be triggered as well. Indeed, if next update comes within 30 seconds, your method won’t trigger, but mine will.
The solution I want is @tom_l, but the problem is that I want the trigger to be activated after the “device_tracker.a” or “device_tracker.b”, leave from a specific zone (“zone.zona_alarme”), and not when I leave the house
You still have the not_home conditions, which you don’t want if they are not correct. You only need to tell Home Assistant what zone you are leaving (from), because this isn’t a zone trigger it’s a platform state trigger so just like every other state trigger, Home Assistant is only interested in what the state was ( from ) and what the new state is ( to ). Because we don’t know what the new state will be, and it doesn’t matter - only the state that it was previously in ( from ) is important.
I think that it should actually just be from: zona_alarme, not from: zone.zona_alarme. Look at the state history for your device tracker, the state will be the name of the zone without “zone.”
it is not working. the state of “device_tracker.iphone1” and “device_tracker.iphone2” is “home” or “not_home”. I want these entities to work with a zone that I created, so I started using “platform: zone”… but then I can’t use the time factor
This is a relatively simple problem but sometimes those are the toughest ones to get finished.
Go back to your original automation version, with a zone trigger. Add to the action a delay of 30 seconds, and then another action that is a condition that you are not in zone.zona_alarme. This will do the “debouncing” in the way that you desire. For real this time!
I found a post with something that I haven’t tested yet, but I think it might solve my problem… I thought there could be a simpler solution, but I think it’s going to have to be with a “script:”