Incrementing a timer

Posted on
Sun Sep 10, 2017 3:51 am
Turribeach offline
Posts: 191
Joined: Feb 06, 2015
Location: London, UK

Incrementing a timer

I got a timer that I want to increment or decrease from a control page. I use the following code to change the timer's start time:

Code: Select all
timerPlugin.executeAction("setTimerStartValue", deviceId=1604521627, props={'amount':'30', 'amountType':'minutes'})


This is working fine but the issue I got is that when I change the timer's start time the timer goes back to inactive, if the timer is running. This in turn runs a trigger which fires on the timer being inactive but I don't want to run in that scenario. I have worked around the situation by checking the state of the timer before changing the start time, then restoring the timer's state after doing it. I also created a variable "DontChangeTimer" which I set to true before I change the timer and I can as a condition on the trigger I don't want to run. Then I set back to false once I finished changing the timer. This works fine but it seems a bit convoluted, is there a better way of doing this? In other words how can I increment a timer without changing it's state?

Thanks!

Posted on
Sun Sep 10, 2017 12:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 13254
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Incrementing a timer

Turribeach wrote:
In other words how can I increment a timer without changing it's state?


I believe your trigger should only fire when the timer expires (using the Timer Expired event rather than a device state changed event), so changing the start time and restarting the timer shouldn't effect the trigger in any way.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Sep 10, 2017 6:07 pm
Turribeach offline
Posts: 191
Joined: Feb 06, 2015
Location: London, UK

Re: Incrementing a timer

Aha! Thanks, Jay. Yes, I was indeed firing the event on Device State Changed => Timer Status is Inactive. But I see now I can use the Timer Expired event as you suggest. But I need to look at my code and confirm there are no side effects of making this change as I think I got some hooks when the timer is stopped as well which then becomes inactive and the trigger fires as well. I kinda see the expired event as a sub-event of the parent inactive event to be honest as for instance stopping the timer won't fire the expired event (I think) but will fire the Inactive event. Am I right?

Thanks!

Posted on
Sun Sep 10, 2017 6:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 13254
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Incrementing a timer

The expired event is specifically provided to ensure that the only time it fires is when a timer organically runs out. Everything else can be done with device state changes.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest