add time to running timer

Posted on
Fri Dec 15, 2017 1:31 pm
dduff617 offline
Posts: 659
Joined: Jul 05, 2006
Location: Massachusetts, USA

add time to running timer

i'm looking for help/advice with timers and pesters. i have a basic countdown timer serving as a sleep timer. works well - no problems. now, i would like a way that (e.g. with a keypad button press) i can implement the following logic: if timer is active and counting and button is pressed, i want to add a fixed amount of time (e.g.10 minutes) to the current timer value (and then have the timer continue/resume) counting down from the newly increased value.

the timers API -- if i am understanding correctly -- allow setting the START time of the timer but not touching the current time (understandable). so i can achieve what i want (i think) by pausing the timer, setting the timer's start time to be the timer's current remaining time + fixed increment, then restarting the timer. does that make sense or is there an easier way?

so next question: is there a way of accessing the current timer value (timeLeftSeconds, i think?) from outside the plugin, such as from an python-script trigger action?

would it work to use counterDevice.ownerProps["timeLeftSeconds"]? or counterDevice.states["timeLeftSeconds"]? i'm a bit vague on the details of different ways an object or a plugin can expose (or not) properties and what that means for how to access them from scripts.

thanks.

Posted on
Sat Dec 16, 2017 11:35 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: add time to running timer

The device state should contain what's left on the timer (that other one shouldn't exist - ownerProps should only have amount and amountType in it I believe).

Changing the start time while it's running won't do what you want - I think it'll stop the timer and change the amount value in the ownerProps. But even if it doesn't then it'll just continue with it's current countdown.

I think what you'll want to do is get the amount of time left, stop the timer, calculate a new total runtime (time left + extra time), set that as the amount (start value), then start the timer again. This will of course mean that you'll need to reset the start amount every time you use the timer since it could be anything after the previous run.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests