I want the trigger to be when I leave a specific zone (zone.zona_alarme) and not when the state is “not_home”
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
That’s fine. Change tom_l 's example to have from: zona_alarme
instead of to: not_home
and I get rid of the event: leave
which I believe is a typo.
alias: Alarme auto-on
description: ''
trigger:
- platform: state
entity_id: device_tracker.iphone1
for:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
from: zone.zona_alarme
- platform: state
entity_id: device_tracker.iphone2
for:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
from: zone.zona_alarme
condition:
- condition: state
entity_id: device_tracker.iphone1
state: not_home
- condition: state
entity_id: device_tracker.iphone2
state: not_home
action:
- service: switch.turn_on
target:
entity_id: switch.alarme_418
mode: single
I’ve tried it and it didn’t work.
Shouldn’t I give the “leave” indication somewhere?
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.”
Good spot! I overlooked that.
Yup Home Assistant is looking for actual text in the platform state trigger.
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
Yes it is. Sorry.
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!
action:
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- condition: not
conditions:
- condition: zone
entity_id: device_tracker.a
zone: zone.zona_alarme
That way, if I re-enter the zone during the 30 second period, is the action cancelled?
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:”
Yes. If a condition “fails,” the automation just stops dead. You should add a not condition for both device tracker a and device tracker b (assuming you want the automation only to fire if no one is in zona_alarme). If you want it to fire when both of you are in zona_alarme, and just one leaves, you would use a “not” condition with an “or” condition.
Edit: I don’t think the script does anything for you. Scripts are just the action portion of an automation. I typically use them if I want to use the same sequence with multiple automations, or want a button to fire the automation manually as I see fit.
i want the action to activate when the two are out for 30 seconds (zone.zona_alarme). if the time does not reach 30 seconds, the action is not activated.
this is automation:
alias: Alarme auto-on
description: ''
trigger:
- platform: zone
entity_id: device_tracker.iphone1
zone: zone.zona_alarme
event: leave
- platform: zone
entity_id: device_tracker.iphone2
zone: zone.zona_alarme
event: leave
condition:
- condition: state
entity_id: device_tracker.iphone1
state: not_home
- condition: state
entity_id: device_tracker.iphone2
state: not_home
action:
- service: switch.turn_on
target:
entity_id: switch.alarme_418
mode: single
can you paste what your complete example looks like for me to try it out, please?
alias: Alarme auto-on
description: ''
trigger:
- platform: zone
entity_id: device_tracker.iphone_11_tr
zone: zone.zona_alarme
event: leave
- platform: zone
entity_id: device_tracker.iphone_ana
zone: zone.zona_alarme
event: leave
condition:
- condition: state
entity_id: device_tracker.iphone_11_tr
state: not_home
- condition: state
entity_id: device_tracker.iphone_ana
state: not_home
action:
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- condition: not
conditions:
- condition: or
conditions:
- condition: zone
entity_id: device_tracker.a
zone: zone.zona_alarme
- condition: zone
entity_id: device_tracker.b
zone: zone.zona_alarme
- service: switch.turn_on
target:
entity_id: switch.alarme_418
mode: single
This will “cancel out” if either one of you is still in zona_alarme.
EDIT: You have to change out the dummy device trackers a and b for the real ones in my example of course.
When either of the two are out or when both are out (for 30 seconds)?
when both are out for 30 seconds
thank you… I’ll try it soon
it works perfectly!
I’m going to study this automation…. i’m more used to the reactor plugin from my vera home.… that I like a lot.
thank you all!
Finally! That one was way harder than I expected.
I’m glad that it worked out. Some automations with much more complex logic than that are easier to figure out.