Life 360 support

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.

Hello I am trying to get this working. I have been using Life 360 for at least 5 years and would like to use it with HA, I am getting an Error when running the script, I copied and pasted 3 different scripts from here but get the same Error

File “life360.sh”, line 13
function bearer {
^
SyntaxError: invalid syntax

the arrorow up is under the last r if that helps

function bearer {
echo “$(date +%s) INFO: requesting access token”
bearer_id=$(curl -s -X POST -H “Authorization: Basic cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg==” -F “grant_type=password” -F “username=$username360” -F “password=$password360” https://api.life360.com/v3/oauth2/token.json | grep -Po ‘(?<=“access_token”:")\w*’)
}

and cant seem to find the Error my next step is to type it all out.

Thank you

Not sure, but you can try copying from https://github.com/Aephir/homeassistant/blob/master/shell_scripts/life360.sh
(just be aware that many of the other files there are very much works in progress). This one works for me.
Maybe check that (1) you can log in to life360 with the username and password provided (line 4 and 5), and that mqtt works (try using this guide: https://home-assistant.io/docs/mqtt/testing/). I used in the terminal:

mosquitto_sub -h 127.0.0.1 -v -t "home-assistant/#"

And then using the developer tool in home assistant to send a test message. If nothing pops up on your terminal (the message you sent), then that’s your problem (perhaps username/password in you home assistant configuration file?)

OK I have had Owntracks running for a few months and mosquitto mqtt broker running for about 6 months I’m not sure if I understand the
mosquitto_pub="/path/to/mosquitto_pub" Is this the topic or the actual path to mosquitto_pub

Edit: looks to me its the path But I’m having trouble finding the path. I installed mosquitto on a raspberry pi

Thank you

Yes, the path. For me, it is

mosquitto_pub="/usr/bin/mosquitto_pub"

If you are on a raspberry (or, I guess, any unix, but specifically for raspbian), I’d recommend doing:

sudo apt-get install mlocate
sudo updatedb

The you can type

locate XXX

and find anything (maybe not hidden stuff, or things the current user doesn’t have access to, I’m not sure about the exact details). Very helpful. I’d try:

locate /mosquitto_pub

Then you should find your path.

Hope this helps

Well not sure what I’m doing wrong all mine looks the same as yours even the location and still getting the same Error.
I know the user name and password is OK, I logged off and back on. I guess I’ll check the script line by line add it instead of copy and paste.

Thanks for you help

is it that good?

Well, I’m running out of ideas.

Do you have citation marks around your username/password? My file looks like this:

#!/bin/bash

#Set variables
username360="XXXX"
password360="XXXXX"
mosquitto_pub="/usr/bin/mosquitto_pub"
mqtt_host="127.0.0.1"
mqtt_port="1883"
mqtt_user="XXXXX"
mqtt_pass="XXXXX"
timeout=300

just with XXXXX replaced with usernames and passwords, but all the quotation marks (") are also included.

Try copying mine from the github, and only changing the username/passwords. I’m not saying I think you made any mistakes, but I know from time to time I have made some small error (like an extra space or something stupid like that), and I couldn’t fix it until I just started from scratch.

@Aephir Well I checked everything an all was fine i even deleted the script and made a new one then added my info and still had the same Error. I’m going to put a fresh copy of everything on another SD card and see if I get the same Error.

Thanks again for your help I’ll let you know what I found out.