Breaking down Presence Detection with Home Assistant

This is a complementary post to the Home Assistant Podcast Spotlight episode on Presence Detection. You can listen to that episode here, and check out Rohan’s Presence Detection here.

When it comes to Home Automation, your home needs to be smart enough to know if the home is occupied or not. This falls under the term of “Presence Detection”, and there are many options available when it comes to detecting presence. Today I’m going to explain some pros and cons of the presence detection I’ve personally used, and some things I’ve learned along the way.

Before we get too carried away though, let’s first talk about why presence detection is so important.

If you’re just starting out with Home Assistant, or perhaps Home Automation in general, detecting presence can easily add some wow factor to your smart home. Before there were smart homes, the smartest way to make your home automated was with cheap plug-in timers. These could easily turn on and off lights or appliances, but only based on a time schedule. That means when you’re working late one night, or you’ve gone away for the weekend, your lights would still turn on and off at the chosen time. Those plugs aren’t smart enough to know that nobody was home, or you’re burning the midnight oil.

Now with modern day technology, and everybody carrying a GPS in their pocket, our homes not only have the ability to detect when someone is home, but also who is home.

This allows for smart homes to adjust to who is home, and what time of day it is. Perhaps if you’re home alone by yourself, the house will ensure the external doors are locked, and your favourite Spotify playlist is playing on your Sonos speakers. If everyone in the house is home, then maybe the Nest Thermostat is set to a more diplomatic setting.

Detecting presence however can be a series of trials and errors. It sounds cliché, but no two smart homes are the same, and what works in one smart home to detect presence may not be very reliable for your smart home. There are many factors that come into play here. From the physical size of your house, to the brand of phone you may or may not have in your pocket.

The most common presence detection methods are based on your phone. So let’s start with those.

 

The Latest In Your Inbox

Enter your email address below to receive my latest blog posts and videos about Home Automation in your Inbox

 

Bluetooth

If you’re in a relatively small home, detecting presence with Bluetooth can be one of the most reliable ways to detect who is at home. The great thing about detecting presence with Bluetooth, is that it doesn’t require your phone to be paired with a device. Just simply having your phones Bluetooth turned on is enough for Home Assistant to scan and detect that your phone is close by.

This can also work out great for guests, as they don’t need to pair or join a network for you to detect when they are home. You will need some way to identify their MAC address/unique ID though.

Bluetooth works great for small spaces, like apartments/condos. Bluetooth has a small range, which can easily be impacted by walls and other obstructions. If you have a larger home, your smart home may not be able to “see” that you’re still home when you’re playing hide-and-seek in the closet.

If you want to get whole-home coverage with Bluetooth, you may be able to spread a few Raspberry Pi’s around your house, then use something like Room Assistant. This will allow you to track where in the home your phone/device is. It is designed to be used to know which room of the house you’re in. However it assumes you’ll always have your phone/device with you. So if you leave your phone in the bedroom to charge, it won’t be able to tell Home Assistant your in the living room.

 

WiFi

Similar to Bluetooth, WiFi allows your smart home to detect who is at home based on what devices are connected to your WiFI network. This does require that your phone or device has WiFi turned on, and connected to your WiFi network.

WiFi signals can reach further than Bluetooth, and if your home uses WiFi repeaters or the like, you could easily have your entire home covered by WiFi and thus, this form of presence detection would be available all over your home.

In Home Assistant, there are a couple of different ways you can use WiFi to detect presence.

Router
If you’re using a supported brand of router, then Home Assistant can login to your router to detect which devices are connected to it. This allows the router to determine which devices are connected or not, and doesn’t need Home Assistant to work it out. This means less resources Home Assistant has to use.

NMAP
NMAP is an open-source security scanner, which scans your local network to determine which devices it can see. This method will require Home Assistant to scan your network once every few minutes to determine which devices are connected.

Ping
Similar to NMAP, a ping is a short data packet which is sent across your network. You’ll need to have your devices set to be assigned a static IP address in your router. Once set, you can tell Home Assistant to send a ping to your device every few minutes, and if your device responds to the ping, Home Assistant will know you’re home.

 

The “Consider Home” Setting

There’s one thing to watch out for when it comes to WiFi and Bluetooth though. Depending on the brand and model, your phone or device may put itself to sleep to conserve battery. This is particularly a problem for iOS devices.

Home Assistant has a setting called “consider home”. This setting allows you to define the number of minutes Home Assistant should wait before it marks you as away.

Let’s assume your phone connects to your WiFi router. Home Assistant will immediately mark you as home. After a minute, your phone puts itself to sleep, and disconnects from the WiFi. Now, Home Assistant will mark you as away (and turn everything off, if you have that as one of your automations). This process will repeat on and off, and get annoying very quickly.

