How to define a timer in Indigo 2

Posted on
Sun Feb 22, 2009 2:27 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Timer won't reset when motion detected

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

Image

Posted on
Sun Feb 22, 2009 7:17 pm
bob offline
User avatar
Posts: 500
Joined: Jun 14, 2006

(No subject)

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 on
Sun Feb 22, 2009 10:29 pm
bob offline
User avatar
Posts: 500
Joined: Jun 14, 2006

(No subject)

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 on
Mon Feb 23, 2009 9:05 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

(No subject)

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"

Image

Posted on
Mon Mar 09, 2009 1:00 pm
bschollnick2 offline
Posts: 1355
Joined: Oct 17, 2004
Location: Rochester, Ny

(No subject)

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

Posted on
Sat Mar 21, 2009 1:25 pm
li0n offline
Posts: 8
Joined: Jan 08, 2009
Location: North Carolina

Thank you all.

Thanks for all the posts. Thanks MacPro. Love the timer script.

-Mark Smith

Posted on
Sat Apr 04, 2009 10:07 pm
boyakaa offline
Posts: 90
Joined: May 12, 2008

(No subject)

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 on
Tue Dec 15, 2009 9:47 am
hornedFrog offline
Posts: 66
Joined: Mar 23, 2007

(No subject)

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

Posted on
Thu Aug 05, 2010 11:47 am
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: How to define a timer in Indigo 2

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.

Posted on
Thu Dec 22, 2016 8:36 pm
btassias offline
Posts: 48
Joined: Apr 18, 2011

Re: How to define a timer in Indigo 2

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

Posted on
Fri Dec 23, 2016 2:08 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: How to define a timer in Indigo 2

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_2

I don't know if it works in Indigo 7 because I'm still on Indigo 6.
My upgrade is planned for the next week.

Posted on
Fri Dec 23, 2016 10:26 am
macpro offline
User avatar
Posts: 765
Joined: Dec 29, 2005
Location: Third byte on the right

Re: How to define a timer in Indigo 2

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.

Posted on
Fri Dec 23, 2016 11:37 am
jay (support) offline
Site Admin
User avatar
Posts: 18185
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to define a timer in Indigo 2

Using Timer devices is almost always better... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 2 guests