Python Plugin: Life 360 Presence Detection

Python and python framework
User avatar
capman
Posts: 202
Joined: Friday 12 July 2013 20:48
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Belgium
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by capman » Sunday 15 April 2018 20:04

I get this error in my log :(
Is this a domoticz , python or life360 problem.
Running domoticz beta v 3.9208 on a synology.
life360.JPG
life360.JPG (111.15 KiB) Viewed 1155 times

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Sunday 15 April 2018 22:13

Could be an authentication problem with life360: (Because of the HTTPError detail)
1. Enable Debug
2. Leave Google api key empty (to make sure the problem is in life30, not google)
3. don't forget to write your email address as life360 username, not only the username itself but includes @somethingemail.com. you can check your credentails from life360 web page login.

Maybe debug option can give more details.

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Monday 16 April 2018 10:03

I noticed the same and it's gone now. I suspect it was an issue with L360 itself.
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

User avatar
capman
Posts: 202
Joined: Friday 12 July 2013 20:48
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Belgium
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by capman » Tuesday 17 April 2018 20:09

Yes , it's gone. Like you suspect , it was a issue with Life360.
Thanks ;)

l00pz
Posts: 56
Joined: Wednesday 01 April 2015 11:52
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by l00pz » Tuesday 05 June 2018 20:32

I'm really happy with this Plug-in as its way more stable then the Geofencing from the Domoticz App or Domofence :D But is it possible to increase the poll period to something lower then 60 seconds? I don't want to make the Life360 Circle to big, but when I make the Circle like 500M the time from opening the door and the time that Domoticz Updates the Life360 plug-in sometimes gives me false alarms. Making the Circle bigger is one solution of course, but if it's possible the lower the poll period to like 30 seconds that would be great.

g00fy
Posts: 10
Joined: Friday 08 September 2017 8:27
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Dordrecht, The Netherlands
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by g00fy » Tuesday 17 July 2018 17:11

Does anyone know what the usage of the Google api means concerning the new pricing policy Google anounced? I see in my case there were more than 44.000 cals on the geocoding api in the last 30 days (I was running an older version, so the cals on the distance api were not counted yet). This means that there will be about 88.000 cals a month when using these features, resulting in a bill of around $240 (not including the free $200 we get from Google).

As I look in the code it seems the api's are contacted every time life360 is contacted. Isn't it possible to limit this to only the times the location from life360 is updated? I supose this will result in a much lower count of api cals?

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Wednesday 01 August 2018 20:42

Unfortunately Google's new pricing policy on Maps API is causing errors on the plugin due to exceeding daily free query quota. I have to change the usage of Google's maps api to something else due to the continuation of free usage for this plugin. The current alternatives are Yandex and waze. If i can extract any information from life360, that will also be a solution. Thanks for your patience...
PS: The free version of Yandex is 25.000 calls per day.
PS2: Yandex doesnot have a traffic API
PS3: Google Directions API is still working without a key, but there's only duration info there (when there is no traffic), not duration_in_traffic...
PS4: Waze maps are still not sufficient for many countries.
PS5: I should give up adding PSs.

g00fy
Posts: 10
Joined: Friday 08 September 2017 8:27
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Dordrecht, The Netherlands
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by g00fy » Thursday 02 August 2018 18:02

I did write a little change to your code that makes it possible to use Open Streetmaps as source, using Nominatum for the API.
At the moment Iam on holidays using it and it seems to work reasonably well for getting your location.

One thing to look into is the usage policies of Nominatim. It wants you to 'provide a valid HTTP Referer or User-Agent identifying the application'. For testing I used Domoticz-geofence for now, but I don't know if that will be right.

It looks like I can't upload the code via Tapatalk, so I will try to sent it to you in a message. Hopefully it will getting you forward in a solution replacing Google Maps.

PS I am not a software developer, so please feel free to change the code when you think it can be done better...

Verstuurd vanaf mijn TA-1012 met Tapatalk


febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Thursday 02 August 2018 22:27

g00fy wrote:
Thursday 02 August 2018 18:02
I did write a little change to your code that makes it possible to use Open Streetmaps as source, using Nominatum for the API.
At the moment Iam on holidays using it and it seems to work reasonably well for getting your location.

One thing to look into is the usage policies of Nominatim. It wants you to 'provide a valid HTTP Referer or User-Agent identifying the application'. For testing I used Domoticz-geofence for now, but I don't know if that will be right.

It looks like I can't upload the code via Tapatalk, so I will try to sent it to you in a message. Hopefully it will getting you forward in a solution replacing Google Maps.

PS I am not a software developer, so please feel free to change the code when you think it can be done better...

Verstuurd vanaf mijn TA-1012 met Tapatalk
Actually getting the address from coordinates is easy, since google maps API doesnt need a key for that. I will change the code according to that next week. The problem is with the traffic data; i may completely take it out.

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Monday 17 September 2018 22:36

@febalci: I noticed in your plugin that, onHeartbeat, you call api = life360(), api.authenticate, api.get_circle_id and api.get_circle. I would expect that you would only need to update the circle details (api.get_circle()) rather than everything else. Any reason why the whole re-initialise?

Reason I am asking is that the urllib calls are all non asynchronous and may cause domoticz to indicate that the plugin may have ended unexpectedly. In that sense, I was hoping to only do the get_circle in onHeartbeat (and maybe even make that asynchronous through the plugin http mechanism) in order to speed things up.

Thoughts?

H
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Tuesday 18 September 2018 9:13