Now let’s set the “consider home” to 10 minutes. When your phone disconnects from the WiFi network, Home Assistant won’t mark you as away, until your phone has been disconnected for more than 10 minutes. For this to work the best, we’re going to assume your phone will wake itself up every 5 minutes and re-join the network to get any updates. You’ll need to do some trial and error to see how long your “consider home” setting needs to be for your particular devices.

 

GPS

Another great feature with smart phones, they all come equipped with a GPS chip. Not only is this great for turn-by-turn navigation, you can expose your location to your smart home, so it knows exactly where on the planet you are.

This opens you up to some powerful automations. Now, your smart home can know when you’re at the supermarket, or when you’re at work. It can also detect when you’re on the way home, and how far away you are from home to determine if it should turn the heater on to warm the house for your imminent arrival.

Once again, GPS has some pros and cons depending on the brand of your device. iOS devices like to force background apps to go to sleep, so you might run into trouble with those devices. Depending on the app you choose, GPS may also drain the battery on your device quicker.

If GPS is something you’re wanting to look at, then you should take a look at the Google Maps and OwnTracks components in Home Assistant.

 

Alarm Panels

So far all the sensors above have been related to your smart phone. What happens if your phone battery is dead, or you’ve dropped it in your coffee and it won’t turn back on? You’ll eventually get to a point in your smart home addiction where it will become hard to function like a normal house. You’ll arrive home, and expect lights to come on automatically. but they won’t because Home Assistant won’t be able to “see” your device. You’ll quickly discover the downsides if you’ve automated a siren or something to make noise as a home-made security system.

This is where a manual override is a great option.

Home Assistant comes with support for a few different alarm panels. You can easily make one yourself using an old Android phone, and then have it use MQTT. I’ve done something similar using an MQTT Alarm Panel, a FireHD tablet and the Lovelace Home Assistant UI.

 

 

These alarm panels, either software or hardware based (like this z-wave model), allow you to enter a code, and then disarm the system. In my case, I have a sensor setup so that when my Lovelace alarm panel is disarmed, my house is put into home mode. Whenever a trusted device joins my network (mine or my wife’s phone), the alarm panel is disarmed.

This gives me a backup option. In the event I or my wife arrive home, and our phones won’t turn on, we can walk up-to one of the Fire HD tablets, and then enter a code in the Lovelace UI. Once that code is entered, the house immediately knows someone (it doesn’t know who though) is home, and then carries on as normal.

I’m sure you can already see the benefit of this for yourself. But consider other users of your smart home as well. Guests who haven’t joined your WiFi network. The cleaner who comes once a month and doesn’t want to clean in darkness.

 

Combining Multiple Sensors for Accuracy

There’s many more types of presence detection you can use with Home Assistant. In-fact at the time I wrote this, there were 47 components in Home Assistant for presence detection alone.

For that reason, it makes sense that you might find it even more powerful, and more reliable to combine many of these sensors, then use that information to determine who is home or not.

 

Groups

If you’ve got multiple device trackers set up, you can place them into a group to determine when you’re home or not. Let’s create a group in Home Assistant.

This should be pretty straight-forward. Here I’ve combined my presence sensors for the Bluetooth and WiFi connections of my phone. Now, if either my phones WiFi or Bluetooth is seen as home by Home Assistant, the group group.phil will be marked as “home”. If both of the devices are marked as “not home”, then the group will be marked as not home.

This is great to combine multiple types of presence. You can extend this from your phone, to things like a camera reading your cars license plate in the garage, then the group will be marked as home as well.

You could also extend this to “types of people”, and allow your smart home to adjust its settings based on the type of people who are currently home.

Now your smart home can detect when a friend is over at your house by looking at the group.friends entity in Home Assistant. Neat!

 

Bayesian Sensor

Now it’s time to get a little bit fancy.

In the example above I mentioned that you could have a camera checking to see if your car is parked in your garage, and if it is, mark you as home. That’s great, assuming you’re always home when your car is at home.

What happens if you decide to take public transport to work one day? Or you’ve gone for a run around the neighborhood. Your house will think you’re home, because your car is still parked in the garage, even though you’ve taken your phone with you. This is where we can let Home Assistant work out how likely it is that you’re home, based on different sensors it can see in your house.

A Bayesian sensor is a binary sensor (so it is always either on or off) that works out the probability of something being true, based on certain states Home Assistant can see. It uses Bayes’ theorem to calculate, which I won’t go into detail here.

Let’s assume I have the following devices setup in Home Assistant, which track whether I am home or not.

  1. WiFi on my phone
  2. My car’s GPS location
  3. A BLE beacon attached to my briefcase

