Life360 Presence Detection
Posted: Saturday 08 July 2017 14:45
Hello, Beginner in Domoticz here. Using iphones familywise. It has always been a headache using presence for home automation on iphones. I tried almost all, including ddwrt, hping3, homekit etc. DDwrt is in basement, my DSL router is in the entrance and it is the first one that catches wifi and it is not open source, so count that out. hping3 is not working on my synology domoticz server, and cannot wake iphone. Homekit seems promising together with homebridge, however family automations are still not there...
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:
I created 3 dummy switches for me, wife and son. Created timers in TimerPlans as "Home" and "Away". Using Lua script in events as
Now the thing is; since i started Domoticz after openHab, i couldn't set the events usage stable in my head. The Bash script is working with synology cron every 2 minutes. It pushes presence info to domoticz json. Lua script is checking switch updates. It pushes to domoticz json again for setting active timer plan. Now that seems to me that is way excessive usage of cron or scripts. How do i keep everything in one place or make it more effective? Any suggestions?
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