An idea for presence tracking

Posted on
Tue Jan 15, 2013 7:47 pm
richy240 offline
Posts: 111
Joined: Jul 08, 2012

An idea for presence tracking

I have tried a few different methods for tracking presence and I have had a hard time finding one that really nails it. Find My iDevices is nice and works really well, but I had a hard time swallowing the ~15-minute delay given the battery drain I experienced (not to mention I noticed some wonky behavior with my setup that couldn't be accounted for). And Smartphone Radar is very reliable in itself, but again there's a delay (the timeout period for away), and the best method I found for forcing Internet access is a POP3 account which polls the server every 15 minutes (which is pretty reliable to ensure I don't go away while I'm actually at home, but not very elegant). I currently have some automation based around Smartphone Radar, and it's working quite well. But still it leaves something to be desired.

So now I am experimenting with Find My Friends on the iPhone, which, as long as you're running iOS 6 (on recent hardware, I can only guess), can send email alerts based your movements - specifically when you arrive or leave a location. And since Indigo can poll an email account at regular intervals, I think this provides a good formula for location-based triggers. (This requires very frequent polling of the Indigo mailbox for minimal delays, but I don't personally see that as a huge problem.) It's much simpler than Find My iDevices, don't get me wrong, and I'm already trying to figure out how to introduce more advanced location tracking using this method. But it grants more flexibility than Smartphone Radar because it's almost real-time and it has the potential to track your presence at multiple locations (home, work, mom's house, etc.) if you had a need for that (I don't).

