Page 1 of 1

Incrementing a timer

PostPosted: Sun Sep 10, 2017 3:51 am
by Turribeach
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!

Re: Incrementing a timer

PostPosted: Sun Sep 10, 2017 12:09 pm
by jay (support)
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.

Re: Incrementing a timer

PostPosted: Sun Sep 10, 2017 6:07 pm
by Turribeach
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!

Re: Incrementing a timer

PostPosted: Sun Sep 10, 2017 6:56 pm
by jay (support)
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.