Cart 0

Geofencing - Why you can't rely on GPS alone

Posted by LiveHouse Automation on

One of the most frequent gripes I see in the online forums is related to Geofencing and using it for presence detection (ie, is someone at home). People blame their "crappy" home controller, or the phone app but in reality the problem is inherent in GPS accuracy.

Point 1 - It's a bloody miracle it works at all.

Any sufficiently advanced technology is indistinguishable from magic. But it's not magic, it's physics. Let's take a little reality check. You have a device with an antenna smaller than your thumb that lives in your pocket which is triangulating signals from a dozen or so satellites that are about 20,000 km away from you. If you walked that far it'd take you to about the exact opposite side of the planet. 

And yet people are surprised when it's not 100% accurate (through a roof and probably your thigh) and sometimes says they've left home, when clearly they've been on the sofa watching TV the whole time. 

The problem here is one of user expectations, not technology limitations. 

Point 2 - Yeah, your expectations are unrealistic.

According to a global study of Smartphone GPS accuracy published in 2015, the average accuracy under an open sky is about 4.9m. That's pretty good, but it's an average. It doesn't tell us about the sometimes huge variations that can occur on a single measurement. It does mention that their accuracy worsens near buildings, bridges, and trees. Which let's face it, is pretty much where we are all the time unless you live in a tent in a field. In which case you're probably not a big Geofencing user anyway.

Officially, the GPS systems accuracy is expressed as "95% of the time". This means that any GPS reading is a roll of the dice and 1 out of every 20 readings is going to be wrong. Potentially way wrong. And potentially way more wrong and way more often due to:

  • Satellite signal blockage due to buildings, bridges, trees, etc.
  • Indoor or underground use
  • Signals reflected off buildings or walls ("multipath")

But don't take my word for it, here is some science I've done on the subject using my iPhone X's GPS readings loaded into InfluxDB and plotted with Grafana. This picture is my GPS coordinates reported over the course of a day, where I was in a city building and never left. Mostly sitting stationary at a desk.


The maximum error in my reported position was up to 150m. It looks like a map of lightning strikes rather than GPS coordinates as it rarely hit the same place twice.

This probably represents a worse case scenario. In the city, you've got lots of buildings and lots of reflected/blocked signals.


But the point is, if you expect that your GPS location won't change because you're busy forging your ass groove on the sofa, or that your presence status will be changed the moment you cross the radius you've set around your house, the problem isn't with your Home Automation system.

Point 3 - Fixing it is your problem. 

Look, technology is always going to improve in accuracy and reliability. The teams that write the software for our phone apps and automation controllers will find ways to filter out the spurious readings. However, these filters will be based on generalisations and compromises which may not work in all situations or may not suit the way we want our Geofencing to work.

At a bare minimum, you'll have one lever to pull - the Home Radius around your house where your controller determines that you're home or not. Set this to something realistic that will be within the margin of error for GPS at your location. Tip - it'll probably be something like 300m, not 30m. 

The ultimate solution is to take some ownership, look at what data our controller has to work with, and write our own rules.

Let's compare my day in the city, with the Sunday before where I didn't leave home all day.

That's what you want to see. I hadn't left the house, my location is fixed on a single point. GPS does not magically work with 100% accuracy at my house, but I can cross reference other data that my Vera has and write my own logic on how to interpret the results.

My recipe for reliable results - Multiple data sources and a dash of common sense.

Based upon what we now understand about GPS accuracy, common sense says we should stop using it when we're at home and replace it with some other way detect presence. The common alternative is checking for your smartphone on the Wi-Fi network, or using Bluetooth beacons but that's not 100% either. However, it does mean you're rolling the GPS dice a lot less often (and saving your phone's battery into the bargain). 

I'll run through how I have my Geolocation and Presence detection set up. Some of this is going to be specific to the devices and technology that I have in my home. But the concepts are the same if you want to elegantly handle the inevitable errors you'll get from relying on GPS alone. The focus here is on Home/Away detection, but I also use this setup to automatically unlock doors and open the Garage based on certain rules.

The Key components configured on my Vera are:

  • iPhone Locator Plugin - Amg0's excellent plugin that allows your Vera to talk directly to iCloud rather than relying on an app running on your iPhone. It also gives you easy access to Speed, Distance, Previous Distance, Present Status and a Mute option to stop the GPS polling.
  • Program Logic Event Generator (PLEG) - RTS's plugin that lets you do advanced logic without writing actual program code.
  • Unifi Sensor - I wrote this plugin to talk to my wireless controller directly rather than Ping phones (which may be asleep) on the network. This is more accurate than the Ping Sensor Plugin, but the idea is the same in testing to see if a device is on the local network.

Now on to the logic and rules of engagement for presence:

  1. When Unifi Sensor detects the iPhone AND the iPhone Locator shows Present - mute the iPhone Locator. In other words, stop checking the GPS because we are definitely at home.
  2. When Unifi Sensor stops detecting the iPhone - unmute the iPhone Locator and poll the GPS. This means we've left, or if the Wi-fi detection has messed up, we'll confirm via GPS that we're still home or not (greater than 95% chance it'll be right, I use a 200m radius) and the Wi-Fi detection will kick back in anyway and Rule #1 applies. 

I've been using these two simple rules for quite some time now, and in the year since I wrote the Unifi Sensor, I've had 100% accuracy for being at home and it has never reported me as having left when I was still at home. Accuracy was a little less when using the Ping Sensor as the phone would be detected as away more often due to being 'asleep'.

If you don't have the capability to check for a device on the wireless network, you could combine other data from your automation controller. Motion sensors can  validate whether someone has been at home recently, or if no one has opened a door sensor since arriving home you can assume they haven't left.

Locks and Garage Doors - Higher Stakes needs more Logic and Data Points

You don't want a GPS accuracy issue to be unlocking doors randomly and you want the garage to open when you pull in the driveway, not when you're 5 minutes away, and not when you're sitting in the car trying to get your phone out of your pocket.

The logic I have around my Garage doors is pretty complicated as it has to deal with 2 people with iPhones who may or may not be in the same car. This involves using timers that get triggered and checked to make sure we're not trying to open the garage if it's recently been activated.

I'll keep it simple here and look at the logic for a single device. The key to this being able to use Speed as a condition as well as Current and Previous Distance readings.

Open the Garage Door if the following conditions are ALL true:

  1. Your Current Distance is Less than Previous Distance (you are recorded as actually approaching home)
  2. Your Current Distance is Less than 0.5km
  3. Speed is more than 10km/h and less than 80km/h (I'm moving at car speed and not walking the dog. It also filters out inaccurate GPS readings. I've seen speeds of 1100km/h due to jumping around).
  4. You haven't been recorded as Present in the last 3 minutes. (So you've been off the Wi-Fi, and more than 200m away from home for at least 3 minutes and haven't just GPS jumped around).

That's the core of the rules. I also have another detection radius where rule #2 is: Greater than 0.5km and Less than 0.9km which delays opening the garage by 15 seconds as it's picked me up a bit further away. I've been using this logic for many years now and it's proven to be very reliable in practice.

Wrapping it up.

Hopefully this has been enlightening on why complaining about the out of box Geofencing experience you get from your Home Automation controller/App is only ever going to get you so far - GPS is (at least for now) inherently unreliable and you need to cross reference other information before you get your controller to act.

One day, Artificial Intelligence or Machine Learning might be able to do this for you. Until then, you know your home, movement patterns, roads around your house better than any computer - use that knowledge to your advantage.

Happy Automating!


Share this post

← Older Post Newer Post →