So, as family we are using life360 app on iphone to check and warn which of us enters or leaves the house with notifications. Altough the api of life360 is not open, the following bash script which i gathered parts from this and there on web works for me:
Code: Select all
#!/bin/bash
#Set variables
#Domoticz Server Settings
domoticzserver="192.168.1.90:8080"
domoticzusername="username"
domoticzpassword="password"
username360="life360username"
password360="life360password"
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*')
}
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-]*')
}
function members () {
members=$(curl -s -X GET -H "Authorization: Bearer $1" https://api.life360.com/v3/circles/$2)
echo "$(date +%s) INFO: requesting members"
}
function domoticzrequest () {
domoticzmessage=$(curl -s -u domoticzusername:domoticzpassword -X GET $1)
}
bearer
circles $bearer_id
#Main Loop
#while :
#do
#Check if circle id is valid. If not request new token.
if [ -z "$circles_id" ]; then
bearer
circles $bearer_id
fi
#Loop through circle ids
for i in "${circles_id[0]}" # @ changed to 0 only for the family group
do
#request member list
members $bearer_id $i
#Check if member array is valid. If not request new token
if [ -z "$members" ]; then
bearer
circles $bearer_id
members $bearer_id $i
fi
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)
locationname=$(echo $members | jq .members[$count].location.name)
if [ "$locationname" = "\"Home"\" ]; then
locationname="On"
else
locationname="Off"
fi
echo "$locationname"
echo "$firstName"
# Me
if [ "$firstName" = "\"King of the North"\" ]; then
passaddress="http://$domoticzserver/json.htm?type=command¶m=switchlight&idx=97&switchcmd=$locationname"
fi
#Wife
if [ "$firstName" = "\"Queen of the North"\" ]; then
passaddress="http://$domoticzserver/json.htm?type=command¶m=switchlight&idx=98&switchcmd=$locationname"
fi
#Son
if [ "$firstName" = "\"Prince of the North"\" ]; then
passaddress="http://$domoticzserver/json.htm?type=command¶m=switchlight&idx=99&switchcmd=$locationname"
fi
domoticzrequest $passaddress
count=$(($count+1))
done
done
#sleep $timeout
#done
Code: Select all
if (devicechanged['FEB_Presence'] or devicechanged['DIB_Presence'] or devicechanged['HTB_Presence']) then
if (otherdevices['FEB_Presence'] == 'On' or otherdevices['DIB_Presence']== 'On' or otherdevices['HTB_Presence']== 'On') then
os.execute('curl -s "http://username:[email protected]:8080/json.htm?type=command¶m=setactivetimerplan&ActiveTimerPlan=4" &')
print("Family is Home")
else
os.execute('curl -s "http://username:[email protected]:8080/json.htm?type=command¶m=setactivetimerplan&ActiveTimerPlan=3" &')
print("Family is Away")
end
end