-- Applescript:
-- do a
ping and see if any device is present, if one answers, someone is home, uses 2 variables in indigo: IP_numbers and minutes without any response, see details below
-- 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 this where the answer is returnd. count number of minutes since last answer by listed IP devices
-- ... create variable ip_devices_IP_of_devices_to_look_for and fill with IP numbers 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.6
-- only 2 indigo variables needed 1. ip numbers and 2. return the number of minutes without any response
-- 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 ip_devices to (get value of variable "ip_devices_IP_of_devices_to_look_for")
end tell
set No_of_devices_to_look_for to count words of (ip_devices) -- count the number of IP numbers
set devices_failed to 0
set NN to 0
repeat while NN < No_of_devices_to_look_for
set NN to NN + 1
set IP_NUMBER to (word NN of ip_devices)
set
command to "/sbin/
ping -o -c 5 " & IP_NUMBER --
ping max 5 times, stop if device answers
set done to 1
try
set thePing to do shell script
command on error
set devices_failed to devices_failed + 1
set done to 0 -- we are 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 -- no device answered
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