Sorry to awaken an old topic however with the release of iOS4 I think there are some new options. It seems that the new iOS, especially with iPhone4, changes how WIFI is handled when the phone is in sleep mode. Although I'm a big fan of Proximity and have used it in the past, keeping bluetooth on when at home is a battery drain and not 100% reliable.
So the current state of things seems to be that while plugged in iOS4 is always connected to WIFI when asleep. When not plugged it the phone will wake up wifi to connect at the interval it is set to for fetching mail, for me this is 15 minutes. In this configuration I can see the phone connecting for approximately 15 seconds every 14.5 minutes, plenty enough to detect it on my network if I ping it's static IP (important detail) every 5 seconds.
I've installed the following cron job on my mac mini:
- Code: Select all
# detect iPhone on network
*/1 * * * * ~/bin/iphonecron &> /dev/null
iphonecron loops 12 times since cron cannot schedule in under 1 minute intervals, each loop interval will take about 5 seconds total:
- Code: Select all
#!/bin/bash
for((i=1; $i<=12; i=$(($i+1)))); do
~/bin/iphonecheck
sleep 4
done
iphone check performs the ping and updates my iphone presence variable only when it changes:
- Code: Select all
#!/bin/bash
IPHONELASTONLINE=`cat /tmp/iphonestate 2>/dev/null`
ISONLINE="false"
/sbin/ping -t 1 -c 1 192.168.1.117 &>/dev/null && ISONLINE="true" && sleep 1
if [[ "$ISONLINE" != "$IPHONELASTONLINE" ]]; then
osascript -e "tell application \"IndigoServer\" to set value of variable \"PresenceiPhone\" to \"$ISONLINE\""
fi
echo $ISONLINE > /tmp/iphonestate
In Indigo I'm using a trigger action to detect the PresenceiPhone value change to ensure my home mode is set to 'home'. My modes are set automatically by inspecting the value of PresenceLastMinSince which is incremented every minute and reset anytime a typical 'being home' action is detected in Indigo. This could be almost any insteon message, IR control, camera motion detection etc. Away and vacation modes are automatically set when PresenceLastMinSince becomes greater than 60 minutues and 18 hours respectively.
This is a new implementation and I'll update here if I experince any problems. I hope these details are useful to other Indigo users.