I’m often looking for ways to improve my home automation system. A few days ago, a post at Hackszine drew my attention to Jesse David Hollington’s article on Bluetooth Proximity Detection on Mac OS X. And more recently, Bruce Stewart wondered how else proximity detection might be used, with Jeff Harrell’s comment about the problematic range of Bluetooth, approximately 40 feet, echoing the problems I’ve had in trying to incorporate Bluetooth into my home automation system.
I quickly learned that using Bluetooth to determine if I am at home (as inferred by the presence of my cell phone) was simply not going work to my satisfaction. The problem was that if I wandered too far from my home office, yet still within my home, the Bluetooth connection would drop and my automation system would decide that I’d left. That’s not such a big deal if all this does is activate your password-protected screen saver; it’s a different story when it causes your home to completely switch operating modes.
Perhaps I should back up a little. One of the cornerstones of my home’s automation is that it behaves differently depending upon who is at home. For example, if someone is home at sunset, inside lights are turned on for them. If the house is empty at sunset, a different set of lights, and the porch light, are turned on instead.
During the middle of the night, if the system detects that someone is walking in the upstairs hallway, the lights in the kitchen are turned on very low, if that’s the direction they’re heading. However, if nobody is at home, and there’s motion upstairs, the house goes into full “intruder alert” mode!
This sort of thing isn’t hard to set up, and it starts to put the smart in “Smart Home,” but it only works correctly if the information about who is currently at home is trustworthy. Yes, it’s “garbage in, garbage out” all over again. I concluded that Bluetooth proximity detection, used for this purpose, would mostly result in “garbage in.”
But after finding out about the intriguing Home Zone application, I was willing to try it again, and this time I had a new idea. Instead of using Bluetooth to figure out if I have departed, I would use it only for determining that I have arrived.
I guess it seems obvious in retrospect, but this realization made all the difference for me. I’ve been playing with the idea for a few days now, and I’m quite pleased so far.
When I leave the house I press a button, located near the front door, that tells the automation system that I’m departing. This is similar to turning on an alarm system and is an easy habit to get into. (In fact, if I’m the last person to leave, it does turn on the alarm system. For full details on how all this works, see “Hack #70-Know Who’s Home” in Smart Home Hacks.)
Normally, when I arrive home I press the button again so the system knows I’m back. Now, I can eliminate that step by using Home Zone (or Salling Clicker , or Proximity, et al). This is accomplished by having the monitoring software execute the following AppleScript when my phone’s Bluetooth signal is detected.
tell application "XTension"
if (status of "Gordon Home") is false then
turnon "Gordon Home"
end if
end tell
This script works by asking XTension, one of the home automation software programs I use, if it believes that I am currently at home. (Represented by the variable “Gordon Home.”) If XTension already knows that I am home, the Bluetooth detection event has offered no new information, so it is ignored.
However, if XTension believes that I am gone, the detection of my phone’s Bluetooth signal is significant, so the variable that tracks my presence is changed. (Which causes other things to happen, depending upon the time of day and other conditions.) When I first got this working it was an almost magical moment; shortly after walking in the front door I heard my computer announce that I had missed four telephone calls while I was gone, and the lights in the entryway turned on by themselves.
For me, the key to successfully using Bluetooth to detect presence, for home automation purposes, is to track only the first appearance of a device, and even then, only in specific contexts. Inferring meaning from the lack of a Bluetooth signal is difficult; there are many reasons why a signal could vanish. But, the arrival of a new Bluetooth device is unlikely to be spurious, and it gives you concrete, actionable information that is easily incorporated into home automation routines.