Tell me if you have heard this one before. Home Assistant doesn’t seem to know where you are when you use your phone as your presence tracker.
We have all been there. Notifications firing that you are home when you are not. Or watching automations, that should happen only after you leave, happen like you are not actually sitting in your house.
Before moving to Home Assistant as my main home automation hub, I relied on Smartthings. Even in Smartthings presence tracking was iffy. This is because I use my phone as my presence tracker. As convenient as it is it has some inherent problems. Like the phone sleeping or the need for wifi to be on. Your phone may not respond to pings if it is sleeping and sometimes people turn off wireless on their phone. And while I don’t have a big need for presence, it sure makes home automation more powerful when your system knows if you are home or not.
So I started using Life360 and man, what a difference. I haven’t dug into why Life360 seems to be so good at location services while not being a drain on my phone’s battery, but I am impressed. In my testing the various device trackers, Life360 continually notifies me that I have left a zone, or entered a zone faster than iCloud, Owntracks, or even nmap. Even when Apple’s own Find Friend’s app can’t get a lock on a family member’s location I can pull up Life360 and see not only where they are but how long they have been there. Add that I have never had a false notification on top of that, and it appears to be a pretty solid solution. The only downside is there is not native connection to Home Assistant.
If you are using smartthings to mqtt bridge then you can stop here. You can just add the presence sensors to the bridge and send that data to mqtt. The details are over on the home assistant forum. I am working on getting away from smartthings completely and don’t really care about battery or actual locations for this particular use case. I simply want to be able to know reliably when someone is at home or if we are all away. So I chose a different path.
In a previous version of this article I used HTTP To MQTT running on my Home Assistant box to act as a middle man in this process for what was probably a “good” reason at the time, but the truth was that was just added complexity. Soon after I wrote this I removed it and never updated the article. Since then I received some questions about the process and replied with the following updated guide. You could even remove the scripts process I am using and update the sensor directly using the API, but you do lose some reusability. Either way, I hope what follows is an easier process.
The solution I came up with uses IFTTT to set a family status MQTT topic to home or away, and then use that topic to fire my automations. I lose some fidelity with this solution in that I don’t know who was the last to leave or arrive, but for most of my presence based automation (at least the big ones) I don’t care. I can still leverage the phones for more specific notifications that I don’t rely on.
If you want to go this route you only ned two things. A Home Assistant instance publicly accessible on the internet (with ssl and api password of course), and Life360. Both can be gotten for free.
Life360 has both a free and a premium plan. The free plan allows you two locations, which for this purpose was perfect. I really just needed one. I setup my home location in Life360, and added my family members to it. Once the app is installed and they are included in your family you are good to go.
The next step is setup a sensor in Home Assistant to hold this new presence. Since I chose to use MQTT to store the value of this sensor I set up the sensor like this:
- platform: mqtt name: “Family Presence” state_topic: “house/family/status”
Next I needed a way to change the sensor value. You could directly update the state of the sensor using the Home Assistant API, but I wanted to use scripts in case I wanted to reuse the update logic in Home Assistant.
I created two scripts. One for when family is home:
family_is_home: sequence: — service: mqtt.publish data: topic: “house/family/status” payload_template: “Home”
And one for when the family is away:
family_is_away: sequence: — service: mqtt.publish data: topic: “house/family/status” payload_template: “Away”
After I had the sensor and knew how I would update them it was time to move to IFTTT and connect the Life360 service to my account.
Then, under My Applets, chose New Applet:
I clicked “this”, chose Life360, and was presented with a choice of triggers. The ones I was interested in were:
I chose “First family member arrives at a specific place” and then was asked to chose which location:
I clicked “Create trigger” and then was taken back to my formula:
I clicked “that”, and this time I chose Webhooks as the service I wanted to use. When using Webhooks as your second service you should only have one option:
Click “Make a web request”, and now it’s time to start building the request.
First step is enter the the url of your Home Assistant Instance. And since in this setup I am using scripts to handle my updates the service I wanted to use was script/turn_on:
After your address you need to configure the method (POST in this case) and the Content Type “application/json”:
Then we need the details of our script that we are calling. In my case this was:
Once you have all that click “save.”
Now you just have to repeat the steps but set it up to trigger when the last person leaves a specific place. And you are all set to enjoy your new found presence in Home Assistant.
So far moving to Life360 as the primary presence tracker for the house appears to have made a big impact on reliability front. Home Assistant knows pretty quickly when we have all left and when we arrive allowing me to leverage Home Assistant as a fully automated security system. And that makes Home Assistant way more powerful.