I want to create an automation of my garage door based on the presence of me and my wive’s phone.
The think is that when we are both in the same car the automation is triggered twice resulting for the garage door to stay semi opened. I want as a condition for the automation to be triggered only if it was not triggered for the last 10 seconds giving time for the garage door to be opened completely, and it will not triggered again since I use condition that the garage door has to be closed.
It all depends on how it’s currently configured - if you share your current code it’s much easier to come up with suggestions that might work.
- id: ‘1548526381210’
alias: Open Garage Door
trigger:- entity_id: device_tracker.nicolasgooglepixelxl
from: not_home
platform: state
to: home - entity_id: device_tracker.angelaslgv30
from: not_home
platform: state
to: home
condition: - condition: state
entity_id: cover.garage_door
state: closed
action: - alias: ‘’
data:
entity_id: cover.garage_door
service: cover.open_cover
- entity_id: device_tracker.nicolasgooglepixelxl
A bit of a hacky sollution, someone might have a more elegant solution based on a template when the automation was last triggered, but I would do the following.
Create an input_boolean switch called input_boolean.garage_door that defaults to off. As a condition of the automation check that the input_boolean.garage_door is off. Have automation peform multiple actions… First turn input_boolean.garage_door to on. Call the service to open the door. Call a delay for 30 seconds or whatever is appropriate. Then turn off the input_boolean.garage_door.
That should create an interlock that will prevent the service from being called twice.
Just put your 2 phones into a group and use the group as the trigger for the automation. That way if either phone changes to ‘home’, the group will activate the automation. It won’t then get 2 triggers and cause the dramas
id: ‘1548526381210’
alias: Open Garage Door
trigger:
platform: state
entity_id: group.our_phones
from: not_home
to: home
condition:
condition: state
entity_id: cover.garage_door
state: closed
action:
service: cover.open_cover
data:
entity_id: cover.garage_door
Well, I thought of that option as well. But there is a scenario that breaks that logic. If one of the two stays at home while the other leaves then the garage door won’t automatically open for them when they come back home.
This is what I use so when I get an alert that a “key” was used on the front door lock I don’t also get an alert that the door was opened… because obviously if someone unlocks the door they are most likely about to open it… maybe you can make it work for you…
- alias: Front Door Alert
trigger:
- entity_id: binary_sensor.front_door_opened
from: 'off'
platform: state
to: 'on'
condition:
condition: and
conditions:
- condition: template
value_template: "{{(as_timestamp(now()) - (as_timestamp(states.group.key_group.last_changed))>60)}}"
- condition: time
after: '20:00'
before: '9:00'
action:
- alias: frontdooralert
data:
message: Front Door Opened
service: notify.ios_briansiphone
So if a anything in the “key group” has been changed in the last 60seconds… I don’t get the front door alert…
Condition_template
- condition: template
value_template:{%- if (as_timestamp(now()) - as_timestamp(states.switch.sonoff63719.last_changed)
< 60 ) and (as_timestamp(now()) - as_timestamp(states.switch.sonoff51083.last_changed)
< 60 ) %} Garage closed & Alarm armed Verified {%- else %} Error occurred arming {%- endif %}
title: 'Home Arming Notification'
That’s part of an automation but you should be able to adapt it
I forgot I also have an automation with almost the same code as what @Bartem has shown. You could try something like this: (note: you will need to create the group.our_phones)
id: ‘1548526381210’
alias: Open Garage Door
trigger:
platform: state
entity_id: device_tracker.nicolasgooglepixelxl, device_tracker.angelaslgv30
from: not_home
to: home
condition:
- condition: template
value_template: '{{as_timestamp(now()) - as_timestamp(states.group.our_phones.last_changed) < 60 }}'
- condition: state
entity_id: cover.garage_door
state: closed
action:
service: cover.open_cover
data:
entity_id: cover.garage_door
for the record, conditions are automatically ‘and’ so @Bartem , you dont need to code the ‘and’ part in, but I do understand that some people like to anyway. Similarly, I always code my triggers and actions with a ‘-’ and the appropriate indentation as if they are going to be a list, just in case I want to add more later, it just makes adding the extras easier.
Yeah remnants of my very first automation …using the automation editor when I first started with HA was probably my biggest mistake… so much easier just doing it manually now.
For my requirement don’t you need the value_template: '{{as_timestamp(now()) - as_timestamp(states.group.our_phones.last_changed) < 60 }} to be greater than 60 than less than 60?
That is less than 60 seconds. The open side of the symbol is facing the 60, so 60 is greater than the template, ie: the template needs to be less than 60.
Can you please explain to me what you are subtracting at the template part?
It’s looking at the current time and subtracting the time that the group was last changed from that, then seeing if the result is less than 60.
So for example if we are in the same car with my wife and the group changes by my phone at 17:15:15 and then by my wife at 17:15:18 won’t this trigger the automation again since it is under 60 seconds?
I’m pretty sure that’s the concept…to be honest another member on this forum gave that code to me and I don’t yet have a solid grasp on templates
EDIT:
…but now that I re-read it, I get the feeling that the < should be a > …
I don’t actually use the automation that this was created for at the moment so I haven’t tested it for months
Yes but this is not what I want. This is the issue I have in the first place.
The condition should be < 20 but if one is home and the other one just arrived this will not trigger the automation since the state of the group has already changed correct?
Hmmm. I will need to look into this further. Hopefully one of the template guru’s can provide better help than me
Just to let you know the way I have achieved what I want to do
{{ as_timestamp(now()) - as_timestamp(states.automation.open_garage_door.attributes.last_triggered) > 15 }} used this as a condition.
good one. not sure why I didn’t think of that