# Algorithm timers

**URL:** <https://discourse.nodered.org/t/algorithm-timers/26113>\
**Category:** General\
**Created:** [5 May 2020 06:37 UTC](https://discourse.nodered.org/t/algorithm-timers/26113 "2020-05-05T06:37:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![HDM](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@HDM](https://discourse.nodered.org/u/HDM)\
**Post date:** [5 May 2020 06:37 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/1 "2020-05-05T06:37:27Z")

</div>

good afternoon  
I apologize in advance if the topic was earlier  
algorithm of operation after 60 seconds the display turns on 4 seconds are turned on, after disconnecting, 60 seconds are counted again, the cycle is repeated  
how to implement this in node-red  
thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2020 08:06 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/2 "2020-05-05T08:06:12Z")

</div>

Hi @HDM, I am sorry but this does not make any sense.

Could you try to explain further?

What is display?

> [@HDM](#):
>
> 4 seconds are turned on,

4 seconds are turned on? It makes no sense I'm afraid.

Perhaps add some screenshots and list your logic out in a numbered list? Perhaps add your flow.

---

<div class="post-metadata">

**Author:** ![HDM](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@HDM](https://discourse.nodered.org/u/HDM)\
**Post date:** [5 May 2020 10:34 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/3 "2020-05-05T10:34:10Z")

</div>

1. 60 seconds countdown timer
2. Turn on the display for 4 seconds by timer
3. Disabling the display
4. The cycle repeats to the point 1  
спасибо

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2020 10:46 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/4 "2020-05-05T10:46:32Z")

</div>

> [@HDM](#):
>
> - 60 seconds countdown timer
> - Turn on the display for 4 seconds by timer
> - Disabling the display
> - The cycle repeats to the point 1

Is this what you want...

- 00:00:00 - begin timer
- 00:01:00 - 60s later - send "ON" to display
- 00:01:04 - 4s later - send "OFF" to display
- 00:02:04 - 60s later - send "ON" to display
- 00:02:08 - 4s later - send "OFF" to display
- 00:03:08 - 60s later - send "ON" to display
- 00:03:12 - 4s later - send "OFF" to display  
... and so on ...

  

_PS, I honestly have no idea what is "Turn on the display" - what kind of display - is this an MQTT signal? or a RELAY to turn TV on / off?_

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2020 10:56 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/5 "2020-05-05T10:56:33Z")

</div>

OK, here you go - best I can do with your description...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f51492435552666ba98821ab5535ef4a6aca71a.png)

Import this flow...

