How to clear or reset a timer?
Moderators: grovkillen, Stuntteam, TD-er
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
How to clear or reset a timer?
Is there a way to clear a timer that is running?
Say, for example I have a timer that runs for 30-secs and I want to clear it so... On Rules#Timer=1 Do fires
What I'm doing at the moment (which works fine) is setting the timer to 1-second ( timerSet,1,1) so one second later the rule fires.
Just wondered if there was a neater way to achieve this?
Say, for example I have a timer that runs for 30-secs and I want to clear it so... On Rules#Timer=1 Do fires
What I'm doing at the moment (which works fine) is setting the timer to 1-second ( timerSet,1,1) so one second later the rule fires.
Just wondered if there was a neater way to achieve this?
Re: How to clear or reset a timer?
The official, and AFAIK documented, way is to set it to 0 
Edit: Documentation: https://espeasy.readthedocs.io/en/lates ... mmand.html (Search for the TimerSet command)

Edit: Documentation: https://espeasy.readthedocs.io/en/lates ... mmand.html (Search for the TimerSet command)
/Ton (PayPal.me)
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How to clear or reset a timer?
In the documentation it says it 'disables' the timer (which is what seems to happen in my rule-set).
TimerSet,<timernr>,0 (disables the timer)
I just wanted to clear or reset the timer.
I'll try the TimerSet_ms,<timernr>,<time in msec> command as I didn't know that existed.
TimerSet,<timernr>,0 (disables the timer)
I just wanted to clear or reset the timer.
I'll try the TimerSet_ms,<timernr>,<time in msec> command as I didn't know that existed.
Re: How to clear or reset a timer?
Then I don't fully comprehem why you wrote 'clear' as in my understanding that would not trigger the timer.
If you want to execute that event 'now', then just use an "event,rules#timer=1" command. Usually, the last command in that handler would be to re-initiate the timer, but if that is not desired you could use that timerset,1,0 just before the event command to prevent it being triggered at its original delay.
If the event is to be executed after the current event is finished, the execution can be queued by using the asyncevent command.
The timerset_ms is the same command as timerset, except it doesn't multiply the time with 1000
If you want to execute that event 'now', then just use an "event,rules#timer=1" command. Usually, the last command in that handler would be to re-initiate the timer, but if that is not desired you could use that timerset,1,0 just before the event command to prevent it being triggered at its original delay.
If the event is to be executed after the current event is finished, the execution can be queued by using the asyncevent command.
The timerset_ms is the same command as timerset, except it doesn't multiply the time with 1000

/Ton (PayPal.me)
Re: How to clear or reset a timer?
To clear, as in no longer get the timer event, you have to set the timer to 0.
To reset, as in re-set, you simply call timerset with the new interval you need. The nr of sec or msec, depending on calling TimerSet or TimerSet_ms from now.
To reset, as in re-set, you simply call timerset with the new interval you need. The nr of sec or msec, depending on calling TimerSet or TimerSet_ms from now.
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How to clear or reset a timer?
Thanks for the suggestion to use... event,rules#timer=1
That works really well for my current project.
Basically what I have is a 300-second timer.
Every time it expires (every 5-mins) it will collect a temperature reading and sends it, via MQTT, to Node-RED where it is stored in a MySQL db and shown on a graph.
Node-RED can send an event to change the time interval to say 15 (seconds) so the updates happen more rapidly.
What I was trying to do was make the change to the time-interval become active from NOW, rather than having to wait until the current time runs out.
Using the... event,rules#timer=1 achieves this and means the system's response is very rapid.
I can now go on and apply the same technique to setting the max and min setpoints from Node-RED.
The final project is going to be a Room Temperature Display system (RTD).
Here's a pic of the prototype and the PCB (which has two RTDs and a piece of spare circuitry).
I've also attached a section of the 'test flow' that runs in Node-RED.
Thanks to everyone for their help and advice.
That works really well for my current project.
Basically what I have is a 300-second timer.
Every time it expires (every 5-mins) it will collect a temperature reading and sends it, via MQTT, to Node-RED where it is stored in a MySQL db and shown on a graph.
Node-RED can send an event to change the time interval to say 15 (seconds) so the updates happen more rapidly.
What I was trying to do was make the change to the time-interval become active from NOW, rather than having to wait until the current time runs out.
Using the... event,rules#timer=1 achieves this and means the system's response is very rapid.
I can now go on and apply the same technique to setting the max and min setpoints from Node-RED.
The final project is going to be a Room Temperature Display system (RTD).
Here's a pic of the prototype and the PCB (which has two RTDs and a piece of spare circuitry).
I've also attached a section of the 'test flow' that runs in Node-RED.
Thanks to everyone for their help and advice.
- Attachments
-
- Screen Shot 11-05-21 at 07.31 AM.GIF (26.66 KiB) Viewed 12078 times
-
- A_Room_temp_and_display.GIF (71.01 KiB) Viewed 12085 times
-
- breadboard_A.jpg (226.67 KiB) Viewed 12085 times
Last edited by dynamicdave on 05 Nov 2021, 08:33, edited 2 times in total.
Re: How to clear or reset a timer?
One more tip:
Please also have a look at the "asyncevent" command.
It is similar to the "event" command, with only difference that it will be put to the event queue and thus not handled immediately (but still fast enough).
The advantage is that it will not "stack" up in event execution as creating an event will initiate a new rule processing step, thus using more resources and with events calling events it may take quite a long time to process.
Most events (almost any, but especially this use case of yours) can be done using asyncevent and it will keep the ESP more responsive.
Please also have a look at the "asyncevent" command.
It is similar to the "event" command, with only difference that it will be put to the event queue and thus not handled immediately (but still fast enough).
The advantage is that it will not "stack" up in event execution as creating an event will initiate a new rule processing step, thus using more resources and with events calling events it may take quite a long time to process.
Most events (almost any, but especially this use case of yours) can be done using asyncevent and it will keep the ESP more responsive.
- dynamicdave
- Normal user
- Posts: 258
- Joined: 30 Jan 2017, 20:25
- Location: Hampshire, UK
Re: How to clear or reset a timer?
Thanks I did wonder about events stacking up.
Just tried using... AsyncEvent,rules#timer=1
Works really well.
Thank you.
Just tried using... AsyncEvent,rules#timer=1
Works really well.
Thank you.
Who is online
Users browsing this forum: No registered users and 15 guests