I am looking for an advise on the best way(s) to implement and arrival home sensor. Every arrival sensor I was able to find is based on “device_tracker” being detected as “home” and then based on a small timer delay an “action” is being fired.
This really does not work well as a person may take their time to actually “arrive” inside the house while already being detected as “home” by a router or other means. What I would like to have is a sensor that is being set to a temporary state of “arriving” for a small set of time. And then have an automation triggered by two or more conditions. (Say: front door has been opened and the person is “arriving” ).
To me the person really arrives, when they open the front door , not when their tracker was picked up by the router. And the issue is that once tracker is set to “home” it will remain in that state. So when a second person arrives 5 minutes later, the second person is the ONLY one arriving. The person who came 5 mins ago is alreay home… So arrival status does not apply to them any more and arriving script should not be executred for them.
So want i want is this: (sudo code)
WHEN “front door” is OPEN (state of a sensor)
AND “person-A JUST arrived” (state of another sensor)
THEN execture arrival_script
(JUST ARRIVED sensor should be reset asyncronosly by the timer)
I am thinking some sort of binary template sensor would work? But not sure how to make it rest on a timer. ?
Maybe there are other easy solutions here, which I am not aware of.
For the “first person home” piece - put all the device_trackers in a group, and use the status of the group. The group will be home when the first person arrives home, and will remain home as long as any member of the group is home.
Now, the way I’d suggest you tackle it is to use a wait condition. Then you can write something like:
This will run when the first person comes home, it will then wait up to 5 minutes for the sensor sensor.front_door to become open. If that happens within 5 minutes, it’ll run the script script.welcome_home, otherwise the automation will stop.
There are many other ways you could do this. You could have one that runs welcome_home when the front door is opened, and then turns itself off with:
Thank you very much for your ideas! I will look into wait_template idea.
But it seems you have read my post as wanting to do “welcome script” just once for the first person arriving. it is not the case.
My actual use case is “welcome voice greeting on speaker” for each person arriving. script.welcome_home should run for each person arriving home, but not repeat for people who have previously arrived and had their greeting played to them.
If all trackers are put in the group, the state will be “home” once first person arrived.
I also would like the ability to trigger the action by the action of the “door opening” , not tracker changing state to “home”. So that greeting is played exactly at the moment of a person entering the house. But, I think you code will actually do that (play exactly on door opening), even though it is being kicked off by state change in person tracker. But, it would only work for the first person.
I guess I could have separate automations for each person in the house without puting trackers in the group… I will try your sample tonight…
I do similar and use a input_boolean I set to on for each person in the household then they come home; and off when they leave. I also use the status of this boolean to trigger one shot automations like you want.
For example when my son comes home from school it senses is iPhone; turns on a boolean that he is home; runs a script telling him to unpack his backpack (he likes to leave his left over lunch in it…); waits 15 minutes; and then tells him again.
It’s also handy to have a boolean to check to see if someone is home for their unique room automations.
Hi all,
Wanted to share my final solution to my question.
This is what I have done:
created two hidden input_boolen switches for me and my wife dmitry_arriving and eileen_arriving (I use them to set the “arriving” state which is a temporary state that lasts x number of minutes from the moment my tracker says the person is home. I have a separate script : set_arrive_sensor which flips the input_boolean on and then later after a delay turn it off.
created two template sensors which mimic the state of the above input_boolean values. Those are display in HA and they are set to “arriving” when input_boolean above is “on”
created “Arriving Home” automation which has multiple triggers and template based action. Basically, it figures out “who” came home and passes an appropriate input_boolean to the script that actually does the job of turning the “arrival” state on and off
Created two automations for random greeting for me and my wife. I could have created just ONE automation with template again, but I wanted to have different greetings for each person. “Dmitry Arrival Greeting” and ‘Eileen Arrival Greeting’ (If somebody knows how could I use a template here to get different greetings while using ONE automation, please let me know.
Created “arrive_greetings” script which is called from “Dmitry Arrival Greeting” automation.
Created “sonos_say” script, which is called from “arrive_greetings”
What I have now is that
Random greeting which is different for each person, plays when a person opens’ the front door (during the period of time while their state is “arrival”
Because I use “template sensor” for arrival state, I can later modify it to evaluate multiple conditions. At the moment, it just checks the input_boolean , which is trigged by device_tracker (via router). Later I can make it more sophisticated and because it is all async and done separately, it does not complicate the random greeting code.
Enjoy and hopefully this will help somebody else later. I have learned all the tricks I use here and I want to thank this community for being so great!
in input_boolean.yaml
dmitry_arriving:
name: Dmitry Arriving
initial: off
icon: mdi:account-key
eileen_arriving:
name: Eileen Arriving
initial: off
icon: mdi:account-key
- alias: 'Arriving Home'
trigger:
- platform: state
entity_id:
- device_tracker.dmitry
- device_tracker.eileen
from: 'not_home'
to: 'home'
action:
service: script.set_arrive_sensor
data_template:
tracker: >
{% set person = trigger.entity_id.split('.')[1] %}
{{ 'input_boolean.' + person + '_arriving' }}
- alias: 'Dmitry Arrival Greeting'
trigger:
platform: state
entity_id: sensor.living_room_door_entry
to: 'Open'
condition:
- condition: state
entity_id: sensor.dmitry_arriving
state: 'arriving'
action:
service: script.arrive_greetings
data_template:
speech_message: >
{% set person = 'Dimitriy' %}
{{ [
"Welcome back home " + person ,
"The king is back. Welcome " + person,
"Are you drunk? " + person,
"Why took so long daddy? Woof!",
"There he is.." + person,
person + "Life is like a song, you’re back where you belong.",
"Welcome Home!" + person
] | random }}
For a similar situation I am using this automation. When I am detected to be home with the nmap device tracker, I am given a 1 minute grace period. If the door is opened in that time I am greeted with a random message (thanks for the random messages by the way).
- id: auto30
alias: Welcome Home
hide_entity: false
trigger:
platform: state
entity_id: device_tracker.sendorm
from: 'not_home'
to: 'home'
action:
- wait_template: "{{ states.binary_sensor.door_window_sensor_158xxxxxxxx.state == 'on' }}"
timeout: 00:01:00
- delay: 00:00:01
- service: media_player.volume_set
data:
entity_id: media_player.home
volume_level: "0.4"
- service: tts.yandextts_say
data_template:
entity_id: media_player.home
message: >
{% set person = 'Sendorm' %}
{{ [
"Hi" + person + ", welcome",
"Hello" + person,
"Greetings" + person
] | random }}
- service: media_player.volume_set
data:
entity_id: media_player.home
volume_level: "1"
fer sure! I’m gonna see how else I can use this! Right now I’m gonna use it to locate my vacuum after I walk in the front door. Was trying to figure out the best way to do this and this is definitely it. Before I just had it on a 1 minute delay upon arriving home, not very smart haha
Would I be able to change the “group.all_people” to just one tracker, replicate this for me and my partner and then it will work when either of us arrive home?
Stumbled across this thread searching and had to reply here – my son does exactly the same thing and your post gave me an idea on how to make sure he takes it out of his backpack