@heggink: Thanks for the details. I was not sure if the circle_id is a constant all throughout the time, or was changing from time to time. That's why i put get circle_id also in the onheartbeat. I am planning to do a do-over of the plugin soon. I will also take this into consideration.

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Tuesday 18 September 2018 11:33

@febalci: I changed my local plugin.py to test it and, for now, it seems to work OK but I am not sure for how long and whether, at some point, you need to reconnect.

On this subject, I was trying to see what's required to move to the plugin framework's async messaging. In that sense, trying to do all the connection setup asynchronously would be a mess (since the startup needs the circle home members in order to create devices) which is where I was wondering whether you can do the setup using urllib and then switch to the async calls for the heartbeats. Then again, if the connection expires then one would need to do a reconnect again so more complexity...

Difficult...
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Tuesday 18 September 2018 12:23

heggink wrote:
Monday 17 September 2018 22:36
@febalci: I noticed in your plugin that, onHeartbeat, you call api = life360(), api.authenticate, api.get_circle_id and api.get_circle. I would expect that you would only need to update the circle details (api.get_circle()) rather than everything else. Any reason why the whole re-initialise?
Just now issued v2.0.0 which includes those items:
v2.0.0
  • Fixed:If the target is unreachable (Other side of ocean-@heggink) the distance is now 0 in order to prevent memory problems
  • New:Removed get_circle_id from onheartbeat since it is a constant (@heggink) to reduce life360 api calls
  • Fixed: If the addess is defined as a name other than 'Home' (Like School) in life360, distance was showing as 0 km.
  • New: Reduced Google Maps API calls by incorporating address to getdistance function. getaddress is only called if getdistance returns None address.
This also solves (at least the memory problem) with overseas travels.

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Tuesday 18 September 2018 15:24

hey @febalic,
your heartbeat still has the following in it:

Code: Select all

           api = life360(authorization_token=self.authorization_token, username=Parameters["Username"], password=Parameters["Password"])
           if api.authenticate():

So you only took out the get_circle_id and not the api.authenticate(). I believe you can also take that out unless the token expires at some point, correct?
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Tuesday 18 September 2018 15:54

heggink wrote:
Tuesday 18 September 2018 15:24
hey @febalic,
your heartbeat still has the following in it:

Code: Select all

           api = life360(authorization_token=self.authorization_token, username=Parameters["Username"], password=Parameters["Password"])
           if api.authenticate():

So you only took out the get_circle_id and not the api.authenticate(). I believe you can also take that out unless the token expires at some point, correct?
Token is more likely to change. I feel it like it is a session token. If you are sure it doesn't change; then we can try it.

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Tuesday 18 September 2018 18:08

Let's see how my changes behave over a couple of days. Will let you know. Also trying to replace the synchronous calls but life360 complains about a bad request
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

febalci
Posts: 334
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by febalci » Tuesday 18 September 2018 20:56

Honestly i didnot get the logic behind changing sync calls. As far as i remember plugin framework was not allowing async calls. And yet i still do not know which is sync which is asynch call :oops: So my motto is if it Aint break dont mess with it :D

User avatar
heggink
Posts: 580
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi
Domoticz version: V4.9999
Location: NL
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by heggink » Tuesday 18 September 2018 21:11

Understood. It's just that I run quite a number of python plugins that use urllib to interface to iCloud, life360, weather systems and so on. Urllib is blocking and I have the feeling that it impacts responsiveness of my system more than if they were in an asynchronous way. Sometimes walking into the garage, it takes seconds for the light to turn on (dzvents script) where normally it is sub second.
Pi3, latest beta
RFXCOM, z-wave (AEOTEC, switches, temhum, pir, contacts),
Plugwise2py, P1 'smart'meter & solar panel
Alexa, Wifi Cams motion detection
ESP: relays, PIR & Temp/TempHum
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest

aldodemi
Posts: 40
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by aldodemi » Monday 01 October 2018 23:16

With current version if I put my Google Maps API Key I receive this error:
2018-10-01 23:13:34.355 Error: (Life360) 'onHeartbeat' failed 'UnboundLocalError':'local variable 'jsonr' referenced before assignment'.
2018-10-01 23:13:34.356 Error: (Life360) ----> Line 254 in '/home/domoticz/domoticz/plugins/life360/plugin.py', function onHeartbeat
2018-10-01 23:13:34.356 Error: (Life360) ----> Line 199 in '/home/domoticz/domoticz/plugins/life360/plugin.py', function onHeartbeat
2018-10-01 23:13:34.356 Error: (Life360) ----> Line 58 in '/home/domoticz/domoticz/plugins/life360/googlemapsapi.py', function getdistance
2018-10-01 23:13:34.356 Error: (Life360) ----> Line 43 in '/home/domoticz/domoticz/plugins/life360/googlemapsapi.py', function make_request

without API key no errors but also no locations info.

The API key is correct.

Any help well accepted
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)

l00pz
Posts: 56
Joined: Wednesday 01 April 2015 11:52
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Python Plugin: Life 360 Presence Detection

Post by l00pz » Saturday 06 October 2018 20:14

heggink wrote:
Tuesday 18 September 2018 21:11
Understood. It's just that I run quite a number of python plugins that use urllib to interface to iCloud, life360, weather systems and so on. Urllib is blocking and I have the feeling that it impacts responsiveness of my system more than if they were in an asynchronous way. Sometimes walking into the garage, it takes seconds for the light to turn on (dzvents script) where normally it is sub second.
Is the Plug-in still working after you modified it? I have the same problem as you describe, and I am curious as this is a possible solution.
Last edited by l00pz on Saturday 06 October 2018 23:00, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests