Thank you to those who responded to my post. I’ve successfully implemented Presence Detection. I’ll post my work in case anyone would like to implement my solution.
I’ve read that many people use the IP address of their iPhone to detect its presence, but others have complained this lead to battery depletion. I’ve also read that some people write scripts they can run on their routers to detect the phone then report that to OpenHab.
My router is provided by my Internet Provider and is one of a variety of Arris routers. I’m not sure of the model and find that immaterial, what is important about it is that the login pages displays up to 15 connected devices. It seems that the most recently connected devices are on the list and those that have been connected longer fall off. This may not be correct but so far it’s the behavior I’ve observed. Since this information is available before login it was obvious to me that I could write a simple curl script to see if the router is aware of my phone. With some pointers from this forum I am able to detect the presence of my phone and act upon it in Openhab2. Here is my configuration:
The Curl Script:
#!/bin/bash
#
# ishome.sh - Detect presence of iPhone on wireless router
#
curl -s http://172.17.0.1|grep iPhone > /dev/null 2>&1
if [ "$?" = "0" ]; then
ishome='true'
else
ishome='false'
fi
echo $ishome
The following are the contents of my ishome.things file:
Thing exec:command:ishome [command="/usr/local/bin/ishome.sh", interval=60, timeout=30]
I’ve set the command to run every 60 seconds and to abort if execution is not complete within 30 seconds.
Finally I had to create an item which looks like this:
String IsHome {channel="exec:command:ishome:output"}
This allows that the string IsHome can capture the output of ishome.sh. Since IsHome is a proxy device it can trigger a rule or be queried as part of a rule. To test I created this rule to log when IsHome is changed:
rule "Presence Detection"
when
Item IsHome changed
then
logInfo("ishome.rules", "Presence changed")
end
So far this works very, very well. I’ve performed several tests by disabling wifi on my phone and re-enabling it. So far, it takes about 5 minutes to signal that the phone is no longer present and takes about 1 minute to detect when it is. Since my polling interval is one minute this is a pretty rapid response, I’d have expected it to average 2 minutes for detection and over the long run may be more reasonable, but even still that’s sufficient for my purpose which will be to signal me if my door contacts are triggered when I’m not home.
Cheers
-Bob