After getting burgled a couple of of years ago, I set up a webcam, a Windows app called Yawcam, and Dropbox to set up a motion detection system that would instantly upload any photos of an intruder to "The Cloud". It was crude, but effective, but the one downside was that I had to leave the camera on all the time, so it did generate a fair amount of traffic. I recently looked at replicating this functionality on a Mac Mini in my lounge, but because it was in a high use area, I only wanted the camera to be active when no-one was home. With both my wife and I owning iPhones, I wandered wether I could somehow use their location to control the activation of the camera. It seemed like a promising idea, so I started planning a geolocation app that could communicate with the Mac to notify it about the movements of our devices.
Fortunately, however, I didn't spend too much time on it before I stumbled upon this great article which shows how to use the geofence feature in Find My Friends to control a home heater. I had no idea it had the ability to send an email to any address when you arrive or leave a location, but it was exactly what I needed to trigger my automated security system.
Step 1 - The Emails
I configured Find My Friends on both devices to send an email when we left, or arrived our home.
Step 2 - The Security Camera
As a proof of concept I went with iSentry - a free app on the Mac App Store which has the basic functionality I need.
Step 3 - The AppleScript
The script (Which you can find on Github) is the glue to hold it all together - it will be called whenever any emails from Find My Friends are received, and keeps track of the devices that are at home. When the last device leaves, it activates iSentry, and starts the camera. As soon as a device returns home, the script kills iSentry.
Step 4 - Mail
The final piece of the puzzle - you need to add a mail rule or 2 to call the AppleScript when Find My Friends emails arrive. See my previous post on sending iMessages for details on how to add these.
So far I've found the system to be fairly reliable, although I've had to play around with the sensitivity of iSentry's motion detection system to prevent false positives. The app has some nice features like the ability to email you when it detects motion, but time will tell whether it's up to the job, or whether a paid app will be needed.
The Find my Friends geofencing is not very precise (To help preserve the battery on your device), so it really works best if you travel a reasonable distance from your house: for instance it might not generate an email if you pop to the neighbours house in the same street.
You can also extend the script to do things like play tracks in iTunes depending on who comes home (which is already in the script), and in the future I have plans of using this technique to automatically send an iMessage to my wife, and play Gangnam Style really really loud when I leave work (I bought it for my kids, honestly..).
If you have any harebrained ideas of things you could do with AppleScript and geofencing, then put them in the comments, or send me a tweet.