So far, it's damn reliable and the battery drain is unnoticeable. I'm alerted to my presence pretty quickly by email via triggers in Indigo I created for testing purposes. I am planning on moving some of my automation over to this soon to see how well it works in "production." Right now it's pretty labor intensive to set up the variables and triggers that do the heavy lifting (and I've only created the basis thus far), but I am starting to play with Python to see if this is plugin material (or if I can even write one - I'm no developer). The only reason I'm using Find My Friends is because I couldn't find another app that does anything like this. (Some come close, granted.)

Anyone have any thoughts or feedback? Has anyone else tried something like this, or even ditched it for another method?

Posted on
Tue Jan 15, 2013 8:15 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: An idea for presence tracking

Sounds great, please keep this thread updated with your progress! I'm especially interested in whether or not you see any negative effects from polling the email frequently. What rate are you polling it at?

Posted on
Tue Jan 15, 2013 8:27 pm
richy240 offline
Posts: 111
Joined: Jul 08, 2012

Re: An idea for presence tracking

Lol, every minute... It's a Gmail account with POP3 enabled. I hope they don't get pissed. :P

Posted on
Wed Jan 16, 2013 1:01 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: An idea for presence tracking

Sounds like a cool idea. I would surmise that this works without draining the battery as much because Apple has some kind of background process (probably the notification daemon) on iPhones with the Find My Friends app installed that pushes geo-location notifications rather than relying on a pull method from the iCloud servers a la Find My iDevice. In any case, sounds promising for iOS users.

Posted on
Wed Jan 16, 2013 6:00 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: An idea for presence tracking

richy240 wrote:
Lol, every minute... It's a Gmail account with POP3 enabled. I hope they don't get pissed. :P


You may not need to use Indigo to do your mail checking...

If you use Apple's Mail.app (and probably other clients as well), you have the ability to execute an AppleScript as a Rule action, The rule can be based on sender, recipient, subject, etc. and would identify incoming Find Friends messages. Such a script can then parse out the data from the location email and put it into Indigo, call an Indigo Action, etc.

BTW, If you switch to IMAP, depending on your mail client, you may have the option of staying synchronized. Or, you could at least check every minute. Since only the mail client would be checking that shouldn't cause any problems.

I have attached an example AppleScript below. In this script I used the shell to make life easier, but you wouldn't have to do that.

Code: Select all
-- This script extracts Solar Radiation (Sol Rad) and ETo data
-- from an email message.

--executes when the conditions of a Mail rule are met
on perform_mail_action(theData)
   --define the output folder to the file path where the attachment(s) should be saved
   set myFile to "var:tmp:cimis_spatial_data" as string
   set myPath to POSIX path of myFile
   
   set cimisDate to ""
   set cimisRefETo to ""
   set cimisSolRad to ""
   
   --script Mail
   tell application "Mail"
      --get array of all incoming messages that match the rule
      set theSelectedMessages to |SelectedMessages| of theData
      
      --loop through the matching messages
      repeat with a from 1 to count theSelectedMessages
         --get this message
         set theMessage to item a of theSelectedMessages
         set msgSource to the source of theMessage
         do shell script ("/bin/echo " & quoted form of msgSource & ">" & myPath)
         -- get today's date from the header
         set cimisDate to do shell script ("/usr/bin/grep ^Date: " & myPath & " |/usr/bin/cut -c7-|/usr/bin/cut -d- -f1")
         -- only read the first line of data (-m1)
         set cimisRefETo to do shell script ("/usr/bin/grep  1,37.90, " & myPath & " |/usr/bin/tail -1|/usr/bin/cut -d, -f5")
         set cimisSolRad to do shell script ("/usr/bin/grep  1,37.90, " & myPath & " |/usr/bin/tail -1|/usr/bin/cut -d, -f6")
         --end repeat
      end repeat
   end tell
   if cimisRefETo is not "-" and cimisRefETo is not "" and cimisRefETo is not 0 then
      updateIndigo(cimisDate, cimisRefETo, cimisSolRad)
   else
      tell application "IndigoServer" to log "Invalid cimis data received for " & cimisDate & ". Variables left unchanged." using type "cimis mail script"
   end if
end perform_mail_action

on updateIndigo(cimisDate, cimisRefETo, cimisSolRad)
   tell application "IndigoServer"
      log "cimis data received for " & cimisDate & ", ETo=" & cimisRefETo & ", SolRad=" & cimisSolRad using type "cimis mail script"
      set the value of variable "cimisDate" to cimisDate as text
      set the value of variable "cimisRefETo" to cimisRefETo as text
      set the value of variable "cimisSolRad" to cimisSolRad as text
   end tell
end updateIndigo


And, thanks for a GREAT idea.

Posted on
Wed Jan 16, 2013 6:13 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: An idea for presence tracking

Been using this today and so far so good! Going to integrate the other two iPhones in the house tonight and see what happens tomorrow when we all go off to work :D

The extra battery drain is noticeable, but not significant I don't think.

Posted on
Wed Jan 16, 2013 6:39 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: An idea for presence tracking

If you use Apple's Mail.app (and probably other clients as well), you have the ability to execute an AppleScript as a Rule action


Thanks for reminding me of this, this is actually preferable since if you don't delete the email, every time indigo polls the email account it will re-trigger the last status received!

Posted on
Wed Jan 16, 2013 10:25 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

Re: An idea for presence tracking

richy240 wrote:

Anyone have any thoughts or feedback? Has anyone else tried something like this, or even ditched it for another method?


Your message prompted me to look into this. I'm using an app called GeoMessage which IMO is easier to integrate than Find Friends. You can set up a rule in Mail.app to run an applescript, parse the message and tell indigo server to do whatever.An alternate approach would be to use the indigo mail trigger to run an applescript which then uses a mail.app tell block, to do the same. Either way, you'll want to parse the message with Mail.app since the Indigo mail trigger does not expose the message body to applescript.

Thanks for introducing another angle on solving this enduring problem.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Wed Jan 16, 2013 11:40 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: An idea for presence tracking

The benefit of using a Mail.app rule is that the detection takes only as long as it takes for Find My Friends to email your location, which in my initial testing is VERY quick. Takes my house out of "Away" mode before I even get to the front door. I now have it set up to turn on user selected lights when that user arrives home also, loving it :D

Posted on
Thu Jan 17, 2013 4:36 pm
richy240 offline
Posts: 111
Joined: Jul 08, 2012

Re: An idea for presence tracking

Wow, I'm really glad this is getting some traction. :D

I've built a little more logic into my setup, which now tracks when Someone or Everyone is home. (Ok, it was there from the beginning, I just didn't mention it before.) I had something like this put together for Smartphone Radar too, since it doesn't keep track of some things I needed. The triggers that relate to Everyone have a condition that checks for the presence of the other person. Two or three more people and this could get very complicated. ;)

Image

Also, I'm still using Smartphone Radar for visitors (so far I only have my mother-in-law's phone added). I'm paying special attention to the AllPhonesAway variable (which I interpret as AllVisitorsAway). It enables/disables any automation in my setup that might affect a guest if we leave the house. We haven't had any visitors since I started working on this, so I don't know if it works, but it looks pretty solid on paper.

guitar486 wrote:
The extra battery drain is noticeable, but not significant I don't think.

I guess I should have qualified my comment by saying that I already use iOS' location awareness for a couple other things, so I'm not seeing any add'l drain than I was before. :P

