Using iBeacons with SmartThings
@DavGlass made a “proof of concept” smartapp for me that allows me to use an iBeacon to flip a SmartThings switch on or off.
Since this could be a virtual switch, it can also be used with the Big Switch for Hello Home Actions to do all kinds of stuff. Or used with IFTTT.
Or, of course, if you want to modify the code, this proof of concept can be used as the basis for many different SmartThings interactions and much more complex smartapps.
The POC SmartApp only asks for the detection range you want to use, and the switch you want to turn on or off. You can get it from Dave’s GitHub:
My very deep thanks to Dave for working this up for me! It has immediate practical use in my house, and I’m sure will be the basis for many other creative solutions for other people.
What You’ll Need
SmartThings hub
One defined SmartThings switch (can be virtual)
One iBeacon (we tested with both GeoHopper and Estimote)
The Beecon+ iOS app or another beacon app that can do http POST
AN INTRODUCTION TO HOW IBEACONS WORK
If you’re already using iBeacons, you can skip all this. If you’re not, read it before setting up your use case, as they probably don’t work the way you expect.
iBeacons are not proximity detectors. Those do exist, typically triangualated infrared, but that’s not what iBeacons are.
The usual metaphor is a lighthouse, which is a good one, but you need to really think about that for a minute.
All an iBeacon is is a tiny very low power transmitter that keeps sending its own ID out. That’s it. (OK, there are some that are also temperature sensors, but forget that part for a minute.) They don’t send a message. They don’t know what receivers have detected them. They don’t run any other code. They just send out the “Beacon 123456789” identifier over and over.
So you need a “receiving station” that will recognize that an iBeacon is transmitting, get that ID, and know what to do with that specific ID. The receiving station is an app that lives on your phone. Not a SmartApp. Not the ST hub. Just a regular app. An app that has been set up ahead of time to recognize a specific iBeacon’s ID.
RANGING
The receiving station is going to recognize the iBeacon ID as one it’s been set up to process, and the first thing it’s going to do is “range” it–determine how far away it probably is based on the strength of the signal it receives. (Not the strength of the signal the iBeacon is sending–that’s always the same. It’s just a lighthouse, remember. But the receiving station is going to guess whether it’s close to the lighthouse or far away based on how strong the signal is at the receiving point.)
Based on the standard, the signal will be ranged as: “Just entered into range,” “far” (typically about 30 meters) “near” (typically about 3 meters), “immediate” (typically within a few inches) or “just went out of range.”
Notice that there are two event ranges: (entered into range and went out of range) and three presence ranges (far, near, immediate).
There is no range value for “just left immediate range and is now in near range.” If it’s near, it’s near, whether its previous range was far or immediate.
Also–a lot of things can affect the perceived distance, but usually it’s something that interferes with the signal so it seems weaker (farther away) than it really is. Rain will also interfere if your phone or the iBeacon are outdoors.
And remember the iBeacon itself doesn’t do anything except broadcast its ID. If your receiving station app isn’t monitoring for it, or your phone is turned off altogether, nothing will happen.
THE RECEIVING STATION APP, AND WHY WE USED BEECON
All receiving station apps can recognize an iBeacon’s ID (although not all brands are detectible by all receiving station apps) and range it. Now what? That just depends on the app.
For example, the Geohopper app is designed as a notifier for individuals getting to and from locations. LIke a college student letting their parents know they arrived back at the dorm or a person working in an office letting their family know they just left the office.
It provides two basic action triggers: entering or exiting range. You can then set it up to email someone, or post to an RSS feed. It has an extra fee webservices option, but it’s still only on enter or exit.
The Beecon and Beecon+ apps from Beacon Sandwich, which are designed for home automation use cases, offer a different set of choices. You can set it up to tweet. You can have it send a post or get request to a web service. Or it can directly control some home automation brands, notably Philips Hues, LifX, iTach (IR) and some WeMo devices.
Remember the iBeacon itself just says “Here’s my ID.” It’s the Receiving Station app on your phone that does whatever comes next based on its recognition of that specific ID.
And now Beecon’s big advantage for home automation: you can set the actions to occur for any of the 5 standard ranges: just came into range, just left range, immediate (which they call “very close”), near, and far.
Unlike many receiving station apps, iBeacon also lets you set a custom distance, which is very useful for home automation. Just remember that this is a measure of signal strength, not real distance, so allow for some variability. But it’s very useful when you want to limit an action area to something a little smaller than just “near.”
One technical limitation: due to various issues with the iBeacon standard, you’re allowed to have one iBeacon trigger for one distance plus exit, but you can’t have one action for Near and a different action for Very Close on the same iBeacon. So you may end up needing more iBeacons than you first expect.
The Beacon Sandwich app costs $1.99 for the basic Beecon, and $8.99 for Beecon+. See their website for the differences.
There are some other technical reasons for why we like Beecon+, including its ability to distinguish between regions and beacons and its resiliency in dealing with overlapping beacons, but that’s getting a little far off topic here. Just look up iBeacon app reviews, they mostly say the same things.
THE IBEACONS
There are about 5 major brands for iBeacons right now, but for home automation I would recommend two at this time. Both can be managed with the Beecon receiving station apps.
- Geohopper, a USB plug in with a wall plug. List price is $40 but usually costs about $25 on Amazon and comes with a free set up app.
http://www.amazon.com/Geohopper-iBeacon-with-Power-Supply/dp/B00N17AU4K
- Estimote, the most popular iBeacon brand. Comes in a “developer kit” of 3 battery powered ibeacons for $99. Free SDK if you want to write your own iOS apps. Free set up app that you will likely only use for things like modifying the ID the estimotes broadcast.
(They also sell “stickers” at 10 for $99, but those only have one reporting range, 10 meters, and are not standard iBeacons so won’t work with many receiving station apps. I don’t know if they could be integrated with ST or not.)
The batteries on a standard Estimote should last several years in most homes, and the estimotes can be cut open if you do want to replace the battery.
You can also use a mix of GeoHoppers and Estimotes with the Beecon receiving station apps. The Geohopper is slightly cheaper and mains powered. The Estimote is slightly more expensive, can be put anywhere, handles overlapping ranges well, and has an SDK for if you want to write your own iOS apps.
MAKING THE SMARTTHINGS CONNECTION
OK, I tried pretty much every built in option for iBeacons to SmartThings integration, including all the options using IFTTT as a “man in the middle,” but nothing worked smoothly enough. The iBeacon recognition was perfect for weeks, but getting the message to ST was lagging too much.
So Dave Glass said, “Beecon+ has a POST method, let me see if that works.” 10 days and several iterations later, I can confirm that it does.
His smartapp asks the user to specify range, on or off, and switch to control. That’s it. Since this is just a proof of concept, right now you need one instance of the smartapp for each beacon. And it’s only set up for switches, although you should be able to modify it for other devices.
GOOD THINGS ABOUT IBEACONS
-
iBeacons should be both fast and reliable for geofence detection in small ranges. Excellent for “car in the driveway,” “person at the front door,” or “person in the living room.” And with Beecon+, you can define a custom distance as well.
-
Unlike a motion detector, you can set detection for a specific person, so there’s no way a dog or cat can set it off, for example. You can also have it work differently for homeowner vs house cleaner, or parent vs teen. This is particularly helpful for me, since I have a service dog. I can send the dog to get something near the iBeacon knowing he won’t set off the event the way he might with a motion detector.
-
And you should never get a false positive from an iBeacon unless your phone went dead and then was recharged, something you’d probably be aware of. Gusts of wind, afternoon sunlight, and air conditioners won’t trigger an event.
-
unlike a motion sensor, an iBeacon has an actual “exiting” event. So you don’t have to worry about the off event triggering too soon. It’s not based on time, it’s based on you actually moving out of range of one iBeacon (or into range of another).
SOME NEGATIVES ABOUT IBEACONS
-
every use case depends on you either bringing the phone near the iBeacon or bringing the iBeacon near the detector (which could be a tablet). So it’s definitely not as good as a regular proximity switch for the “Very Close” distance use cases. If you forget your phone in the living room, it won’t trigger the iBeacon in the bedroom. And your phone has to have been set up with the receiving station app first, so it’s unlikely that iBeacons will work well for visitors.
-
they don’t toggle for distances other than “out of range.” You could certainly have your lights come up when you to the house and turn off again when you leave. But if you want to use them for Very Close switches, you need one for on and one for off. Or have a metal box to drop over it to force it “out of range.”
-
They don’t work great with Android. iOS detects iBeacons at the operating system level, which is both easier on the battery and means the receiving station app can be set to work even when it’s closed. Android’s native functionality requires that the receiving station app be open in order to detect the beacons. I don’t know what other options there are for this, but it’s no coincidence that Beecon is only available for iOS.
-
If your phone goes completely dead and is then recharged, it will be treated as an Arrived in Range event. Just something to be aware of.
-
They’re not cheap. If it takes two to handle the on and off conditions, that’s fifty or sixty dollars. Since I’m quadriparetic, there are a lot of use cases where that’s worth it to me, but for many people, the primary justifiable use will be at the geofence border for arriving home/leaving home use cases where you’ll only need one.
-
As of this writing, May 2015, they aren’t detectable by smart watches, only phones and tablets. The Beecon+ app does have an apple watch version, but while it lets you launch actions manually, the watch itself doesn’t have the receiving station. So the range is always relative to where the paired phone is, not the watch itself.
-
depending on exactly how you set it up, it may use too much battery on your phone. There are a lot of options to play around with, but again something to be aware of.
SUMMARY
Dave’s proof of concept definitely works, so if you’re interested in using iBeacons with SmartThings and you have an iOS device to host the receiving station app, you’ve got a good jumping off point. Have fun!