Presence Detection with Life360 (or OwnTracks if you prefer)


Presence Detection:

One of the most useful, and yet elusive, features of a good Smart Home is location tracking.  For as long as I’ve been involved in the DIY Smart Home community (which admittedly hasn’t been very long), there has been a clamoring among the people in search of the “best” way to incorporate location into our automations.  We want a way to know where our important people are so we can use that information to make fun and useful automations. There have been a lot of contenders in this race. OwnTracks, Nmap, the iOS app, Google Maps, have all been okay, but currently the one I’ve had the best experience with is Life360.

 

For most of the past year or so I’ve been using OwnTracks.  It was good enough, but not perfect. What convinced me to switch from OwnTracks to Life360 was accuracy.  Here’s an example. With Owntracks my location would jump around, when I was not actually moving. But with Life360, it just knows where I am and reports my location in nice solid block.  That makes it infinitely more useful for Automations. Imagine you want an automation that will turn off the lights when you leave the house. If you’re presence detection platform isn’t accurate, you’re going to get frustrated with that automation pretty quickly.  WAF -20 pts. So Accuracy is the most important quality in a presence detection, or location tracking service. And in the few weeks I’ve been using it, Life360 has been plenty accurate.

 

Life360 is an app that’s available on iOS and Android. It’s main purpose is location tracking of family members. It does have some other features, like messaging but I haven’t used any of those. The app is free and the setup is simple.  It does require a phone number, so this isn’t something you can use on a tablet or ipod, it has to be a phone. You sign up with your email and a password. That email and password is what you’re going to use in your Home Assistant configuration to get information from Life360.

 

Once you’ve installed the app and setup your Life360 account we can move on to the Home Assistant setup.  As of right now, in version 0.81.6 of Home Assistant, Life360 is not an official component. That’ll probably change before too long, but for now that means a couple extra steps are required to get it working with Home Assistant. That also means, that there will potentially be future changes to the scripts that make it work. So you may have to repeat this process to get the newest scripts. They won’t automatically update. You been warned. Big thanks to Phil for putting together this custom device tracker for us.  Great work Phil!

 

https://community.home-assistant.io/t/life360-device-tracker-platform/52406

https://github.com/pnbruckner/homeassistant-config

 

Step one is to go to Phil’s github and download it and extract it.  Now you need to move 2 files. They are both called Life360.py, but they are NOT the same.  The first Life360.py file goes in a subfolder of your HA config folder, called “custom_components”. If you don’t already have that folder, just create it, then copy the Life360.py file, from the “custom_component” folder in Phil’s repo to your own custom_components folder.  Next, inside your custom_components folder, make a new folder called “device_tracker”. Copy the other life360.py file from Phil’s device_tracker folder into your new device_tracker folder. Until this becomes an official part of HA, you may need to repeat this process to get the latest features or fixes.  

After moving those two scripts into their new homes, you can open up your configuration.yaml file and add the lines you’ll need for Life360.  There are a lot of optional parts to this configuration. For mine, I’ve kept it minimal. You can play around with the other options once you get the basics up and running.

 

https://github.com/pnbruckner/homeassistant-config/blob/master/docs/life360.md

 

device_tracker:

platform: life360

  username: !secret life360_user

  password: !secret life360_pw

 

The user and password here are the email and password you used when you installed the Life360 app.  When you’ve got this in, save, check the config, and restart HA. When it comes back up you should see yourself as a new badge on the overview page.  It uses the image that you specify in Life360. If you want a different picture, you can change your picture in the Life360 app, or you can go to the Customization page in HA, find your device tracker and change the entity image there.  

 

If you want to add more people it is very simple to do.  The person you want to add needs to install the Life360 app.  But when they do, you just need to add them to your “circle” and their location will show up in your Life360 app and in Home Assistant.  To add someone to your circle you click the button that says “+ add new members”. It’ll show you a code for your family circle. You can either send that code to someone by email or text message, or the person you are inviting can click “join a circle” and then type in the code for your circle.  Once they’ve joined your circle they’ll pop up in HA right away. No need to restart or change the config or anything. That’s cool.

 

Life360 reports a lot of information. Some of which, might be pretty useful. In addition to the usual location information you would expect, it also gives you information about someone’s movement, include how fast they are moving.  When I saw that I could track how fast Mrs Zzs was driving I had to do something with it. So I whipped up this little beauty of an automation. Anytime she goes over 45mph, this is what happens.

 

########## Speeding #############

alias: Slow Down Turbo

  trigger:

    – platform: numeric_state

      entity_id: device_tracker.mom

      value_template: ‘{{ state.attributes.speed }}’

      above: 45

      for:

        minutes: 1

  action:

    – service: notify.ios_janis7

      data:

        title: “Speed Warning”

        message: “Slow Down Turbo!”

        data:

          attachment:

            url: “https://i.imgur.com/WRyZKEO.jpg”

 

