loafbread wrote:I ping the iPhones 5 minutes after a garage or house door opens/closes. That tells me who is home. I wake up the iPhone just prior to the ping with a push using http://dopushmail.com/. It is easy to email the push. We have a pushmail profile on the iPhone that is silent so the intrusion is minimal. I have tried many methods over the last 2 years and this one seems to work great. It doesn't detect arrival but I realized I didn't really need that. I just wanted to know when everyone was gone so I could close garage doors and turn off lights.
I was using https://github.com/tylerhall/sosumi PHP to locate the phones but the last update of Find My iPhone broke it for me. I played with Latitude but I like this method of pinging the phones best.
-- First we'll test for the iPhones via wi-fi:
with timeout of 10 seconds
-- Test for Andrea's iPhone
try
(do shell script "ping -o -t 4 -c 4 192.168.1.11")
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "home"
set value of variable "PresenceDetection" to "SomeoneHome"
log "Andrea is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "away"
log "Andreas iPhone wasn't detected"
end tell
end try
-- Test for Sean's iPhone
try
(do shell script "ping -o -t 4 -c 4 192.168.1.12")
tell application "IndigoServer"
set value of variable "iPhoneSean" to "home"
set value of variable "PresenceDetection" to "SomeoneHome"
log "Sean is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneSean" to "away"
log "Seans iPhone wasn't detected"
end tell
end try
end timeout
-- If the iPhones aren't found, then we'll try sending the pushmail to wake them up:
--Variables
set theAccount to "**************"
set recipientName to "Home Automation"
set recipientAddress to "**********@dopushmail.com"
set theSubject to "AppleScript Automated Email"
set theContent to "This is a test for your iPhone."
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Send the Message
send
end tell
end tell
-- Wait for 10 seconds for the message to be sent and received at the iPhone, waking it up and putting it back on wifi:
delay 10
-- Now look for the IPhones using wifi at home:
with timeout of 4 seconds
-- Test for Andrea's iPhone
try
(do shell script "ping -o -t 4 -c 4 192.168.1.11")
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "home"
set value of variable "PresenceDetection" to "SomeoneHome"
log "Andrea is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "away"
log "Andrea is Away"
end tell
end try
-- Test for Sean's iPhone
try
(do shell script "ping -o -t 4 -c 4 192.168.1.12")
tell application "IndigoServer"
set value of variable "iPhoneSean" to "home"
set value of variable "PresenceDetection" to "SomeoneHome"
log "Sean is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneSean" to "away"
log "Sean is Away"
end tell
end try
end timeout
dstrickler wrote:I would try an put a full path to your ping statement(s) - it may not be running ping at all. On my MBP with Snow Leopard, I show ping as "/sbin/ping", but you should verify that on your system. And please note I have not tried your clever script, so I don't know if this will work - just a guess.
do shell script "/sbin/ping -o -t 4 -c 4 192.168.1.11 > /tmp/ping_output.log"
cat /tmp/ping_output.log"
hamw wrote:This is a neat idea; do you have a complete and working script that you could share? What are you all's thoughts re GPS location detection vs wifi?
http://www.perceptiveautomation.com/userforum/viewtopic.php?f=11&t=5604&p=38582
Does sending all that pushmail crowd your outbox? Is there an autodelete in mail?
-- The purpose of this script is to detect the presence of Sean and Andrea's iPhones. If the phones are detected then the appropriate status will be set to "home" otherwise it will be set to "away". iPhones only respond if they are using wi-fi. Currently, if the iPhone is screen-locked it won't continiously use wi-fi - it'll only connect to get email. To get around this, we send a push email to xxxxx@dopushmail.com to knock the phone back on to wifi, wait 10 seconds, then test to see if it's in the house.
-- First we'll test for the iPhones via wi-fi:
-- Now look for the IPhones using wifi at home:
-- Test for Andrea's iPhone
try
(do shell script "/sbin/ping -o -t 2 -c 4 192.168.1.11")
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "home"
log "Andrea is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
log "Andreas iPhone wasn't detected - will try to wake it up"
end tell
end try
-- Test for Sean's iPhone
try
(do shell script "/sbin/ping -o -t 2 -c 4 192.168.1.12")
tell application "IndigoServer"
set value of variable "iPhoneSean" to "home"
log "Sean is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
log "Seans iPhone wasn't detected - will try to wake it up"
end tell
end try
-- If the iPhones aren't found, then we'll try sending the pushmail to wake them up:
--Variables
set theAccount to "Answer Phone"
set recipientName to "Home Automation"
set recipientAddress to "xxxxx@dopushmail.com"
set theSubject to "AppleScript Automated Email"
set theContent to "This is a test for your iPhone."
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Send the Message
send
end tell
end tell
-- Wait for 10 seconds for the message to be sent and received at the iPhone, waking it up and putting it back on wifi:
delay 10
-- Now look for the IPhones using wifi at home:
-- Test for Andrea's iPhone
try
(do shell script "/sbin/ping -o -t 3 -c 4 192.168.1.11")
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "home"
log "Andrea is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneAndrea" to "away"
log "Andrea is Away"
end tell
end try
-- Test for Sean's iPhone
try
(do shell script "/sbin/ping -o -t 3 -c 4 192.168.1.12")
tell application "IndigoServer"
set value of variable "iPhoneSean" to "home"
log "Sean is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneSean" to "away"
log "Sean is Away"
end tell
end try
-- The purpose of this script is to detect the presence of Sean and Andrea's iPhones. If the phones are detected then the appropriate status will be set to "home" otherwise it will be set to "away". iPhones only respond if they are using wi-fi. Currently, if the iPhone is screen-locked it won't continiously use wi-fi - it'll only connect to get email. To get around this, we send a push email to xxxxx@dopushmail.com to knock the phone back on to wifi, wait 10 seconds, then test to see if it's in the house.
-- First we'll test for the iPhones via wi-fi:
-- Now look for the IPhones using wifi at home:
-- Test for Marion's iPhone
try
(do shell script "/sbin/ping -o -t 2 -c 4 10.0.1.51")
tell application "IndigoServer"
set value of variable "iPhoneMarion" to "true"
log "Marion is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
log "Marion's iPhone wasn't detected - will try to wake it up"
end tell
end try
--end try
--Note that the script doesn't seem to advance beyond this point if Marion's phone is detected--
-- Test for Ham's iPhone
try
(do shell script "/sbin/ping -o -t 2 -c 4 10.0.1.50")
tell application "IndigoServer"
set value of variable "iPhoneHam" to "true"
log "Ham is Home"
return
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
log "Ham's iPhone wasn't detected - will try to wake it up"
end tell
end try
-- If the iPhones aren't found, then we'll try sending the pushmail to wake them up:
--Variables
set theAccount to "Answer Phone"
set recipientName to "Home Automation"
set recipientAddress to "xxxx@dopushmail.com"
set theSubject to "AppleScript Automated Email"
set theContent to "This is a test for your iPhone."
--Mail Tell Block
tell application "Mail"
--Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
--Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--Send the Message
send
end tell
end tell
--tell application "Mail"
--hide
--end tell
-- Wait for 10 seconds for the message to be sent and received at the iPhone, waking it up and putting it back on wifi:
delay 10
-- Now look for the IPhones using wifi at home:
-- Test for Marion's iPhone
try
(do shell script "/sbin/ping -o -t 3 -c 4 10.0.1.51")
tell application "IndigoServer"
set value of variable "iPhoneMarion" to "true"
log "Marion is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneMarion" to "false"
log "Marion is Away"
end tell
end try
-- Test for Ham's iPhone
try
(do shell script "/sbin/ping -o -t 3 -c 4 10.0.1.50")
tell application "IndigoServer"
set value of variable "iPhoneHam" to "true"
log "Ham is Home"
end tell
on error errStatement number errNum --errStatement holds text of error message, errNum the integer code described in either 'man ping' or sysexits.h
tell application "IndigoServer"
set value of variable "iPhoneHam" to "false"
log "Ham is Away"
end tell
end try
Users browsing this forum: No registered users and 2 guests