Create a Trip Time Sensor and Pickup Reminder in Home Assistant

If you live in the urban area and need to pick up someone regularly, e.g. a family member off work or kid from school, a simple alarm on your smart phone might work out for you but not the best solution. With the help of home assistant, we can make it much smarter by utilizing real-time traffic information and home automation.

Let's look at a use case here:

  • School pickup time @3:00pm every weekday
  • Consider traffic congestion from home to school and adjust accordingly
  • Send out reminder to user on time for school pickup

Due to the increased traffic congestion nowadays, the trip time from home to school varies between 13 to 22 mins. Of course you could always take off early and use the 22 mins as a safe start, however you could save some of your precious time if reminded by the home assistant.

My solution is to automate the reminder using real-time traffic estimate and send out a push notification to phone beforehand. The steps are below:

1. Waze Travel Time integration

First thing is first. We need to install waze travel time integration in home assistant. Head to integration section of home assistant, and add "waze Travel Time" integration with the origin & destination filled, as well as a friendly name. Note the address can be GPS coordinate or street address.

For convenient quick peek of the trip time, a trip time card can also be added to lovelace UI as shown below.

waze travel time integration waze travel time
waze travel time integration waze travel time

2. Custom template sensor for remaining time to take off

The idea is to create a template sensor tracking the remaining time before you have to take off for pick-up. For example, if the real-time travel time is 20 mins and school pickup time is 3:00pm, you will have to leave at 2:40pm. This is usually a theoretical estimation assuming you are already in the car and ready to drive. So a template sensor is created to accommodate more time for preparation time. Note the value of the template is also decreasing upon time elapsing so that it can be used in automation easier.

Let's say current time is 2:35pm and the waze travel time is 15 mins, the following template sensor will evaluate to 5 mins which means you have 10 mins till 3:40pm to prepare for taking off and start driving @ 3:45pm. The 5 mins preparation time can be adjusted to any preferred value.

1   - name: "Time remaining to go to pickup"
2     icon: "mdi:clock"
3     unit_of_measurement: min
4     state: >
5       {{ (14 - now().hour)*60 + (60- now().minute) + 5 - states('sensor.school_pickup_time') | int }}
6     # sensor.school_pickup_time is the waze integration sensor

3. Automation to send a reminder

Once we have the above prerequisites, setting up the automation is super easy. Create a new automation and select the template sensor as entity trigger. Since the remaining time is a numeric value, you can adjust the trigger condition in several ways. My setup is to check the reaming time is between 0 and 3 mins. Conditions are Monday to Friday. The action is send out a notification using the generic service notify.notify with a text message. In my case I am getting a notification on my phone. This could be either a text message or even a phone call depending on your home assistant capability.

automation setup notification
automation notification

Conclusion

Home assistant offers endless potentials to bring convenience to daily life. I have presented a simple solution to remind myself for school pick-up based on real-time traffic info. Some future improvements could be:

  1. Integration with google calendar so the automation observes stat holiday as well as non-school days
  2. Make a custom component so adding a new reminder is easier and less overhead for configurations.
comments powered by Disqus

Translations: