I have been trying to find a reliable way for HG to know when I or a few friends are present in my home.
I have been trying this with PingMeAtHomeExtended which pings your smartphone. However I have found this to not be reliable for these reasons.
The program identifies you with your local network IP 192.168.1.6 as an example. This works fine until DHCP assigns a different IP.
Most if not all smartphones will shutoff the wifi while idle to save battery. There are ways to keep it on but even with these adjustments it still seems to drop out.
It requires a lot of constant network activity to detect you.
What router do you use? I use DD-WRT and run a shell script and look at the mac address table for the relevant entries like this (you would need to define the mac addresses)
# This loop will check if a device is registered on the AP and set the virtual
# switch to on or off.
# wl command is used on broadcom chipsets
# wl_atheros command is used on qualcom atheros chipsets
while sleep $WATCHDOG_SLEEP_SEC
do
# echo Starting loop
if [ "$x" == 360 ]; then
# Every 30 minutes or so we do them all again, just in case we missed something
x=0
c1_last_state="0"
c2_last_state="0"
fi
c1_new_state=`/usr/sbin/wl_atheros assoclist | grep $MAC_ADDRESS_1`
c2_new_state=`/usr/sbin/wl_atheros assoclist | grep $MAC_ADDRESS_2`
# If they are different or its the first run.
if [ "$c1_new_state" != "$c1_last_state" ] || [ "$x" == 1 ] ; then
# There has been a change so set the last state and update
c1_last_state="$c1_new_state"
if [ "$c1_new_state" == "assoclist $MAC_ADDRESS_1" ]; then
# echo Device 1 user is in
wget -qs "http://$IP_ADDRESS/api/Presence.WifiCheck/1/Detected"
else
# echo Device 1 user is out
wget -qs "http://$IP_ADDRESS/api/Presence.WifiCheck/1/NotDetected"
fi
fi
# If they are different or its the first run.
if [ "$c2_new_state" != "$c2_last_state" ] || [ "$x" == 1 ] ; then
# There has been a change so set the last state and update
c2_last_state="$c2_new_state"
if [ "$c2_new_state" == "assoclist $MAC_ADDRESS_2" ]; then
# echo Device 2 user is in
wget -qs "http://$IP_ADDRESS/api/Presence.WifiCheck/2/Detected"
else
# echo Device 2 user is out
wget -qs "http://$IP_ADDRESS/api/Presence.WifiCheck/2/NotDetected"
fi
fi
# Increment Counter
x=$(( $x + 1 ))
done
Yup, mac addresses are the way to go. My router is very limited. To solve this I’m thinking of installing dnsmasq (?) on the Rpi that runs homegenie and have it be the dhcp dns server. That opens a lot of opportunities compared to my router. I looked into DD-WRT but it not for my actiontec router.
Currently, I’ve been using an app on my adroid phone called automate. I’m trying to get it to arm and disarm the security program. So far the results are encouraging. I have a “flow” (that’s what they call a script) based on location and one based on connection to my wifi. So far neither seems perfect.
Having the dns in the pi could help this as well. Inside I must use an ip number, outside I use a no-ip web address. So the flows must determine the connection and send the correct command. Being able to point the outside address via the host file while inside my network simplifies this greatly.
Once I get this working I plan to make the garage door automatic and have the house randomly turn lights on and off while I’m away.