Presence arrival using DHCPlisten possible?

Here’s a screenshot from Grafana of my presence over the last 14 days.

Can you guess when I got arping working right??

@rlkoshak - ah, I hadn’t given a thought to pushing from the phone rather than looking for it. I’d rather not have to install anything on the phones involved, but this does look like it would solve the problem nicely. Thanks for the idea and link

@rlkoshak @Confused - I thought the hping3 thread was iOS specific so will re-read that and also look more closely at how arp actually works. Pretty clear that if you get it set up right, it does seem to work based on that graphic!

Thanks for the info guys.

ARP stands for Address Resolution Protocol. When a device on the network wants to connect to another device on the network that it hasn’t connected to very recently it sends out a “Who has IP address” request. This goes out to everyone and if necessary the router forwards the request to its router. The device who has that IP address, or if the router knows that a specific device has that address, it responds with “MAC address blah blah blah has address”

What the hping3/arp and Network binding does is first send a specially crafted packet to the phone that causes it to partially wake up, and then it sends an arp “Who has” message and because of that first packet, the phone responds with “I have blah blah blah” and you know the phone is on your network. I’m pretty certain that specially crafted packet is a standard thing (like the WOL packets) which is why it works across iOS and Android.

But I have to say, it has been quite awhile since the last time I studied this stuff in depth. I may have said something wrong.

1 Like

As an update/info for anyone coming across this thread later:

I now have stable presence detection of android devices running Nougat 7.1.1, and LineageOS 14, and Apple devices on iOS 10.3.3 using the network binding. As pointed out by @rlkoshak and @Confused, arp just needs to be correctly configured.

Setup is on a Rpi3 using the openhab(2.2) image.
The installed arping tool did not wake the 7.1.1 or iOS devices, but did wake the LineageOS. The iputils-arping tool woke one of the 7.1.1 but not the other or the iOS device. This was based on ping and arping tests from the command line.

Updated the arping tool to v2.19-3 (was 2.14) - tested again, and all devices responded to arping after going into sleep mode, despite not responding to ping (as expected).

For network binding to work:
Added sudo nopasswd permissions using “su visudo” then "chmod u+s /usr/sbin/arping"
On the network things, increased retry value to 10, and timeout value to 20000.

Tested overnight and all devices stayed active for 12+hours. Based on the logs, it looks like the 7.1.1 devices can stop responding for 4-6 mins so a retry value of 10 looks reasonable.

Thanks for the pushing me in the right direction guys,much better solution.


Does anybody use the network binding successfully under Windows? Unfortunately there seems to be no recent arping implementation for windows and the current version of the network binding under Windows produces only wild fantasy states in OH (devices online which are not online for 2 days, devices offline which run 24 hours and so on).
My impression is that the network binding is at the moment useless in a Windows environment. Or has anybody better news and useful hints for me?

Updated the arping tool to v2.19-3 (was 2.14) – warcom

It sounds simple, but it took me a while to figure out how to do this. The thing is, the current stable version of openhabian (raspbian) has arping 2.14, and there is no simle way to upgrade to a newer version. So, for those who want to install arping v2.19-3, here’s how to do that:

  1. The *.deb package can be found at the Launchpad website. If you’re on a Raspberry Pi (like me), you’ll need the armhf build of the package. Download it to your Raspberry Pi like this:
  2. Once downloaded, the package can be installed as follows:
    sudo dpkg -i arping_2.19-3_armhf.deb
  3. That’s it, you can verify the version of arping by executing
    arping -v
    The output will be something like:
    ARPing 2.19, by Thomas Habets <>
    usage: arping [ -0aAbdDeFpPqrRuUv ] [ -w <sec> ] [ -W <sec> ] [ -S <host/ip> ]
              [ -T <host/ip ] [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]
              [ -C <count> ] [ -i <interface> ] [ -m <type> ] [ -g <group> ]
              [ -V <vlan> ] [ -Q <priority> ] <host/ip/MAC | -B>
    For complete usage info, use --help or check the manpage.

Goog luck!


Exactly my issue right now… Did you (or anybody) solve the Network Binding issue for Windows? I’m running OH on Win 10.

Hello, I have the same problem with my presence detection in openhab and tried the above steps to install the arping package. But I got an error while trying to install. Being a total noob in linux :blush: I don’t know how to proceed. Is it safe to uninstall the conflicting package? Don’t know how but i can google how to uninstall.

This is the output from the terminal:

[11:22:31] openhabian@openHABianPi:/sbin$ sudo dpkg -i arping_2.19-3_armhf.deb
Selecting previously unselected package arping.
dpkg: regarding arping_2.19-3_armhf.deb containing arping:
 arping conflicts with iputils-arping
  iputils-arping (version 3:20161105-1) is present and installed.

dpkg: error processing archive arping_2.19-3_armhf.deb (--install):
 conflicting packages - not installing arping
