Life 360 support

The way I understand HA’s device tracking is that you need to have the Lat/Lon set in the configuration.yaml file and then when this addon pushes those coordinates HA figures out if your home based on the home lat/lon/radius vs the device lat/lon.

A few things to figure out where things are going wrong:

  • Are you getting data from Life360? ie when the addon starts do you see json objects with correct data
  • Are messages making it to home assistant? You could download an MQTT application such as MQTT lens and subscribe to the topic to see if information is making it to the hub. (Alternatively you could try setting up HTTP in the addon to narrow down where the issue is coming from)

If that doesn’t work let me know :slight_smile:

1 Like

Hi Editter,
Just wanted to say that I’ve just installed your add-on and got it working (with MQTT) without much problems.

Keep up the good work! :+1:

Yes, it seems that I am getting data from Life360 into your add-on… this in the log on your Hassio Add-on

3/9 3:06:59 pm - info: MQTT Message was written to life360/location/Jonathan
3/9 3:06:59 pm - info: MQTT Message was written to life360/location/Katie Beth 

As far as seeing what data is being written, I don’t know how to check that.

I am also using the built-in MQTT Hassio Mosquitto Add-on.

As an aside, I do have the Mosquitto MQTT subscribed successfully to the Smartthings Bridge so I do know that its capable of receiving data, but I’m not sure how to connect your add-on to the Mosquitto MQTT.

Also, I do have Zones configured in my configuration.yaml but I’m not sure how to confirm that the lat and long match up to the place created by Life360.

Thanks for your patience and help.

Also, here’s my current configuration.yaml entry:

device_tracker:
  - platform: mqtt
    devices:
      JP_phone: "life360/location/Jonathan"
  - platform: mqtt
    devices:
      KB_phone: "life360/location/Katie Beth"

Do you have known_devices.yaml setup? I don’t know if case is a problem so maybe change JP_phone => jp_phone (as well as kb).

And I am happy to help. The HomeAssistant community is great and I love that I can contribute in some way :slight_smile:

Yes, here is my known_devices.yaml. I just now changed the case as you suggested to all lower case.

jp_phone:
  track: yes
  hide_if_away: no
  name: "Jonathan"
kb_phone:
  track: yes
  hide_if_away: no
  name: "KB"

Waiting for a restart.

I did wonder, in the configuration.yaml my MQTT setup looks like this:

mqtt:
  broker: core-mosquitto
  discovery: true
  discovery_prefix: smartthings
  username: xxxxxxx
  password: xxxxxxx
  port: 1883
  # client_id: hassio
  keepalive: 60

Does that discovery_prefix for the SmartThings bridge create a problem for me to incorporate Life360 via MQTT?

After restart, still doesn’t seem to be any communication to update the device tracker state.

device_tracker.jp_phone	  not_home	source_type: null
                                    friendly_name: Jonathan
device_tracker.kb_phone	  not_home	source_type: null
                                    friendly_name: KB

I commented out the discovery_prefix: smartthings and restarted. Didn’t seem to have any effect on SmartThings connectivity but also didn’t change Life360.

Oh I think I see it!

device_tracker:
  - platform: mqtt_json <=  you have mqtt not mqtt_json
    devices:

Well, I made the change to platform: mqtt_json, but didn’t seem to resolve things for me. I’m sure I’m missing something simple but I just can’t figure out what.

Hi, trying to use your addon.

Some question, what do I have to put in

“known_devices_name”: “???”

Hi,

I have been using a version of this script for over a year, I migrated the script over to a new machine today (I’m using Home Assistant in VirtualEnv) and for some reason it’s now only showing me members of one circle.

I then updated the script to the newer version by @editter and still getting the same thing, just once circle…

I am a member of 3 circles and members of all 3 used to show.

Does anyone know if something changed recently in the API?

Cheers!

known_devices_name matches to what you have in the known_devices.yaml name.

For the life360 addon how many circles does it show when you first start the addon?

I’m not using HASS.IO so I’m using the modified script your posted here: https://pastebin.com/Jnagdh3V

I’ve been using the original version of that script for over a year but now I’m not getting all member from all circles, only one circle.

This is the print-out, the members are only of one of the circles, I have another circle with 4 other members.

./life360.sh
1521486684 INFO: requesting access token
1521486684 INFO: requesting circles.
1521486685 INFO: requesting members
“Michael”
“Gemma”
“Sue”

It’s stopped working a couple of days ago.

Hi all. New to HA (I’ve been using SmartThings for a while, but am in the process of moving to HA) and, of course, this forum. But after searching around a bit, and reading through this topic, I thought I’d prefer to have a more direct integration that doesn’t rely on MQTT or shell scripts.

I found this: https://github.com/harperreed/life360-python. I know it’s probably not “complete”, and it isn’t a PyPI package, but it was a start. I grabbed a copy and then wrote this Device Tracker platform (which I also named life360.py, hence the renaming of the other script to pylife360.py):

import logging
import voluptuous as vol
from homeassistant.components.device_tracker import (
    PLATFORM_SCHEMA, CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_point_in_utc_time
from homeassistant import util

_LOGGER = logging.getLogger(__name__)
_AUTHORIZATION_TOKEN = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_USERNAME): cv.string,
    vol.Required(CONF_PASSWORD): cv.string
})

def setup_scanner(hass, config, see, discovery_info=None):
    from pylife360 import life360
    try:
        api = life360(_AUTHORIZATION_TOKEN, config[CONF_USERNAME], config[CONF_PASSWORD])
        if api.authenticate():
            circle_id = api.get_circles()[0]['id']
        else:
            raise
    except:
        _LOGGER.error("Life360 authentication failed!")
        return False

    _LOGGER.info("Life360 authentication successful!")
    interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
    Life360Scanner(hass, see, interval, api, circle_id)
    return True

class Life360Scanner(object):
    def __init__(self, hass, see, interval, api, circle_id):
        self._hass = hass
        self._see = see
        self._interval = interval
        self._api = api
        self._circle_id = circle_id
        self._update_life360()

    def _update_life360(self, now=None):
        try:
            circle = self._api.get_circle(self._circle_id)
            for m in circle['members']:
                loc = m['location']
                lat = float(loc['latitude'])
                lon = float(loc['longitude'])
                name = " ".join([m['firstName'], m['lastName']])
                attrs = {
                    'friendly_name': name
                }
                self._see(dev_id=util.slugify(name), location_name=loc['name'],
                          gps=(lat, lon), gps_accuracy=round(float(loc['accuracy'])),
                          battery=int(loc['battery']), attributes=attrs)
        finally:
            track_point_in_utc_time(self._hass, self._update_life360,
                                    util.dt.utcnow() + self._interval)

Seems to work ok for me and my small Circle. Looking for any feedback, good or bad, and generally, what you think about the approach.

1 Like

Hi, is anyone else getting the following error since updating to Hassio 0.65?

nvalid service data for device_tracker.see: extra keys not allowed @ data[‘name’]. Got ‘DeviceName’

I’ve been receiving this error in the logs, which has resulted in the users’ location not updating ever since:

Yes, I believe this commit is causing the error (specifically the voluptuous validation) when HTTP is used (MQTT is not affected).

@HITChris I think I fixed this issues. Please update to resolve

Awesome. I’ll confirm once the add-on has been updated

Just updated and now get the same error but @ data[‘friendly_name’]. I’m using HTTP method.