Hey everyone, I just thought I’d share what I got working recently. I created an on-demand script to notify me when my wife is heading home.
A little backstory is my wife and I used to be on iOS devices and used Find My Friends with each other and our friends. That app has a handy feature to trigger a notification the next time a person leaves their current location. So, if my wife is working late it would be nice to know when she finally leaves. I didn’t want a notification every day and every time, just an on-demand way of turning it on. So, I decided to use a script with a wait_template
.
So, first I had to set up the proximity sensors for both our phones. We are already using the gpslogger presence detection, so all I had to do was tell proximity to monitor that location. The default zone it uses to calculate is the “home” zone so I didn’t need to define it here.
proximity:
joe_distance_from_home:
devices:
- device_tracker.joes_pixel_2
tolerance: 100
unit_of_measurement: m
rachel_distance_from_home:
devices:
- device_tracker.rachels_pixel_2
tolerance: 100
unit_of_measurement: m
- I used meters for the unit of measurement so that it would update more frequently. I initially had miles, but it was not updating fast enough to my liking.
- The tolerance I chose was 100. I initially tried to do something large like 500 so that if my wife walks across the campus she works at instead of drives away it wouldn’t trigger a false positive, but it seemed to be too large and didn’t trigger at all. Not sure if that means it went back to “stationary” during her drive home or what.
Next I had to create the script. This took me a while to figure out 1) the syntax to use in the wait_template
and 2) how to actually retrieve the dir_of_travel
. I initially tried using {{ is_state() }}
for the boolean check, but it didn’t seem to work. I went back and forth trying to find examples and other code from google searches, so this is just what I landed on that I know worked; is_state()
may work as well.
rachels_heading_home:
alias: Rachel's heading home
sequence:
- wait_template: "{{ states.proximity.rachel_distance_from_home.attributes.dir_of_travel == 'towards' }}"
timeout: '12:00:00'
continue_on_timeout: false
- data:
message: Rachel is heading home
service: notify.html5_joes_pixel_2
- I have an identical one to notify my wife for my phone, but didn’t paste it as it is mostly redundant.
- I added a 12 hour timeout so the script would fail out if something failed to trigger.
That’s about it. Now there is a little switch in my front end that allows me or my wife to trigger the script and it seems to work great so far. This required me to already have the gpslogger presence detection and html5 notifications set up, but those are already well documented in their respective component pages so no need to paste that config.