Linking Life360 and OH2 gpstracker [a simple script]

Tags: #<Tag:0x00007f386a499d10> #<Tag:0x00007f386a499ba8>

My family are on Life360, and I wanted to use gpstracker to manage presence, so I modified the ubiquitous Life360/mqtt script to post directly to gpstracker via HTTP.

Here’s a link to the code:

and for those that enjoy cut and paste:



function check_error() {
    local error=$?
    if [ $error -ne 0 ]; then
        echo "error in $1: $error"

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" | ggrep -Po '(?<="access_token":")\w*')
    check_error bearer

function circles() {
    echo "$(date +%s) INFO: requesting circles."
    read -a circles_id <<<$(curl -s -X GET -H "Authorization: Bearer $1" | ggrep -Po '(?<="id":")[\w-]*')
    check_error circles

function members() {
    echo "$(date +%s) INFO: requesting members"
    members=$(curl -s -X GET -H "Authorization: Bearer $1"$2)
    check_error member

function get_circles() {
    circles $bearer_id
    if [ -z "$circles_id" ]; then

function get_members() {
    members $1 $2
    if [ -z "$members" ]; then


#Loop through circle ids
for i in "${circles_id[0]}"; do # @ is made 0 to include Family group only

    #request member list
    get_members $bearer_id $i

    members_id=$(echo $members | jq '.members[].id')
    IFS=$'\n' read -rd '' -a members_array <<<"$members_id"
    for i in "${members_array[@]}"; do
        firstName=$(echo $members | jq .members[$count].firstName)
        lastName=$( echo $members | jq .members[$count].lastName)
        latitude=$( echo $members | jq .members[$count].location.latitude)
        longitude=$(echo $members | jq .members[$count].location.longitude)
        accuracy=$( echo $members | jq .members[$count].location.accuracy)
        battery=$(  echo $members | jq .members[$count].location.battery)
        timestamp=$(echo $members | jq .members[$count].location.timestamp)

        # change the following line if the first and last initials are
        # not unique in your Life360 family group


        curl -H "Content-type: application/json" \
             -s -S \
             -d "{ \
                  \"_type\":\"location\", \
                  \"tid\":  \"$tid\",     \
                  \"tst\":  $timestamp,   \
                  \"lon\":  $longitude,   \
                  \"lat\":  $latitude,    \
                  \"batt\": $battery,     \
                  \"acc\":  $accuracy     \
                }" \

        check_error "sending $tid to gpstracker"
        count=$(($count + 1))

echo "$(date +%s) INFO: done"

Thanks for posting! I’ve moved the post to the Tutorials and Examples category.

I keep getting the error “ggrep: command not found” when I try and execute the script. I see the ggrep command at the end of the line getting the bearer_id and without that, the rest of the script fails as would be expected.

I’ve tried doing apt-get install ggrep, but I get “Unable to locate package ggrep”. I have also googled around a little to figure out ggrep is and all google gives me is info on grep. I am running on Rasbian.

Never mind. I just did a find and replace all instances of “ggrep” with “grep” and it looks like the script is working. Now time to try and hook it up with the binding.

Yeah, sorry about that. On my Mac, ggrep is gnu grep.

@Dave_Thomas thank you so much for this. This was a million times easier to set up and work with than “Life360 and MQTT”. These are the steps I took to get this setup and running.

  1. SSH into my openhabianpi using putty. I created a new script sudo nano /etc/openhab2/scripts/
  2. Paste in @Dave_Thomas’s script from above with some minor changes.
    2.1 change all occurrences of ggrep to grep there are two
    2.2 change the IP address >/dev/null to >/dev/null
  3. Add execute permissions to the script sudo chmod +x /etc/openhab2/scripts/
    3.1 You can test the script /etc/openhab2/scripts/
  4. Now we want to run the script on a timer. I set mine to run once a minute.
    4.1 Open crontab crontab -e and add the line */1 * * * * /etc/openhab2/scripts/ >/dev/null 2>&1. Then exit and save.
    4.2 Restart crontab service cron reload
  5. Go into the paper UI and install the “GPSTracker Binding”
  6. Once the binding is installed you should automatically see each member of your family circle from life360 (They will show as GPS Tracker initials) appear in your inbox.
  7. Now you can work with this data the same as you would with the standard “GPSTracker Binding”

Thank you again @Dave_Thomas I have you give you all the credit for getting this working so easily for me.