# Timer in node-red

**URL:** <https://discourse.nodered.org/t/timer-in-node-red/52361>\
**Category:** General\
**Created:** [18 October 2021 11:12 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361 "2021-10-18T11:12:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)\
**Post date:** [18 October 2021 11:12 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/1 "2021-10-18T11:12:26Z")

</div>

Hi all,

I would like introduce a timer which run when an input occurs.  
I'd like also that other commands runs while timer is running. For example while timer is running, if a gpio input turn on, I would stop, reset and change other paramenter of timer. this is possibile?  
and I would like that other global var is set true or false when timer ends.

Maybe the dalay could be set externally from a dashboard input?

Many thanks

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [18 October 2021 12:45 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/2 "2021-10-18T12:45:41Z")

</div>

Om the surface what you are asking seems possible. Perhaps just a little more information? What are you trying to do, just a little more specific. What have you tried up to this point?

---

<div class="post-metadata">

**Author:** ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)\
**Post date:** [18 October 2021 13:05 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/3 "2021-10-18T13:05:02Z")

</div>

Thank you for your answer. I will add more informations.

I have a raspberry and I need read an input many times. the input is a series of pulse with a define timestep between them and after many pulses there a pause and then the train of pulses restart.

so my intention is:

1. when I read the first pulse I start a countdown and if before countdown ends another pulse arrives, I **reset** countdown and **restart** it.
2. when a train of pulse ends, the countdown arrives to 0 so I understand that the train of pulses is finished.
3. I start now a new countdown relative the pause between trains of pulses. If countdown ends before the first pulse of the following train of pulses, an error message will be shown.

I hope is clearer than before. So I need start/stop/reset the timers externally (maybe by functions too or python-functions too) and I would like to set the timer duration from a dashboard input.

Many thanks

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [18 October 2021 13:17 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/4 "2021-10-18T13:17:19Z")

</div>

A Trigger node can do that.  
Send nothing, then wait for msg.delay milliseconds.  
Extend delay if new message arrives.  
Reset by sending msg.reset or if msg.payload == 0

So nothing will be sent by the trigger unless the timeout expires.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 October 2021 13:20 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/5 "2021-10-18T13:20:15Z")

</div>

How are you reading the pulses?

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [18 October 2021 17:20 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/6 "2021-10-18T17:20:07Z")

</div>

So play around with the ideas and try to build a flow, if you need more help come back and ask more questions

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [19 October 2021 00:14 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/7 "2021-10-19T00:14:17Z")

</div>

I'm using the [MyTimeOut node](https://flows.nodered.org/node/node-red-contrib-mytimeout) for a long time as it is fully customizable

- "on" or 1 - which turns on the timer and uses the default settings in the node (and issues an "on" on the output)
- "off" or 0 - which turns off the timer (and issues an "off" on the output)
- "stop" - which stops the timer (and issues a "stop" on the output)
- "cancel" - which cancels the timer (and does not send any output)
- Anything not listed above will be considered an on condition (a kicker or reset if you will)

i use it to manage my lights:

- ON/OFF switch from my external trigger
- Motion sensor will send "MOTION" to this timer. Command is umnknown and timer will reset/start
- msg.timeout is specifiying the timer-duration which I adjust with a normal slider node

have fun trying out 😉

---

<div class="post-metadata">

**Author:** ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)\
**Post date:** [19 October 2021 03:45 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/8 "2021-10-19T03:45:37Z")

</div>

Many thanks

I read pulse with gpio library and when inlet signal is true and when it turns false I would like start timer and if it turns true again before timer ends I would like stop timer and reset it. If timer end before next pulse I would send a message

---

<div class="post-metadata">

**Author:** ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)\
**Post date:** [19 October 2021 03:46 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/9 "2021-10-19T03:46:55Z")

</div>

Thank you nexus I try

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 October 2021 08:08 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/10 "2021-10-19T08:08:53Z")

</div>

> [@denissanga](#):
>
> I read pulse with gpio library

Do you mean you use the standard GPIO In node which sends a message each time the input changes? If so then you are not strictly reading the pulses. Using the word 'read' implies that you take some action to fetch the value, whereas the pulse messages will be sent out of the GPIO node when they happen, not when you choose to read them.

---

<div class="post-metadata">

**Author:** ![denissanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/denissanga/32/48346_2.png) [@denissanga](https://discourse.nodered.org/u/denissanga)\
**Post date:** [19 October 2021 08:38 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/11 "2021-10-19T08:38:27Z")

</div>

exactly, I'm really sorry for using incorrect word.  
I would like catch messages when pin status change and when it happens start or stop or reset timers.

I hope now it is clearer than before what I need to do.  
Many thanks for your patient

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 December 2021 08:38 UTC](https://discourse.nodered.org/t/timer-in-node-red/52361/12 "2021-12-18T08:38:43Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