bobeast wrote:
Your message prompted me to look into this. I'm using an app called GeoMessage which IMO is easier to integrate than Find Friends. You can set up a rule in Mail.app to run an applescript, parse the message and tell indigo server to do whatever.An alternate approach would be to use the indigo mail trigger to run an applescript which then uses a mail.app tell block, to do the same. Either way, you'll want to parse the message with Mail.app since the Indigo mail trigger does not expose the message body to applescript.


Oh, wow, GeoMessage is just what I was looking for. Too bad you can't control the Subject, but yeah, moving over to this and Mail.app might be the way to go. Looks like GeoMessage lets you tightly control the emails' schedule, etc. - that's ideal. I will experiment with this and Mail.app and see what I can come up with. Thanks for mentioning this. How is the battery drain using this app?

EDIT: I grabbed GeoMessage, and my only complaint is that messages are sent a maximum of once per day when they involve a schedule. This is a pretty huge limitation. What if I come home from work, then an hour later go to the grocery store? Any automation surrounding my leaving home will not be triggered. Hopefully they will consider changing this in a future revision. I guess this, in combination with Find My Friends, might alleviate the problem, but using GeoMessage alone might not work for everyone.

Posted on
Thu Jan 17, 2013 8:37 pm
SpencerJRoberts offline
User avatar
Posts: 256
Joined: Dec 09, 2012
Location: Mountain View, CA

Re: An idea for presence tracking

richy240 wrote:
The triggers that relate to Everyone have a condition that checks for the presence of the other person. Two or three more people and this could get very complicated. ;)


I already have an "atHome" variable so the way my system works is that anytime someone leaves it checks to see if anyone else is home, if not it puts the house in "Away" mode. It's all done in applescript though, so adding people or other variables is pretty simple.

Especially when using a mail rule to trigger events instead of an Indigo schedule, as I said in an earlier post it's nearly instant. As I'm walking from my car to my front door it recognizes me, puts the home in "Home" mode, and soon (once I install the front door contact sensor) the house will greet us by name over the speakers :D

Posted on
Thu Jan 17, 2013 9:08 pm
richy240 offline
Posts: 111
Joined: Jul 08, 2012

Re: An idea for presence tracking

guitar486 wrote:
It's all done in applescript though, so adding people or other variables is pretty simple.

Will you elaborate on this? Maybe even post some of the code?

Posted on
Thu Jan 17, 2013 9:38 pm
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

Re: An idea for presence tracking

richy240 wrote:
EDIT: I grabbed GeoMessage, and my only complaint is that messages are sent a maximum of once per day when they involve a schedule. This is a pretty huge limitation. What if I come home from work, then an hour later go to the grocery store? Any automation surrounding my leaving home will not be triggered. Hopefully they will consider changing this in a future revision. I guess this, in combination with Find My Friends, might alleviate the problem, but using GeoMessage alone might not work for everyone.


Yeah. I just realized that as well. I'm tempted to write my own geo fence type app. So much code....so little time :)

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Fri Jan 18, 2013 8:48 am
richy240 offline
Posts: 111
Joined: Jul 08, 2012

Re: An idea for presence tracking

bobeast wrote:
Yeah. I just realized that as well. I'm tempted to write my own geo fence type app. So much code....so little time :)

I guess a workaround to this would be to create multiple schedules that kinda correspond to your potential movements (one schedule for leaving home in the morning and one for the evening), but that might be overkill unless you have really specific needs. For it simplicity I think Find My Friends is going to be my choice for location alerting for now. I LOVE how GeoMessage lets you set your radius though... I would certainly use it if it had more scheduling options.

I still want to play with Mail.app and see if I can get IMAP push working to improve response times and limit the server polling, but I haven't had time to mess with that yet.

Posted on
Fri Jan 18, 2013 10:31 am
bobeast offline
User avatar
Posts: 400
Joined: Apr 16, 2003

Re: An idea for presence tracking

richy240 wrote:
bobeast wrote:
Yeah. I just realized that as well. I'm tempted to write my own geo fence type app. So much code....so little time :)

I guess a workaround to this would be to create multiple schedules that kinda correspond to your potential movements (one schedule for leaving home in the morning and one for the evening), but that might be overkill unless you have really specific needs. For it simplicity I think Find My Friends is going to be my choice for location alerting for now. I LOVE how GeoMessage lets you set your radius though... I would certainly use it if it had more scheduling options.

I still want to play with Mail.app and see if I can get IMAP push working to improve response times and limit the server polling, but I haven't had time to mess with that yet.


I have reverted to Find My Friends as well, at least for the time being. Please let us know how the IMAP experiment goes.

Choose to chance the rapids.
Dare to dance the tide.

Who is online

Users browsing this forum: No registered users and 9 guests