Presence detection with Wifi and Airport Express

So I have been looking for different Presence detection (I believe someone should make a post organizing all the ideas) I am kind of detecting the phone and have tried different approaches with varying results.
Now this approach I’m testing for not so long but looks promising:
Many suggest to use a Open WRT router, but I have an Airport Express which happily will show me in the custom UI what wireless devices are connected, so… trying to get the information from the device I found out that (a bit hidden) is the option to enable the snmp interface on the Airport Express. After doing some research and installing the MIB Browser and the AIRPORT-BASE STATION-3-MIB file found on the internet, I found out some promising items, like the Signal strength based on MAC Address of the device, this item is only available for already connected devices, so I installed the SNMP binding and created an Item:

String SnmpGLMiPhone <network> { snmp="<[10.0.1.1:public:.1.3.6.1.4.1.63.501.3.2.2.1.6.17.50.48.58.65.66.58.51.55.58.xx.xx.58.xx.xx.58.xx.xx:10000]"

which corresponds to the OID of the signal strength of a device with max 20:AB:37:xx:xx:xx so between points are ascii codes of the hex value of the mac.
(Sidenote 1: 10.0.1.1 is my Airport Express IP Address)
(Sidenote 2: I had to modify the openhab2/conf/services/snmp.cfg file and set the port to something hight than 1024, like 3085 for the binding to work ok)
Unfortunately this did not work very well, for some reason the Airport Express is not updating the values for the OID item and is always returning a “cached” value… but it is refreshing it when you SNMP-Walk from the higher range of the tree… unfortunately the SNMP binding cannot do this for me so I

apt-get install snmpd

to get the snmpwalk command line and verified that issuing

 snmpwalk -Os -v 2c -c public 10.0.1.1 .1.3.6.1.4

would effectively walk the sub tree and the next request by the binding will yield in an updated value! hurray. But now I need a monkey to perform this command so… I learn that the command

watch -n10

will execute the command every 10 seconds (which is the update rate of the snmp get in the binding) and well, the update can take as much as 20 seconds in the worst case which is ok for me.
So I added this line to my /etc/rc.local file just before exit 0

watch -n10  snmpwalk -Os -v 2c -c public 10.0.1.1 .1.3.6.1.4 &

(mind the & at the end) and got the PI (did I mention I was working with a PI) doing it after it rebooted ok.
Now I just need a switch item instead of a string to easily trigger rules and other stuff so I created the following item

    Switch PresenceGLM <man_3>

and the following rule

    rule "GLMPresence"
    when Item SnmpGLMiPhone changed
    then
    	if (SnmpGLMiPhone.state == "Null" && PresenceGLM.state != OFF) 
            postUpdate(PresenceGLM, OFF)
        else if (SnmpGLMiPhone.state != "Null" && PresenceGLM.state != ON) 
    		postUpdate(PresenceGLM, ON);
    end

And is looking ok so far… so I hope this might help you and let me know what you think about this…

2 Likes