Page 2 of 2
Re: Timer won't reset when motion detected
Posted:
Sun Feb 22, 2009 2:27 pm
by matt (support)
There are a couple of problems. Ricks' version of the script has the code to reset the timer value but the version wikner posted that you used doesn't. Additionally, there is a problem because the timer is
using the countdown type.
Here is a modified (but untested) version that should work better:
- Code: Select all
on SetTimer()
tell application "IndigoServer"
set myDelay to value of variable "My_Delay"
set triggerTime to current date
set triggerTime to triggerTime + (myDelay as number)
if not (exists time date action "_MyTimer") then
set a to make new time date action with properties ¬
{name:"_MyTimer", date trigger type:absolute, time trigger type:absolute, absolute trigger time:triggerTime, auto delete:true, enabled:true}
tell first action step of a
set action type to executeScript
set script code to "MyTimeout()"
end tell
else
set absolute trigger time of time date action ("_MyTimer") to triggerTime
end if
end tell
end SetTimer
on MyTimeout()
-- do whatever you need on timeout
end MyTimeout
Posted:
Sun Feb 22, 2009 7:17 pm
by bob
Sorry Matt, I didn't get notification of your reply. I'll try your script. Could you also tell me how to do the script for the last post I sent?
thanks!
bob
Posted:
Sun Feb 22, 2009 10:29 pm
by bob
Matt,
Thanks for the script. It works well.
I am trying to get three motion detectors to keep lights on while there is motion. I found I could do it by using the Auto-off, every new motion resets the Auto-off but this way I can only use Control Light/Appliance Action. I can't set the Brightness as the Brightness Action has no Auto-off. So I was looking to set the Brightness with the Action and then an Applescript to do the Auto-off.
If I use
- Code: Select all
turn off device "someDevice" in 60
will it reset if triggered again?
bob
Posted:
Mon Feb 23, 2009 9:05 pm
by matt (support)
bob wrote:If I use
- Code: Select all
turn off device "someDevice" in 60
will it reset if triggered again?
No, that AppleScript verb always creates a new delayed action and never replaces the existing one. But you can remove all the existing delayed actions for that device first (before calling
turn off device ...) via:
- Code: Select all
remove delayed actions for device "someDevice"
Posted:
Mon Mar 09, 2009 1:00 pm
by bschollnick2
The only drawback I found is that it's possible to have multiple Indigo Timer scripts running at the same time. That obviously would cause inaccuracy with the timing...
This works around it, by checking to see if the script is running, and aborting if it is...
- Code: Select all
--
-- Retrieve Timer variables from Indigo and count them down.
--
-- Paul Roomberg
--
-- Version Date Info
-- ------- --------------- --------------------------------------------------------------------
-- 1.0 15-12-2006 First version
-- ------------------------------------------------------------------------------------------------
--
property timerRefreshRate : 15 -- refresh Timer variables every N seconds
property timerTimeOut : 5 -- Time Out value
property theHour : -1 -- Save the current hour
-- Count Down for one particular timer
-- Only if its value is positive, because negative or zero
-- means to not use it.
-- But when a timer counts down below zero, fix it at zero.
on doTimer(theTimer)
try
with timeout of timerTimeOut seconds
tell application "IndigoServer"
set theValue to value of variable theTimer
if theValue > 0 then
set theValue to theValue - timerRefreshRate
if theValue < 0 then
set theValue to 0
end if
set value of variable theTimer to theValue
end if
end tell
end timeout
on error number errNum
if errNum is -1712 then
tell application "IndigoServer"
log "Timer '" + theTimer + "' time out occured" using type "error"
end tell
else
tell application "IndigoServer"
log "Timer '" + theTimer + "' error occured: " & errNum using type "error"
end tell
end if
end try
end doTimer
set myName to "indigo timers.scpt"
set procCount to do shell script "ps axww|grep -e \"osascript.*" & myName & "\"|grep -v grep|wc -l"
if procCount as integer is greater than 1 then
tell application "IndigoServer"
log "Indigo Timers is Already running. Aborting start"
end tell
return false
end if
tell application "IndigoServer"
log "Starting Indigo Timers"
end tell
-- Timer Main Loop
repeat
try
-- Timer Loop
repeat
try
with timeout of timerTimeOut seconds
tell application "IndigoServer"
-- Show a heartbeat every hour
if not (the hours of the (current date)) = theHour then
set theHour to the hours of the (current date)
log "Timer script heartbeat" using type "info"
end if
-- Fetch all timer variables and process them
repeat with aVar in variables
set theTimerName to the name of aVar
if theTimerName begins with "Timer" then
my doTimer(theTimerName)
end if
end repeat
end tell
end timeout
on error number errNum
if errNum is -1712 then
tell application "IndigoServer"
log "Timer loop time out occured" using type "error"
end tell
else
tell application "IndigoServer"
log "Timer loop error occured: " & errNum using type "error"
end tell
end if
end try
-- Wait till the next run
delay timerRefreshRate
end repeat
-- This is the most important part of this script.
-- Somehow the inner loop dies on a time out after a
-- period of time. I have no clue why this happens,
-- but adding an outer loop with timeout detection
-- solves this.
on error number errNum
if errNum is -1712 then
tell application "IndigoServer"
log "Timer main loop time out occured" using type "error"
end tell
else
tell application "IndigoServer"
log "Timer main loop error occured: " & errNum using type "error"
end tell
end if
end try
end repeat
Thank you all.
Posted:
Sat Mar 21, 2009 1:25 pm
by li0n
Thanks for all the posts. Thanks MacPro. Love the timer script.
Posted:
Sat Apr 04, 2009 10:07 pm
by boyakaa
Thanks for the script. this works great..Can be used to automatically set your alarm system in case the exterior lights are tripped at night or motion is detected during the day When away..or home..
Posted:
Tue Dec 15, 2009 9:47 am
by hornedFrog
I posted a way to handle this yesterday and I think it is pretty clean and easy:
http://www.perceptiveautomation.com/php ... php?t=5292
Re: How to define a timer in Indigo 2
Posted:
Thu Aug 05, 2010 11:47 am
by loafbread
Thank you macpro and all the commenters. Very good timer ideas. I have implemented macpro's script and created several timers already. I like it.
Re: How to define a timer in Indigo 2
Posted:
Thu Dec 22, 2016 8:36 pm
by btassias
Hi
I had been using the Timer.scpt for awhile in indigo's past version when i updated to Indigo 7 i notice errors in the log file about not being able to
find the Timer.scpt and i don't see in in script background folder is this not needed or supported anymore ? and or should i be using timer and pester instead?
Thanks
Re: How to define a timer in Indigo 2
Posted:
Fri Dec 23, 2016 2:08 am
by macpro
Maybe it's located in the Indigo 6 folders. You have to manually move it to the Indigo 7 folders.
Take a look at this info:
http://wiki.indigodomo.com/doku.php?id= ... 5_4_3_or_2I don't know if it works in Indigo 7 because I'm still on Indigo 6.
My upgrade is planned for the next week.
Re: How to define a timer in Indigo 2
Posted:
Fri Dec 23, 2016 10:26 am
by macpro
I moved the upgrade to today and I'm now running Indigo 7.0.2.
After the first start, the Timers script did not run.
But as expected, I had to move/copy the script from the Indigo 6 directory to the Indigo 7 directory.
The old location is /Library/Application Support/Perceptive Automation/Indigo 6/Scripts/Background Tasks
The new location is /Library/Application Support/Perceptive Automation/Indigo 7/Scripts/Background Tasks
Next a restart of the Indigo Server and everything is working the way it should.
Re: How to define a timer in Indigo 2
Posted:
Fri Dec 23, 2016 11:37 am
by jay (support)
Using Timer devices is almost always better...