[SOLVED] Presence with Android after using Iphone

Does phone have anti-virus?

In the phone settings what is the IP?

No, I do not have antivirus. I use MAC OS in my laptop without antivirus.

In my phone setting, I have the same IP than the router, first 192.168.2.120, then I change to 192.168.2.160, and neither of them appears in INBOX.

Well, thatā€™s odd. I guess, but thatā€™s only a guess, that your router is not making that IP address visible to other devices in the network. Have you checked all the router settings especially one concerned with your phoneā€™s MAC

Yes is very odd. I will have a look in the router setting. My router is from Telekom Speedport (Germany).

I will let you know at the end of the week. I am traveling till thursday.
Thanks.

An old thread. But interesting workaround (apart from writing you own Android app) mentioned there is

You could use Tasker or Locale instead of writing your own app. Both allow you considerable flexibility in setting up rules, which could include making an http request to your server when in range of your wireless network

Another option I already mentioned - IFTTT Android app, that can drive a switch item on wifi events. But needs internet and OH cloud to contact OH instance (two dependencies!).

There is also a bluetooth binding based presence detection that many people seem to use.

Since you are on Android now and only want to tell OH when you arrive and leave, perhaps you check out something I provided: Tasker with myopenHAB.org (Screenshots for tasker)

It would require a purchase of Tasker, but it will easily give a ROI in a short amount of time. :wink:

Try adding a static ARP entry for your phoneā€™s MAC in your openHAB server.

openhabian:/opt/openhab2 $ sudo arp -s 10.0.1.51 b9:c7:7d:cd:ez:ad
openhabian:/opt/openhab2 $ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
10.0.1.3                 ether   c9:88:ad:16:6c:09   C                     eth0
10.0.1.51                 ether   b9:c7:7d:cd:ez:ad   CM                    eth0

The CM flag indicates a static entry.
If it works, make it persist across reboots by adding it in /etc/ethers file on OH. Create the file if it doesnā€™t exist.

b9:c7:7d:cd:ez:ad 10.0.1.51

EDIT
Above solution is working for me, along with following:

  • Setting retry in thing config to 3 gives reliable results.
  • Make sure your USERDATA/etc/network.binding.cfg is owned by openhab user. sudo chown openhab:openhabian /var/lib/openhab2/etc/binding.network.cfg
  • Make sure arping path is set in that .cfg. arpPingToolPath=/usr/sbin/arping
  • arping must be setuid root. sudo chmod u+s /usr/sbin/arping

Instead of manual step of adding static ARP entry, the binding can be fixed by giving a mac hint to arping tool:

Instead of

arping -i eth0 10.0.1.51

binding should do

arping -i eth0 -t b9:c7:7d:cd:ez:ad 10.0.1.51

Let me know anyone wants me to create PR for this.

Works just fine. Some Androids also go to sleep so the arping is needed for those as well. You may need to tune it a little by adjusting the retry, timeout, and refresh fields on the Thing.

IFTTT only works with cloud services.

Itā€™s been recommended many times. Given how well the Network binding works and all the other options, Iā€™m not sure I would support adding this feature to the Android app.

That is correct, though if you want to be away for more than 5 minutes before going to ā€œawayā€ you will need Rules. See Generic Presence Detection.

How log do you wait? This binding, much like your original script, only checks every so often. That is what the refresh field controls, how often it attempts to ping the phone.

This is where the refresh and retry fields may need to be adjusted. There have been many threads on this forum discussing the best values for these fields for iPhone. I canā€™t find them right now though but perhaps someone can post a link.

That isnā€™t how OH works. You have an Item that represents whether the phone is present or not (i.e. online)/. You have another Item that represents whether the door is opened or closed.

If you want to do something only when the door opens and your phone is present you need a Rule.

I donā€™t have much else to offer and it seems lots of knowledgeable users are providing help.

FYI

Above solution, setting static ARP entry, is working for me, along with following:

  • Setting retry in thing config to 3 gives reliable results.
  • Make sure your USERDATA/etc/network.binding.cfg is owned by openhab user. sudo chown openhab:openhabian /var/lib/openhab2/etc/binding.network.cfg
  • Make sure arping path is set in that .cfg. arpPingToolPath=/usr/sbin/arping
  • arping must be setuid root. sudo chmod u+s /usr/sbin/arping

Instead of manual step of adding static ARP entry, the binding can be fixed by giving a mac hint to arping tool:

Instead of

arping -i eth0 10.0.1.51

binding should do

arping -i eth0 -t b9:c7:7d:cd:ez:ad 10.0.1.51

Let me know anyone wants me to create PR for this.

However, network binding depends on arping which is not installed on windows or linux by default (the regular ICMP ping doesnā€™t work for mobile devices in sleep). Not sure whether arping is in pre-packaged list of openhabian, it should be, including setuid root step.
Such extra install / configure / debug steps could be avoided if OH app and OH server handles this automatically, not sure about the amount of effort though. Since the usecase is so common, we shouldnā€™t expect OS admin skills from innocent users. :slight_smile: It should just work.

