Life360 script doesnt work after 3.4->4.0.1

Hi ,for a long time i use GPSTracker binding with Life360 with a script and i am pretty happy with that.Its fast and accurate and i use it for several automations.After upgrading to 4.0.1 the script does not run anymore.No errors in log.The script is that :

#!/bin/bash

username360="xxxxxxxxx@gmail.com"
password360="xxxxxxxxxxx"
openhabIP="127.0.0.1:8080"

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

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*')
    check_error bearer
}

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

function members() {
    echo "$(date +%s) INFO: requesting members"
    members=$(curl -s -X GET -H "Authorization: Bearer $1" https://api.life360.com/v3/circles/$2)
    check_error member
}

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

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

get_circles

#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"
    count=0
    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

        tid=${firstName:1:1}${lastName:1:1}

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

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

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

and i use a rule to run it every minute

rule "location"
when
   Time cron "0 * * ? * *"
then
    executeCommandLine("/etc/openhab/scripts/life360_presence.sh")
end

Any ideas why it is not working any more?
thnx!

What is the output if you manually execute/run /etc/openhab/scripts/life360_presence.sh ?

i run it and i ve got

openhabian@openhabian:~ $ /etc/openhab/scripts/life360_presence.sh
1690752766 INFO: requesting access token
error in bearer: 1
1690752767 INFO: requesting circles.
1690752768 INFO: requesting access token
error in bearer: 1
1690752768 INFO: requesting circles.
1690752769 INFO: requesting access token
error in bearer: 1
1690752770 INFO: requesting circles.
1690752770 INFO: requesting access token
error in bearer: 1
1690752771 INFO: requesting circles.
1690752771 INFO: requesting access token
error in bearer: 1
1690752772 INFO: requesting circles.
1690752773 INFO: requesting access token
error in bearer: 1
1690752773 INFO: requesting circles.
1690752774 INFO: requesting access token
error in bearer: 1
1690752775 INFO: requesting circles.
1690752775 INFO: requesting access token
error in bearer: 1
1690752776 INFO: requesting circles.
1690752776 INFO: requesting access token
error in bearer: 1
1690752777 INFO: requesting circles.
1690752778 INFO: requesting access token
error in bearer: 1
1690752778 INFO: requesting circles.
 1690752779 INFO: requesting access token
error in bearer: 1
1690752780 INFO: requesting circles.
1690752780 INFO: requesting access token
error in bearer: 1
1690752781 INFO: requesting circles.
1690752781 INFO: requesting access token

So that looks like a problem with requesting access token as it returns error in bearer.

Run :

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

on command line make sure that $username360 and $password360 is set before resp. replace them with their values. What is returned ?

it returned

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
</body>
</html>

so i think its an API problem?

Of Life360 but not OH.
You may try to add the switch -L to your curl command to try if it follows the 301 redirect then.

1 Like

Hi, the token has been changed to “Y2F0aGFwYWNyQVBoZUtVc3RlOGV2ZXZldnVjSGFmZVRydVl1ZnJhYzpkOEM5ZVlVdkE2dUZ1YnJ1SmVnZXRyZVZ1dFJ”

this token worked for me

Y2F0aGFwYWNyQVBoZUtVc3RlOGV2ZXZldnVjSGFmZVRydVl1ZnJhYzpkOEM5ZVlVdkE2dUZ1YnJ1SmVnZXRyZVZ1dFJlQ1JVWQ==

Looks like this token stopped working…going to move to something else for location tracking.