Better Presence

One of the critical things that Audrey needs to know is if someone is actually in the house, and who.  This will help her make decisions like setting the house in an economy mode or turning on security monitoring.

My first choice was motion detectors and although a good choice, had some shortcomings.  If there is a couch potato in the house not moving (or even sleeping), Audrey will mistake the house as unoccupied and all sorts of havoc could occur.

Since most folks have phones available, my next level of checking was if a phone was present in the house.  My first attempt was to check for Bluetooth but required some tough setup and wasn’t that reliable.  Then I thought to ping the phones for WiFi but since many phones go into various modes of sleep to extend the battery, it wasn’t reliable either.

I read about Joshua Stein’s Ecobee automation hack which describes similiar problems in his attempt to automate.  His solution was to check with his wireless accesspoint to see if the phone’s MAC was still connected to WiFi.  Brilliant!

The rub was that he walked his AirPort’s SNMP MIB and from what I could find, my Linksys E2000 didn’t provide SNMP access.  But I did find a web page (/WL_ClientList.asp) in the admin section that listed the connected MACs.  So with a quick script, I had Audrey pull the page, check it against a list of MAC addresses in an .ini file, and then turn virtual devices on and off according to status.

Currently, I still need to ask my friends to keep their WiFi on, connect it to my network, put the MAC in a config file, and create a virtual device to hold status.  My plans are to automate it by using some DHCP scripts automating the ini entries and device connections.

More Posts:

Details for the Geeks

For the tech on how I did this, here are the ingredients:

  • All the Audrey tech laid out here including Homeseer Software HS2
  • The script below to gather presence from accesspoint (I am not a professional coder so modify and use at own risk)
 ' set_presence.txt
 ' Sets presence if a phone is in the house
 ' Lee Rogers 12/28/2011 10:08 AM

Sub Main
 strScript = "Presence"
 strINIFile = "presence.ini"
 strURL = "http://accesspointURL/WL_ClientList.asp"

'Pull connected MACs from accesspoint
 page = hs.geturlie(strURL,false)

'Pull users from ini and parse
 strUsers = hs.getinisection("macs",strINIFile)
 arrUsers = split(strUsers,chr(0))
 for i = 0 to ubound(arrUsers)
 user = hs.StringItem(arrUsers(i),1,"=")
 mac = hs.StringItem(arrUsers(i),2,"=")

'Test if MAC is present in accesspoint
 Set mactest = New RegExp
 With mactest
 .Pattern = mac
 .IgnoreCase = True
 .Global = True
 End With

isHome = mactest.test(page)

'If present, set devices
 if isHome then
 hs.SetDeviceStatusByName "Location Users " & user, 2
 'hs.writelog strScript, user & " is home"
 hs.SetDeviceStatusByName "Location Users " & user, 3
 'hs.writelog strScript, user & " away"
 end if

hs.writelog strScript, user & " " & mac & " " & isHome


' Kill IE after to stop errors
 ' ===================================================
 strComputer = "."
 strProcessToKill = "iexplore.exe"

Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" _
 & strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
 ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
 For Each objProcess in colProcess
 count = count + 1

Set page = Nothing

End Sub