I donā€™t disagree with this statement. What I disagree with is basically moving this implementation to the Android app. For one, it only addresses the problem for Android and given how difficult it is get developers to contribute to the iOS app to keep up basic capability I doubt this would ever find its way to iPhones where it is needed as well.

Also, there are plenty of use cases where I would want to know if a phone is present without the OH app installed on that phone.

So Iā€™m all for a solution that makes working with Network binding and arping easier. But only if it addresses the problem for all of the above. Otherwise it replaces complexity with complexity.

yes, but mostly its family memberā€™s phones people want presence detection for. If its kidā€™s tablet, you can always put an AppLock on OH app, but keep it running. Implementing it in app would serve more than 80% users outright. Remaing 20% who have advanced use cases, may find network binding based solution useful. So the App based solution still has a lot of value to lot of people. iOS developers, we need to attract more, we canā€™t get stuck by that line of reasoning, every time there is new feature to be added to OH Apps.

Nothing is preventing you from filing an issue (if there isnā€™t one already) and even better a PR.

Iā€™d still rather see a solution that solves everyoneā€™s problem then three or four solutions that solves each individual problem in a different way.

Or distant relations or guests. Iā€™m not going to say ā€œsorry, the heat will be off if I or my wife leaves the house because it will think no one is homeā€ and Iā€™m not going to force them to install an and configure an app.

A strong assertion. Do we have any sort of metrics to actually back up that claim? I really do not have a good feel based on postings on the forum what percentage of users have:

  • only Android phones
  • use those phones for presence detection
  • use the wifi on those phones for presence detection

I donā€™t have any numbers either. It could be 80%, it could be 40%. But Iā€™m always very cautions about making decisions when people pull statistics out of thin air.

Iā€™m not a developer (on OH). Iā€™m not a maintainer. My opinion counts for little. BUT, I am the most prolific user on this forum when it comes to helping users, particularly new users. And I can say without a doubt that inconsistencies between the how and what the phone apps are capable of has a real and significant cost to the new users. I will not support any change that increases the amount of diversity in parts of the system that should work the same.

But ultimately, unless you or I or some other developer is willing to actually submit some code to do this and convince the maintainers to merge it into the baseline, this whole conversation is academic.

1 Like

I kind of had presence detection working on a combination of devices using the Network binding, including arping and DHCP listen, but it was never completely reliable.

Iā€™ve since installed a Ubiquiti access point, and the binding, and this has been absolutely spot on. I am detected immediately when Iā€™m within range of the house, and the timeout is configurable, and if Iā€™m watching OH and the clock after disabling WiFi on all of the phones, it marks as Offline almost to the second.

Yes, thereā€™s an outlay for Ubiquiti equipment, but theyā€™re also very good bits of kit, and Iā€™d have had one anyway, the benefit of reliable presence detection has been a very welcome side-effect too!

At least for now I can provide

  • a PR to network binding for MAC address hint, that solved it for my Adroid 7 phone. Since MAC is not part of discovery process of this binding, it would be a thing config parm[optional].
  • Another PR to ensure arping is setup on openhabian.

Till then, users (who are having issues wt Android presence with network binding) will have to

  • add a static arp entries in /etc/ethers (on OH Linux server) for your Androids/iOS devices. One device per line aa:bb:cc:dd:ff 192.168.1.51
  • I noticed that the arp db /etc/ethers is not loaded by rasbian init scripts. You need to either manually do sudo arp -f /etc/ethers or put a line arp -f /etc/ethers in /etc/rc.local script (before exit 0 command in that file)
  • a fixed IP assigned to Android device in wifi routerā€™s DHCP settings, or static IP (outside DHCPā€™s IP range) set in phoneā€™s wifi settings
  • setup arping tool themselves
  • change retry to at least 2 in network bindingā€™s Thing config
  • provide arping path to network binding via USERDATA/etc/binding.network.cfg file or CONF_DIR/services/network.cfg file.
1 Like

Exactly. No one knows about how many users get affected by a certain feature. Your assessment may primarily be based on only those who report back here on community. Some people quit an approach silently or afraid to ask. Or they quit OH silently, which we donā€™t want. Mozilla Firefox nowdays is humbly asking their users to share anonymous stats to them, in order to prioritize issues and feature requests. We should do that too. We do trust OH foundation with our data, at least anonymous.

Thank you for the answer. I am not at home untill Friday to answer properly everything.i do not have my laptop with me, sorry.

@rlkoshak I will read carefully and i will try again step by step but what I am pretty sure is that OH does not ā€œseeā€ my device connected when actually is.
I tried last weekend arping which worked but not completly fine.

@diyha i will try you proposal after reading and understanding everything properly.

But I think that for me if OH does not see my device, how is possible that something works if OH does not detect my device?

arping works as long as there is entry in ARP cache. The cache has timeout within minutes range. After which MAC address hint helps, as I suggested earlier.

So with my Android connected to wifi and not sleeped, i mean, while working with the phone , the Arping gave me backs sometimes like OFF device, this is not possible.

Maybe I need to tune it better.

With the network binding, I tried different tunning and never detected device ON, after more than 3-4 minutes waitting.