```auto
[{"id":"6ce23b61.a6abe4","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"ON","op1type":"nul","op2type":"str","duration":"60","extend":false,"units":"s","reset":"","bytopic":"all","name":"Wait 60s","x":760,"y":660,"wires":[["dd3cf54c.611e18","b58e1059.a7678"]]},{"id":"dd3cf54c.611e18","type":"trigger","z":"b1c27b9d.5a0ab8","op1":"","op2":"OFF","op1type":"nul","op2type":"str","duration":"4","extend":false,"units":"s","reset":"","bytopic":"all","name":"Wait 4s","x":760,"y":700,"wires":[["5a87d7ed.d05a38","398ab895.734ae8"]]},{"id":"a5906ac4.de8f68","type":"inject","z":"b1c27b9d.5a0ab8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":530,"y":660,"wires":[["6ce23b61.a6abe4"]]},{"id":"5a87d7ed.d05a38","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":780,"wires":[["6ce23b61.a6abe4","dd3cf54c.611e18","1e654c0d.f5dac4"]]},{"id":"b58e1059.a7678","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":950,"y":660,"wires":[]},{"id":"1e654c0d.f5dac4","type":"change","z":"b1c27b9d.5a0ab8","name":"","rules":[{"t":"delete","p":"reset","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":840,"wires":[["6ce23b61.a6abe4"]]},{"id":"398ab895.734ae8","type":"debug","z":"b1c27b9d.5a0ab8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":950,"y":700,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 May 2020 11:01 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/6 "2020-05-05T11:01:57Z")

</div>

Steve - I think you can do a bit simpler like this 😉

```auto
[{"id":"36bf2f7e.c210e","type":"inject","z":"173b76d0.b5b879","name":"","props":[{"p":"payload","v":"","vt":"str"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":500,"wires":[["b00cc370.971e6"]]},{"id":"b00cc370.971e6","type":"trigger","z":"173b76d0.b5b879","name":"","op1":"OFF","op2":"","op1type":"str","op2type":"payl","duration":"-64","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":430,"y":500,"wires":[["cde0d496.d916f8","19b29a02.c5ee26"]]},{"id":"cde0d496.d916f8","type":"debug","z":"173b76d0.b5b879","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":500,"wires":[]},{"id":"19b29a02.c5ee26","type":"trigger","z":"173b76d0.b5b879","name":"","op1":"","op2":"ON","op1type":"nul","op2type":"str","duration":"60","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":450,"y":560,"wires":[["cde0d496.d916f8"]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd667aa9cfcdbdb384ae72cdaab313fc8db9854b.png)

---

<div class="post-metadata">

**Author:** ![HDM](https://avatars.discourse-cdn.com/v4/letter/h/8797f3/32.png) [@HDM](https://discourse.nodered.org/u/HDM)\
**Post date:** [5 May 2020 13:32 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/7 "2020-05-05T13:32:19Z")

</div>

thanks, thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 May 2020 13:39 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/8 "2020-05-05T13:39:47Z")

</div>

Dave, I don't often use trigger node & that shows in my (albeit working) demo.

But one thing that always amazes me - the flexibility of node-red. 👍

---

<div class="post-metadata">

**Author:** ![duaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duaw/32/20970_2.png) [@duaw](https://discourse.nodered.org/u/duaw)\
**Post date:** [6 May 2020 15:34 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/9 "2020-05-06T15:34:58Z")

</div>

Hi, all!  
This shows us: Yes, the learning curve is flat at the beginning. Jeez, it looks so easy! So colourful. So nice! So intuitive.  
**But:** It is extremely difficult to discover the real power and potential of the in-built nodes when facing a problem you want to solve using these nodes. The curve becomes so steep. An easy looking problem becomes virtually insurmountable.  
Oh yes, once you are willing to "javascript" you can put it all in a function node. But this hides the inherent elegance of those nodes.  
Or you quit.  
What we need for beginners and not-so-beginner-anymore is more problem examples and their Node-RED solutions. Small problems. Some problems rather concrete, others of a more decoupled character wihout a problem "domain", propably popping up in different projects, contexts.  
Yes, a trizillion of questions have been asked here before, answers given. No, they are not always easy to dig out.  
The existing cook book is a start, needing further expansion.  
Just my 2 cent.  
Uwe

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [6 May 2020 15:47 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/10 "2020-05-06T15:47:35Z")

</div>

> The existing cook book is a start, needing further expansion.

Did you ever look at [this full playlist](https://www.youtube.com/watch?v=ksGeUD26Mw0&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6) ? It covers many aspects of node-red and when to apply what.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 May 2020 17:21 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/11 "2020-05-06T17:21:24Z")

</div>

Do you have a list of examples in mind ? Yes the cookbook is always looking to be extended... happy to take contributions and suggestions.

---

<div class="post-metadata">

**Author:** ![duaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duaw/32/20970_2.png) [@duaw](https://discourse.nodered.org/u/duaw)\
**Post date:** [13 May 2020 18:02 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/12 "2020-05-13T18:02:35Z")

</div>

I completey overloked this little gem. There seems to be no linke on the website.  
Yes, some answers are given, help to get the required insight.  
Thanks for pointing this out.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [13 May 2020 19:40 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/13 "2020-05-13T19:40:21Z")

</div>

It is [in the documentation](https://nodered.org/docs/user-guide/). (see: working with messages).

---

<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:** [12 July 2020 19:40 UTC](https://discourse.nodered.org/t/algorithm-timers/26113/14 "2020-07-12T19:40:23Z")

</div>

Closed on 12 July 2020 19:40 UTC

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