How to Implement Presence Detection With OpenHab

Presence detection is the ability to detect who is home at any given time, this piece of information is crucial for every Home Automation System,  it allows you to customize every gadget to the taste of every member of the family. Implementing presence detection can get very sophisticated but you may want to start with something simple and improve it over time. Today, I want to walk you through the simplest and quickest way to implement presence detection with OpenHab.

If you are not yet familiar with OpenHab I suggest you check this post:  First Steps with OpenHab and Home Automation.

Let’s get started!

Requirements of your Presence Detection System

Like for every new functionality, you need some kind of requirements gathering before starting your implementation. I want my Presence Detection system to be able to do at least the following:

  • Provide information when a given person arrives or leaves the apartment.
  • Monitor at any time who is home.
  • Having an indicator that tells me if there are people at the apartment.

I know! It is very simple…but you have to start with something, don’t you?

Proposed Solution

You might be thinking…let’s put motion sensors all over the place!

Or you might just be thinking that you are hungry…who knows…

Anyway, motion sensors are not always a great idea and here are the reasons why:

  • They can tell you that there is someone at home but they can’t tell you who that person is.
  • I share my apartment with pets, a crazy cat and a crazy dog, and motion detectors go nuts with things like the cat jumping around the apartment.
  • For my first approach to presence detection with Openhab, I want to keep it simple and avoid buying new gadgets.

Ok, so no motion sensors ruled out…

What is it going to be then?

One of the things that distinguish ourselves from our pets is that we have smartphones and they don’t,  in most cases at least…

The first thing that your smartphone does when you get home is connecting to the WiFi.  At this point, you were probably able to join the dots…

That’s right! we are going to detect who is home by checking phones connected to the wifi.

Let’s get down to business then…

Beginner’s Guide to Implement Presence Detection with OpenHab

Assign Static IP’s to the devices you want to Track

This is the kind of thing people often forget therefore I have decided to put it in the first place. Every device that you want to track must have a static IP, otherwise, the next time that you restart your router it will mess everything up.  Pretty much every router allows this setting but the setup will be slightly different for each router.

I can’t really cover every single router so I think it is best to leave this part for you to investigate.

Install and configure the Network Binding

In order to monitor the devices connected to the network, we will use the OpenHab Network Binding. The installation and configuration is pretty simple but I will leave you a few screenshots.

1. Open the PaperUI and go to the addons section. 

2. Look for the Network Binding and click on Install.


Presence Detection with Openhab - Install Network Binding


It will take a few minutes. After the process is done, you can go to your inbox and see what your new binding has discovered.

3. Create Things for the devices you want to track

If you go to your PaperUI Inbox you should see all the devices that the network binding has discovered.

Presence Detection with Openhab - Inbox


Among the new devices, you will see the static ip’s of the smartphones that you want to track. If you don’t see them, run the discovery process again.

Once you have identified the static ip’s you can create things for the devices that you want to track by clicking on the tick iconRepeat the process for all the devices you are willing to track before moving to the next step, normally one per person you want to keep track on.


Presence Detection with Openhab - Create Things


4. Create a group of items

At this point we should be able to track every device separately however, most of the times we only need to know if there is somebody at home. We don´t need to know specifically who that person is.

–  How can you do that?

–  You could ping every single device one by one until you find one that is online!

– Sure, that would work…it is a bit painful and rather difficult to maintain though.

Instead, we are going to use a group item. Every time that you want to add a new device to your household you only need to add it to the group. Easy and low maintenance 🙂

Edit one of your items files under /etc/openhab2/items/ and add the following content:

The status of the group will be ON if any of the smartphones in the group is connected to the network.

The group will allow you to know if there is somebody at home for general rules,  but you will still be able to trigger different actions by a person (device) detected, you’ll have the best of both worlds.

5. Create Items for the phones you want to track

From the Things menu, click on the thing that you want to track the status for and link a new item to the channel online.

Presence Detection with Openhab - Create Things 2


Presence Detection with Openhab - Link to Online Channel

Presence Detection with Openhab - Create a New Item


As part of the definition, make sure you add the item to the group defined in the step 4, gPresence.


Presence Detection with Openhab - Item Details


Repeat this step until you have an item for every device that you want to track.

You presence detection with openhab is ready to be used.


If Openhab doesn´t detect that your devices are online or produces unreliable results, check the following tips:

1. Make sure that you are looking for the right IP’s.

2. Make sure that the device is online using the following command in SSH.

** Replace the interface and the IP address of your particular case. Run ifconfig if you don’t know the name of your interface.

3. Make sure arping is installed

Let’s see what can you do with it!

Presence Detection with OpenHab in your Sitemap

One of the things that you may want to do is to show in your sitemap who is home. Sitemaps are one of the features available on Openhab to interact with your Home Automation System. If you are not familiar with it you can learn more about it here OpenHab Sitemaps.

Here you can find a simple example of how you can do that. You need to replace the name of the items by the ones that you have created in the step 5.



Presence Detection with Openhab - Sitemap 1



Presence Detection with Openhab in your Rules

There are tons of use cases to use presence detection in your rules, I’ll give you a very simple one.

One of the coolest things about Home Automation is that it helps us saving energy by optimizing the use of resources (lights, temperature, water…). If you want to know more about this topic check 8 Ways to Save Energy with Home Automation.

The key for optimization is to design rules that adapt your smart home to your lifestyle.

One of the things that I used to forget 9 out 10 times that I left the apartment is to shut down the AC or HEAT. This results in wasted energy and money. Here is a simple rule to turn off the AC/HEAT when you leave your house or apartment.


This is only a starting point but I hope you found it useful.

Where else you think that Presence Detection can help you? Do you have any other ideas on how to detect presence? How do you use your presence detection system? I would like to hear all your ideas.


This Post Has 9 Comments

  1. Mkjn72

    Thanks for publishing this tutorial, was helpful. I successfully recreated your results with things, creating items+groups and a sitemap display. Only thing is, after some time (say 15 mins) when my phone goes to sleep it is signalled as being ‘away’ 🙁 . How did you manage to keep a connection active even when a phone is in standby mode? I checked my phone, and it has ‘keep wifi alive even in sleepmode’ setting, but clearly this isn’t the case..

  2. David C.

    Hi There!

    Accurate presence detection can be very challenging sometimes. There is a known issue with iphones when they go into deep sleep.

    Are you using iPhone?

  3. Markus S.

    Proper presence detection is a challenge indeed.
    Check out my presentation on presence detection from last year’s Smart Home Day at to find various use cases and solutions to be discussed, network binding as you suggested being one of them. Yes the Audio quality isn’t the best possible but it’ll help you understand the slides 🙂

  4. MNB

    Thank you so much, i hope you keep on giving tutorials on OPENHAB.

  5. David C.

    Thanks for the feedback!! I will definitely keep doing it.

  6. DawieDB

    Thank you very much for a great tutorial, you have no idea how much time you saved me. Looking forward to your next tutorial….

  7. David C.

    Thanks for the feedback Dawie! Don’t be a stranger!

  8. Peter

    what if you’re on a public network ,
    Can I even connect to a public network with a static ip?
    Why not a presence detection based on the mac id, that’s unique for every device and does’nt change any time.

  9. David C.

    Hi Peter,

    MAC ID is also an option. Is this the way you have implemented it?

    I wouldn’t tipically put my Home Automation System in a public network but yes, you can setup a static IP as long as it it not within the DCHP range of the router of that public network.

Leave a Reply