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!