Life 360 support

This feature would be a great addition. I currently use Life360 in combination with IFTTT. It would be great to bring it all into Home Assistant.

1 Like

Would love to have this as well!!

1 Like

I wrote a quick shell script to login to life360 and publish a mqtt message. It’s pretty basic but seems to work well. Just fill in your username and password in the script and run it. You also need to add the following to your configuration.yaml:
"device_tracker:

  • platform: owntracks"

You can find the script at https://pastebin.com/3q3ntT0a

2 Likes

Wow…this is exciting. How do we run the script? Can you provide little more details and steps involved? Also, if I already have a MQTT server (mosquitto), can I just use that? IN which case, what should mosquitto_pub="/path/to/mosquitto_pub" be?

I’ve been using life 360 for a long time and got tired of checking for the promised api. If the app is now useable that would be awesome. I have found it to be a reliable app. I tried it with IFTTT and getting a response 15-30 minutes later was pointless. This is encouraging news!

You can run the script on any linux box. Make sure you have jq and mosquitto_pub installed. mosquitto_pub is part of the mosquitto package, so if you have mosquitto installed mosquitto_pub should already be on your server.
Create a new file on your linux server. paste the code from the pastebin into it. Change the top ten lines to your personal information. Chmod +x the file and run it. It requests member locations every 300 sec (set by the timeout var) it then publishes a JSON message (in the owntracks format) to owntracks/FirstName/DeviceID/ on the mqtt server you specified.
Use nohup to run the script in the background when your done testing.

I am just starting to evaluate home assistant to run for my home automation. I did not want to invest to much time into this. I don’t sanitize any input from life360, so don’t name your kids Tommy’); DROP TABLE or anything silly. Also, life360 does not publish any info about their api so they might block this at some point.

I copied the code to file life360.sh, modified the first few lines, and have both jq and mosquitto_pub installed. I ran the script and get the following errors:

pi@raspberrypi:/home/hass/.homeassistant/python $ ./life360.sh
./life360.sh: line 4: username360: command not found
./life360.sh: line 5: password360: command not found
Error: Unknown option '='.

Use 'mosquitto_pub --help' to see usage.
./life360.sh: line 7: mqtt_host: command not found
./life360.sh: line 8: mqtt_port: command not found
./life360.sh: line 9: mqtt_user: command not found
./life360.sh: line 10: mqtt_pass: command not found
timeout: invalid time interval ‘=’
Try 'timeout --help' for more information.
./life360.sh: line 21: syntax error near unexpected token `<'
./life360.sh: line 21: `    read - a circles_id << <$(curl - s - X GET - H "Authorization: Bearer $1" https: // api.life360.com / v3 / circles.json | grep - Po '(?<="id":")[\w-]*')'

change first line to #!/bin/sh

with #!/bin/sh

pi@raspberrypi:/home/hass/.homeassistant/python $ ./life360.sh
./life360.sh: 4: ./life360.sh: username360: not found
./life360.sh: 5: ./life360.sh: password360: not found
Error: Unknown option '='.

Use 'mosquitto_pub --help' to see usage.
./life360.sh: 7: ./life360.sh: mqtt_host: not found
./life360.sh: 8: ./life360.sh: mqtt_port: not found
./life360.sh: 9: ./life360.sh: mqtt_user: not found
./life360.sh: 10: ./life360.sh: mqtt_pass: not found
timeout: invalid time interval ‘=’
Try 'timeout --help' for more information.
./life360.sh: 14: ./life360.sh: function: not found
1491944218 INFO: requesting access token
grep: Po: No such file or directory
grep: (?<="access_token":")\w*: No such file or directory
curl: option -: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
./life360.sh: 16: ./life360.sh: bearer_id: not found
./life360.sh: 17: ./life360.sh: Syntax error: "}" unexpected

Line 4 is just setting a variable named username360 equal to whatever you have in quotes. You have something weird going on. Was the script copied and pasted fine? Copy the script from https://pastebin.com/raw/3q3ntT0a and use nano or vi to paste it. Maybe windows is putting some weird characters in there or something?

If that doesn’t work, paste the following in the shell prompt:
var=‘test’ bash -c ‘echo $var’

Does it echo test back?

There were some extra spaces…removed them…now I am getting

hass@raspberrypi:~/.homeassistant/python$ ./life360.sh
./life360.sh: 13: ./life360.sh: function: not found
1491945674 INFO: requesting access token
./life360.sh: 16: ./life360.sh: Syntax error: "}" unexpected

You must still have spaces or extra characters in the script.

1 Like

Here’s my script https://hastebin.com/qopudanisu.bash

I double checked and did not find any spaces. I am getting error:

./life360.sh: 17: ./life360.sh: Syntax error: "(" unexpected

Do we need the parentheses in function circles () on line 17?

looks like your error is on line 15. put the closing } on a new line, just like what I had put on pastebin. Also change line 1 to match pastebin.

Thanks a lot for that, I’ve been jumping through hoops trying to get life360 from IFTTT to an input_boolean in homeassistant etc. etc.

The location works great. Well, it probably all does, but I can’t seem to get the sensor for battery info to work in HASS. I can do a mosquitto_pub in terminal, and I get the battery stats just fine. But not in HASS. My sensor.yaml has

- platform: mqtt
  state_topic: "owntracks/MYNAME/DEVICE_ID"
  name: "Phone Battery 360"
  unit_of_measurement: "%"
  value_template: "{{ value_json.batt }}"

where my NAME and DEVICE_ID is what was auto-populated in known.devices.yaml (is that rght? My name used in the app, then a 32 character string as device id?). Other than the topic, it’s the exact same configuration as I use for owntracks.

EDIT: If I delete the device ID from the sensor.yaml file (so just do state_topic: “owntracks/MYNAME/#”), then it works fine. So I guess this works, now I’m more just curious about why it doesn’t with the device ID?

Getting the below error. Any idea what im doing wrong?

./life_360.sh: line 56: jq: command not found

I think that jq: command not found that you didn’t install jq (like brazen1445 said you needed to)

For me on raspbian jessie, just a sudo apt-get install jq should do it (see the documentation for installation for your specific system)

I have updated the script to fix a conditon where you might get duplicate id’s. https://pastebin.com/xrYTvtCR

My sensor reads the battery fine. My config looks like:

device_tracker:

  • platform: owntracks

sensor:

  • platform: mqtt
    state_topic: “owntracks/MYNAME/DEVICE_ID”
    name: “Battery My Device”
    unit_of_measurement: “%”
    value_template: ‘{{ value_json.batt }}’

I would sugest you search through your hass log for “Received message on owntracks” and make sure you have the correct mqtt topic

OK, finally got around to testing.

The tracker makes its own entry in known_devices.yaml with name and DEVICE_ID, but in the mqtt topic it sends, it has inserted four dashes within the ID. So for my known_devices.yaml, I have someting like (auto-created, I didn’t write any of this, except changing the “name”):

MYNAME_XXXYYYYZZZAAABBBCCC:
  hide_if_away: false
  mac:
  name: MyName 360 tracker
  picture:
  track: true
  vendor:

where the XXXYYY… is the auto-generated DEVICE_ID.

But checking my logs, and to get my battery tracker to work, I needed to do

- platform: mqtt
  state_topic: "owntracks/MYNAME/XXX-YYYY-ZZZZAAAA-BBBB-CCCC"
  name: "Aephir Phone Battery 360"
  unit_of_measurement: "%"
  value_template: "{{ value_json.batt }}"

Which is really weird, since it gets the location with the un-dashed ID, but needs the dashes for the battery sensor. And the location seems to work just fine, even though the mqtt topic has the dashes.