Re: Life 360 Module
I was trying to find a way to make life360 display location info for my family and ended up making it work using the a python script to generate the info into an html page that I then use the MMM-SmartWebDisplay Module to grab the generated html. This gave me a bit more control over the updates as I update less during the night than the day. and I wanted the table reused elsewhere.
What I used:
Config.js
MMM-SmartWebDisplay
{
module: 'MMM-SmartWebDisplay',
position: "middle_center",
config: {
url: ["http://192.168.1.106/life360.html"],
width: "700px",
height: "400px",
updateInterval: 4,
logDebug: false,
displayLastUpdate: false
}
},
NOTE: for anyone else trying to figure out why MMM-SmartWebDisplay isnt working, if the default text in your html is black and your mirror background is black then nothing shows! the module is working it is just the text is invisible.
I use crontab to run the script, e.g. this will run it every 3 minutes
*/3 * * * * /usr/bin/python /home/pi/dev/life360-python/checklife360.py >/var/www/html/life360.html
This is my checklife360.py
from life360 import life360
import datetime
from mapbox import Geocoder
geocoder = Geocoder(access_token="insert your mapbox token here")
if __name__ == "__main__":
# basic authorization hash (base64 if you want to decode it and see the sekrets)
# this is a googleable or sniffable value. i imagine life360 changes this sometimes.
authorization_token = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="
# your username and password (hope they are secure!)
username = "life360username"
password = "life360password"
#instantiate the API
api = life360(authorization_token=authorization_token, username=username, password=password)
if api.authenticate():
circles = api.get_circles()
id = circles[0]['id']
circle = api.get_circle(id)
print "<HEAD><link rel='stylesheet' href='main.css'></HEAD><BODY><TABLE>"
for m in circle['members']:
bat = int(float(m['location']['battery']))
loclat = float(m['location']['latitude'])
loclng = float(m['location']['longitude'])
print "<TR><TD style='color:#ffff00;'>", m['firstName'] + "</TD>"
# only call the geocoder if the name is not know this reduces the api calls
if m['location']['name']is not None:
print "<TD> </TD><TD style='color:#ffff00;'>" , m['location']['name'] + "</TD>"
else:
response = geocoder.reverse(lon=loclng, lat=loclat)
features = response.geojson()['features']
addr1='{place_name}: {id}'.format(**features[0]).split(",")
addr2='{place_name}: {id}'.format(**features[1]).split(",")
print "<TD> </TD><TD style='color:#3383FF;'>" + addr1[0] + ", " + addr2[1] + "</TD>"
if bat > 40:
print "<TD style='font-size: 15px;color:#00FF00;'>" , "{:.{}f}".format(float(m['location']['battery']),0) +"%</TD>"
elif bat > 21:
print "<TD style='font-size: 15px;color:#FFFF00;'>" , "{:.{}f}".format(float(m['location']['battery']),0) +"%</TD>"
else:
print "<TD style='font-size: 15px;color:#FF00FF;'>" , "{:.{}f}".format(float(m['location']['battery']),0) +"%</TD>"
print "</TR>"
print "</TABLE></BODY>"
else:
print "Error authenticating"
Hope this helps someone else.