It needs some fine tuning, but it works.  To be fair I should set Zones with different speed limits, and set the automation so the speed that triggers the warning is actually above the speed limit in that Zone.  But I’m not interested in being fair. I’m just having some fun.

 

So Life360 is accurate, but not surprisingly, that accuracy costs you some battery life.  I looked in my phone to see how Life360 compared to OwnTracks in battery usage. It’s clear Life360 uses more battery.  But, that isn’t a totally fair comparison. Owntracks has several settings that change how often the location is reported.  I had mine set to “significant changes”. In that mode, small location changes don’t get reported. Less reporting mean less battery usage.  So to be fair, I changed the mode in Owntracks to report every location change. The results were not surprising. Battery usage became about the same. Life360 doesn’t have an option to decrease the frequency of location reporting. At least not that I could find. So, if battery usage is really critical to you then you may want to use OwnTracks instead.  For me, since my phone is old and I’m charging it at least once in the middle of the day anyway, I’ll keep using Life360.

 

Since there are probably some folks who really need to save phone battery capacity, let’s go through the setup for OwnTracks real quick. OwnTracks is also available for iOS or Android. There are two main ways that OwnTracks can report your location to Home Assistant. MQTT or HTTP.  Initially I used MQTT, I followed Bruh Automations video from a couple years ago and it worked fine. The problem with MQTT for OwnTracks is you either have to open up your main MQTT broker to the internet, or you have to set up a second broker. It got scary and complicated so I decided to use the HTTP method instead.  

 

Fair warning, Life360 is much easier to setup than OwnTracks. To use OwnTracks with HTTP you’ll need to have a duckDNS URL setup.  If you haven’t done that, here’s a video: https://youtu.be/VUTPAoB27iQ

When you’re setting up OwnTracks, you select HTTP as the “Mode”. Tracker ID is just some initials that will show up on the Map that identify you.  Turn Authentication on. UserID can be anything you want (I think). This Password is your Home Assistant API password. This may be a problem in the future as Home Assistant is moving away from simple passwords and is using more secure Tokens, but for now your old password that you use to login to Home Assistant is what you use here. I’m not using encryption, so I leave this blank, then you need to put your duckdns url in this last box. Followed by the home assistant port, then /api/owntracks/<name>/<device>

So something like this:

http://blahblah.duckdns.org:8123/api/owntracks/blah/phone

That should be it. The status box will tell you if there’s a problem and hopefully give you some clue how to fix it.  If it says “connecting” then “idle” you’re good. The last thing to set in the App is the reporting frequency. Click the icon In the upper right corner and it will go through the 4 options for reporting frequency, Manual, Quite, Move, and Significant Change.  If you want low battery usage but still want some automatic reporting then use Significant Change.

After that you just need one line in your HA configuration.yaml file:

 

device_tracker:

platform: owntracks_http

 

Save, check config, and restart HA.  With that URL you should have a new device with the entity_id of “device_tracker.blah_phone”.  

 

One last thing to do since we’re talking about Location Tracking is setting up Zones. In your configuration.yaml you make a heading that just says “zones” then list name, long/lat, radius measured in meters, then an icon:

zone:
 – name: School
   latitude: 32.8773367
   longitude: -117.2494053
   radius: 250
   icon: mdi:school

 – name: Work
   latitude: 32.8753367
   longitude: -117.2474053

 

 

https://www.home-assistant.io/components/zone/

You can also break out your zones into a separate yaml file:  Keep it Secret, Keep it Safe.

zone: !include zones.yaml

 

Then in the zones.yaml file you list all your important zones. Remember, anytime you’re breaking part of your configuration.yaml out into a separate file, you need to maintain the spacing as if it were still part of the main config file. So in this case if your zones were in the main config.yaml you would have two spaces before the dash for each zone.  So in Zones.yaml you also start each zone entry with two spaces before the dash for the name. Pro-Tip.

 

Now, to use location in automations you’ll use the state of the tracked device. If you don’t define zones, then you’ll have two possible states for each device you’re tracking “home” and “not_home”. If you have defined zones then the state will be the name of that zone.  Anytime you’re not in a zone the state will be “not_home”. Here are some examples of Automations using Location:

 

alias: DrZzs leaving Work

  trigger:

    – platform: state

      entity_id: device_tracker.drzzs

      from: ‘Work’

      to: ‘not_home’

  action:

    – service: notify.notify

      data:

        message: Daddy just left work, should be home soon

#######

alias: No one home Away Mode On

  trigger:

    – platform: state

      entity_id: device_tracker.mom, device_tracker.drzzs

      to: ‘not_home’

      for:

        hours: 24

  action:

    – service: climate.set_away_mode

      data:

        entity_id: climate.upstairs_ac

        away_mode: ‘on’

 

That’s it.  Hope that helps. Location tracking is fundamental in a useful smart home. I expect there will be more and better ways in the future, but for now, for me, Life360 has become a great solution.  Remember, it’s not stalking if it’s your family.

Social Links

Menu