-- Applescript:
-- do a ping and see if device is present, example here has 3 ip numbers to ping. if one answers, someone is home, if none answers set away flag etc
-- works with every router, no other prerequisites
--
-- ping the IP numbers several times, if not successful increment ip_devices_not_online_minutes in indigo
-- in indigo:
-- ... create variable ip_devices_not_online_minutes
-- ... create variable ip_devices_No_of_devices_to_look_for and set to number of devices to look for
-- ... create variable ip_devices_IP_of_devices_to_look_for and fill with IP number separated by space eg "192.168.1.122 192.168.1.125 192.168.1.134" without the quotes
-- ... put this file into a folder on your mac and in scheduler set once a minute execute as apple script file, do not use embedded, as indigo will "stop" / wait for this to end
-- ... create a trigger if ip_devices_not_online_minutes > 60 ( for 60 minutes) then set e.g. away_mode = 1 ...
-- works ok if the iphone/other devices are not asleep
-- must / should set DHCP IP number fixed in router for pinged devices
-- Karl Wachs
-- v 1.5
-- changed to loop structure
-- may 28, 2013
--
-- use basic post from
http://macstuff.beachdogs.org/blog/?p=34 for ping and error capture
tell application "IndigoServer"
set ip_devices_not_online_minutes to (get value of variable "ip_devices_not_online_minutes")
set No_of_devices_to_look_for to (get value of variable "ip_devices_No_of_devices_to_look_for")
set ip_devices to (get value of variable "ip_devices_IP_of_devices_to_look_for")
end tell
set devices_failed to 0
set NN to 0
repeat while NN < No_of_devices_to_look_for
set done to 1
set NN to NN + 1
set IP_NUMBER to (word NN of ip_devices)
set command to "/sbin/ping -o -c 5 " & IP_NUMBER
try
set thePing to do shell script command
on error
set devices_failed to devices_failed + 1
set done to 0 -- not done yet
end try
if done = 1 then set NN to 9999 -- found one live device, exit
end repeat
if devices_failed = No_of_devices_to_look_for then
set ip_devices_not_online_minutes to ip_devices_not_online_minutes + 1 -- increment minutes offline counter
else -- .... found at least one alive, reset minutes counter to 0
set ip_devices_not_online_minutes to 0
end if
try
tell application "IndigoServer"
set value of variable "ip_devices_not_online_minutes" to ip_devices_not_online_minutes
end tell
end try