Using these device trackers, we can teach Home Assistant the probability that I am home, based on what sensors are home. In the ideal scenario, all of the device trackers above are seen as home by Home Assistant, and the Bayesian sensor is marked as on, because everything is home. Now let’s mix things up.

Let’s say my car is in the shop getting repaired. However, my phone and my briefcase are home. Using the right probability settings, Home Assistant would be able to determine that I am probably at home, and hence mark me as home.

Now let’s assume my phone and car are not at home, but I’ve left my briefcase at home while I go away for the weekend. Once again, setting the right probability settings in Home Assistant, I am probably not at home, so things can turn off as expected. Had I just been using groups, the fact that my briefcase is home would have been enough to make Home Assistant think that someone was home.

 

Going Further with States

Presence detection in Home Assistant can easily become a way of saying “home” and “not home”. However, there might be some situations where you want to break this down a little bit further. If you want your house to be able to determine when you’ve “just arrived” or “just left”, or you’ve been away longer than usual, check out my blog post Making Home Assistant’s Presence Detection not so Binary.

I’ve found it a great way for my smart house to automatically activate vacation mode, or start playing music when I just arrive.

Recommended Posts
  • Roger Heward

    There another powerful way that I use in my system. It’s a combination of motion sensors and door sensors. When a door is closed, the sensor shows as “away” until a motion sensor is triggered, and it’s then marked as “home” until the next time a door is closed. This doesn’t tell you who is home, but someone must be. This stops my system from turning off the heat when a babysitter is taking care of my daughter, but we’re out for the evening.
    We don’t use it in isolation, we also have Bluetooth and nmap for our phones, but this gives an additional safeguard against showing the home as unoccupied when we leave someone else there, or when our phones might be off for some reason. And doesn’t require us to manually add every guest to our configuration.

    • That’s very interesting!

      For security, does it work in the inverse? So if a door opens the house gets marked as home? If that’s the case, then the only downside would be that you then can’t use Home Assistant as a security system, as anyone who comes through a door would “disarm” home assistant when it marks the status as home.

      • Roger Heward

        My presence panel shows 3 “people”, my wife, myself, and “unknown person”, (based on motion detectors and doors) any of them being home show the house as occupied, but if unknown person is triggered without one of the others at home I get a single notification which I can then investigate further if it’s unexpected. No real downside to turning on the furnace and water heater for a burglar (bigger issues to deal with). And a light coming on might just help scare them away.

        Worst case I get notified each time the babysitter opens the door while I’m out for the evening with my wife, but that also means I’ll know if they invite friends over instead of just taking care of my daughter.

  • Miles

    Hi Phil
    I’ve been using just plain ol WiFi presence detection using the unifi tracker for a while, I want to add bluetooth to the mix, but it’s kind of a nightmare since I’m using HA in a docker in unraid and unraid doesn’t have drivers for bluetooth built in so I can’t pass through my dongle.

    I’m using your not so binary presence detection for a long time and love it, my question is, how do you think I should go about adding bluetooth presence detection when I can’t add bluetooth to my HA instance?

    My thoughts were to use a mqtt topic or something similar but I don’t think its possible to combine device_tracker and sensor components together to be used for device tracking.

    Any input would be greatly appreciated!

    • Hey Miles,

      Interesting! If I were you, I would check out a repo called Room Assistant. It uses Bluetooth and then publishes to an MQTT topic. The MQTT topic I think is then added to home assistant which you can use in a group, like I’ve done here.

      Just because it is room assistant, doesn’t mean you can’t use it to track your whole house though, assuming Bluetooth is strong enough.

      Cheers

  • friends:
    name: Friends
    entities:
    - device_tracker.george_iphone
    - device_tracker.steph_bluetooth
    - device_tracker.annie_car

    Does this mean that all three have to be “home” for “group.friends” to be marked “home”

    • Nope! Groups will treat them as an OR. So as long as one device_tracker is marked as home, the group will be marked as home.

  • Hey,

    Person should be pretty similar to device tracker or groiups, so all you should need to do is change the entity ID from the device tracker or group to person, and it should work as normal.

  • Jay Sprenkle

    On my PC the blog font is small and the contrast is very low. It makes it quite difficult for older people to read.

    • Best to check your settings. I myself don’t have the best eye sight, so I’ve set the font size larger than most websites and blogs I come across for that reason. As for the contrast, this is something that the theme sets for me.

  • Chris

    I just Google’d “wifi mesh triangulation” and found a few really interesting things. Mesh routers spread throughout your home so there’s not one access point, but many. This, in theory, can be used for pretty precise triangulation. May be worth looking into.

  • Barclay

    When you say installing multiple Raspberry pi’s around your house and using home assistant. Can you explain that a little more? do you put home assistant on all the extra pi’s?

Start typing and press Enter to search