Errors were encountered while processing:
[11:22:43] openhabian@openHABianPi:/sbin$

I would really like to get this presence detection working, kinda is essencial in any home automation :sweat_smile:

Got it installed, I just went for it and removed the conflicting package. Then followed the rest of the steps. Now my onePlus stays online as long as i’m at home. :star_struck: But for some reason my wife’s samsung galaxy S5 doesn’t. Any ideas why?

EDIT: and just as i hit save edit my phone goes offline again :disappointed:

Modern phones will go to sleep and don’t even respond to arp pings for a few minutes. You need a bigger timeout window on your Things (like 5 mins or so). Or use a dedicated device, like a BLE enabled one.

The network binding is not the best presence detection anymore nowadays I guess.

Hy David,

Thanks i will try that.

Can you suggest a better strategy for presence detection? I plan to use motiondetectors based on “mysensors” that report to openhab via the serial binding, but I still have to develop these.

Either a BLE device, motion sensors or camera object/person recognition with openCV

Guess i better get working on those motion detectors

@jimmyalias if you have SNMP support on your network equipment it is possible to query the SNMP for network connectivity of your phone.

I have older Cisco equipment my work was going to throw out, but it should work for any SNMP network device it is just a matter of hitting the correct OID.

Wow, thats chinese to me. :laughing:

I will have to do a whole lot of reading and get back to you, but thanks for the suggestion

iPhone Presence Detection with hping3 and ARP might work for you. It uses a special ping to wake up the phone and cause it to respond with an arp.

I was under the impression that arping in the Network binding does the same but perhaps not. I use something like this and it has worked with iPhones, Pixel 2 XL and Pixel 3 XL.

Does it allso work with android phones? :thinking:

it has worked with iPhones, Pixel 2 XL and Pixel 3 XL.

Ok thanks, I will take a look at it tomorrow, its been a long day of programming and trying things out :sleepy:

Has anyone experimented with setting a 5 minute DHCP lease for mobile devices as a way to force a wake up? While it’s not super.high resolution, presumable it would be enough when coupled with a 10 minute timeout in the network binding to turn off lights/heating/music if nobody is at home.

Hi tried implementing [iPhone Presence Detection with hping3 and ARP]. I don’t get any errors but the script allways seems to return that my phone is present, even when it is switched off. Any ideas how i can further debug this?

this is the output in the log:

2018-12-27 09:33:00.164 [INFO ] [.eclipse.smarthome.model.script.RULE] - Iphone update

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

==> /var/log/openhab2/events.log <==

2018-12-27 09:33:00.176 [ome.event.ItemCommandEvent] - Item 'Iphone_Sw' received command ON

==> /var/log/openhab2/openhab.log <==

2018-12-27 09:33:00.210 [INFO ] [.eclipse.smarthome.model.script.RULE] - Iphone_Sw received command ON. Counter reset to 0

No idea where the admin lecture comes from either :laughing:



 #Enter your ip of your device here
DEVICES="my device IP here"

for i in `echo $DEVICES`; do
    # Change dev and eth0 if needed
    ip neigh flush dev eth0 $i
    hping3 -2 -c 10 -p 5353 -i u1 $i -q >/dev/null 2>&1
    sleep 1
    # Only arp specific device, grep for a mac-address
    status=`arp -an $i | awk '{print $4}' | grep "..:..:..:..:..:.."`
    #A mac will be 17 characters including the ":"
    if [ ${#status} -eq 17 ]; then
        echo "Phone $i is detected!"
        echo "Phone $i is not present"

The rule:

var Number IphoneCounter = 0
val Number MaxCounter = 18

rule "Execute script IphonePresence"
    Time cron "0 * * * * ?"
    var String IphoneExec = executeCommandLine("sudo@@bash@@/opt/", 5000)
    logInfo("RULE","Iphone update"+IphoneExec)

rule "Determine presence Iphone"
	Item Iphone received update
then {
	if(Iphone.state == "OFF") {
		IphoneCounter = IphoneCounter + 1
		if(IphoneCounter > MaxCounter) {
			IphoneCounter = 0	
			logInfo("RULE","Iphone  counter reached threshold and sent command OFF. Counter set to 0")
		else {
			logInfo("RULE","Counter Iphone threshold not yet reached. Counter set to " + IphoneCounter)
	else {
		IphoneCounter = 0
		logInfo("RULE","Iphone_Sw received command ON. Counter reset to 0")

ls -all looks like this:

-rwxrwxrwx  1 openhab    root        624 Dec 27 08:55

visudo last line (since i’m using openhabian):

openhabian ALL=(ALL) NOPASSWD: /bin/ip, /bin/bash

I do notice that where i inserted a logInfo in the first rule, that IphoneExec seems to be empty.

Sorry if i’m missing something stupid. Still got a lot to learn about linux :blush: