[SOLVED] Cell Phone State keeps going to OFF

So I was following the beginner tutorial found here

It all works as expected except for one small issue, the cell phone state keeps switching to off after a few seconds.

I can switch the phone state to on and the state shows on and a light comes on, switch phone state to off and the light goes off. But after a few seconds to a minute the phone state switches to off and then the light goes off.

Any thoughts on this? Seems like an Apple thing as my wife’s Android returns 100% when pinged at any state (awake, screen off, screen on but locked)


Post your items definition, rules, etc.


Switch Presence_Mobile_William "William's iPhone" <network> { channel="network:pingdevice:8151d486:online"}
Switch LR_West_Lamp "Living Room West Lamp" <slider> { channel="tplinksmarthome:lb110:EDBF1D:brightness"}


Turn on Light when I come home or Leave home
rule "Living Room West Lamp ON"
  Item Presence_Mobile_William changed from OFF to ON

rule "Living Room West Lamp OFF"
  Item Presence_Mobile_William changed from ON to OFF

sitemap --> don’t know if this is needed

sitemap default label="Devices"
Frame label="Devices" {
        Switch item=LR_West_Lamp label="West Living room Lamp" icon="light"
        Switch item=Presence_Mobile_William label="William's iPhone"


Read this

To test, when Presence_Mobile_William changes to OFF, open a different device (like a computer or something else other than your iPhone). Leave the iphone off, don’t touch it.

Open a command prompt or a terminal. Enter this command:


if you don’t get a response, then your iphone is not responding, which means there’s nothing wrong with your rule/setup. It’;s just that your device is not responding to ping, and hence, openHAB is thinking it’s offline.

When it’s sitting idle, screen off…

Pinging with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)

When I press the home button (just awake, not unlocked)

Ping statistics for
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 60ms, Maximum = 152ms, Average = 83ms

So there you have it, You are correct

What can I do to fix this?


Hmm. Not entirely sure. Can you test same scenario with the phone plugged in (charging). I don’t have an iPhone but I suspect this is by design to save battery. Are you familiar with coding? If so, I think one trick to try is to write a script (in iPhone) that pings something every x seconds. This will make the phone think network is in use so that even while sleeping, it should not disconnect with the wifi.

If you are using the Network binding, to get continued and accurate presence detection, you need to get arping working correctly. iPhones and some Android phones switch off the WiFi when asleep (often even when charging) to save power.

What are you running openHAB on?

If Linux-based, then you need to install arping and get it running from the command line without root access.

If Windows - then I don’t think any version of arping is currently working, so you’re out of luck.

Have a look at the following topic, which outlines some of the steps someone else took to get it working just right. Presence arrival using DHCPlisten possible?

But this will not solve the issue if the device went to sleep and DHCP lease is expired.

How short is your DHCP lease then?

From what I’ve seen, iPhones wake up and do something on the network on average every 19 minutes or so at the least frequent - but arping should still respond with a successful response, even when the phone is in deep sleep, until the device is actually no longer in range of the network.

Setting retry to a value such as 10 should give you almost uninterrupted “Online” response, until the device actually leaves WiFi range (yes, there will be a lag of up to 10 minutes to detect that you are gone, but that doesn’t appear to be an issue here?)

Please actually try it before instantly dismissing it - it has worked successfully for quite a few people, I would be very surprised if it doesn’t work for you.

(You still haven’t answered the question of what operating system you are running openHAB on, by the way, which may be important to us helping you get a suitable solution)

Just a point about it working on the Android device and not iPhone, this will depend on the version of Android. From Lollipop (v5) onward, changes were made to battery management that prevented ping responses in certain situations. From Marshmallow (v6) onward, Doze was implemented that is far more aggressive in turning off WiFi and cellular connectivity and only waking periodically which prevents any ping responses once in “sleep” mode. From my experience, Android devices on KitKat (v4.4) or lower will respond to a ping regardless of state.

Also, when testing arping (assuming it’s a Linux based openHAB) be aware that iPhones (or iOS devices) can take 25-30 “arps” before waking and responding so set your count higher than the usual 4.

Even if DHCP has expired, it should still respond to an arp request as the device will use the last one assigned until told otherwise.

1 Like

Presence detection using the Network binding will not work if your phone disables the WiFi when going to sleep / power save mode. From what you posted I assume this is exactly what happens.

I have it working using a RPi3, detecting several android devices and a couple of iOS without issue IF the network binding is configured correctly. And by this I mean the arping tool is installed and accessible to the binding. On the Android devices, the “Keep WiFi on during sleep” is set to Always, but Doze still drops the WiFi connection when it wants to. I think this setting is just to keep it on when you initially turn the screen off.

It doesn’t seem that WiFi is fully powered off, only disabled for application use and ping. Arp requests are eventually acknowledged so the network binding should be able to function. However, like anything, I guess it will also depend on the specific device being polled and how that manufacturer has implemented things.

1 Like

@yesimwilliam Continue your inquiries here

I’m running OH on RPi3.

I will give arping a try as soon as I can…seems promising though. I’m not sure how long my DHCP lease is. I checked the router and not sure how I would check the length of DHCP lease.

Its funny, I got up this morning and was in the kitchen decided to check something on my phone and all of a sudden my lights came on, presumably because I “woke” up my iPhone.

This is definitely an iPhone thing. I can ping my wife’s android all day long and it always responds, no matter what state its in. my daughter and my iPhone’s will not respond 10 seconds after you lock the screen.

Thanks for all the info everyone.

arping should work just fine then :slight_smile:

Unless your DHCP lease is only minutes long, you really shouldn’t have an issue - although even if it is only minutes long, your phones should know that, and should wake up to renew their lease.

How do I install arp?

I did a google search to find out but cannot see anything resembling arping for RPi3? Is it an add-on in OH? I cannot find it bindings either, not sure how to proceed.

It is a Linux package - see details in the Network Binding documentation https://docs.openhab.org/addons/bindings/network/readme.html#arping

So I installed iputils-arping and I noticed that there are two locations for arp, one at /usr/sbin/arp and /usr/sbin/arpd.

Which one do I use? Is this the path put into the network binding for arping?

So long as you can run arping from the command line, and it works - openhab will find the right one to use.


So that is not working. If I type arping -c 5 it says “arping: Suitable device could not be determined. Please, use option -I.”

It appears that I am typing this command in wrong? I typed it in exactly as you did changing to my correct IP address with the same results. I tried to ping my wife’s android phone (which is always on) with this and got the same result, hmmm.

Which package should I have installed? I installed iputuls-arping.

If I type arp -a I can see my iPhone, with my correct IP and MAC address.

Any thoughts…