# Need Help with Making a Countdown Timer Display

**URL:** https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387
**Category:** General
**Created:** [20 July 2020 09:56 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387 "2020-07-20T09:56:37Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 12:45 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/22 "2020-07-20T12:45:35Z")

</div>

{{msg.payload}} part was 30 by default. It needs an integer, I guess. How can I fix this issue?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67fe0c294acd5cd2bee518e2190acc9be949a6c9.png)

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 12:50 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/23 "2020-07-20T12:50:22Z")

</div>

Description says this:

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

How and where should I set the topic to "control", and a "number" as payload?

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 12:51 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/24 "2020-07-20T12:51:06Z")

</div>

remove 30 in countdown

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 12:52 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/25 "2020-07-20T12:52:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 12:55 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/26 "2020-07-20T12:55:31Z")

</div>

use change node to set msg.topic as control and msg.payload as the number. Keep 30 as is

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 12:59 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/27 "2020-07-20T12:59:54Z")

</div>

This is the switch's change:

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

This is the dropdown's change:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76848e14bf8dfd8bc3f4c952a2f1749d7ecffc10.png)

Here is the flow:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/09b3a1f750f41de5f8801dc94a3476a673b40748.png)

This is the UI, 2 seconds after I pick 60 min, and use the switch:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b21a1605f259f7372edd61315a410b37d51bb2b.png)

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 13:03 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/28 "2020-07-20T13:03:18Z")

</div>

msg.number is not needed.

Set topic as below

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e1c674bbdad065cc49bdc4dbcf9d97ddc40a149.png)

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 13:09 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/29 "2020-07-20T13:09:30Z")

</div>

It is not counting now, it is stuck at 0.

Under the node, I see 3600, when I choose 60 min and click on the switch, but the text stays at 0.

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 13:11 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/30 "2020-07-20T13:11:16Z")

</div>

Export the flow and post it here.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 13:12 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/31 "2020-07-20T13:12:00Z")

</div>

```auto
[{"id":"cdfeb830.a33e78","type":"ui_text","z":"7e5c236f.8633ec","group":"72303c1.198bdc4","order":2,"width":0,"height":0,"name":"","label":"Time:","format":"{{msg.payload}}","layout":"row-spread","x":470,"y":220,"wires":[]},{"id":"72303c1.198bdc4","type":"ui_group","z":"","name":"Default","tab":"d50f4120.5bc2d","order":1,"disp":true,"width":"6","collapse":false},{"id":"d50f4120.5bc2d","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 13:13 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/32 "2020-07-20T13:13:00Z")

</div>

you need to select all nodes while exporting

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 13:13 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/33 "2020-07-20T13:13:34Z")

</div>

Sorry about that.

```auto
[{"id":"2d77e272.6328ee","type":"ui_dropdown","z":"7e5c236f.8633ec","name":"","label":"Pick the Time","tooltip":"","place":"-","group":"72303c1.198bdc4","order":0,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"15 min","value":900,"type":"num"},{"label":"30 min","value":1800,"type":"num"},{"label":"45 min","value":2700,"type":"num"},{"label":"60 min","value":3600,"type":"num"}],"payload":"","topic":"","x":120,"y":300,"wires":[["6feec9f.ad92b38"]]},{"id":"cdfeb830.a33e78","type":"ui_text","z":"7e5c236f.8633ec","group":"72303c1.198bdc4","order":2,"width":0,"height":0,"name":"","label":"Time:","format":"{{msg.payload}}","layout":"row-spread","x":470,"y":220,"wires":[]},{"id":"1b9a8d7e.7c6ca3","type":"ui_switch","z":"7e5c236f.8633ec","name":"","label":"switch","tooltip":"","group":"72303c1.198bdc4","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":90,"y":80,"wires":[["69826164.f4c7"]]},{"id":"e3bbeb29.b7d7f8","type":"countdown","z":"7e5c236f.8633ec","name":"","topic":"","payloadTimerStart":"true","payloadTimerStartType":"bool","payloadTimerStop":"false","payloadTimerStopType":"bool","timer":"30","resetWhileRunning":false,"setTimeToNewWhileRunning":true,"startCountdownOnControlMessage":false,"x":270,"y":220,"wires":[[],["cdfeb830.a33e78"]]},{"id":"6feec9f.ad92b38","type":"change","z":"7e5c236f.8633ec","name":"","rules":[{"t":"set","p":"time","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":300,"wires":[[]]},{"id":"69826164.f4c7","type":"change","z":"7e5c236f.8633ec","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"time","tot":"flow"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":140,"wires":[["e3bbeb29.b7d7f8"]]},{"id":"72303c1.198bdc4","type":"ui_group","z":"","name":"Default","tab":"d50f4120.5bc2d","order":1,"disp":true,"width":"6","collapse":false},{"id":"d50f4120.5bc2d","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 13:21 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/34 "2020-07-20T13:21:23Z")

</div>

```auto
[{"id":"79282b81.e1b524","type":"ui_dropdown","z":"aac2052a.d31d18","name":"","label":"Pick the Time","tooltip":"","place":"-","group":"2cbbe9ad.d21546","order":0,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"15 min","value":900,"type":"num"},{"label":"30 min","value":1800,"type":"num"},{"label":"45 min","value":2700,"type":"num"},{"label":"60 min","value":3600,"type":"num"}],"payload":"","topic":"","x":200,"y":260,"wires":[["b09d3114.368b2","42e56d09.67a354"]]},{"id":"b09d3114.368b2","type":"change","z":"aac2052a.d31d18","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":260,"wires":[["aa8804ca.299348","9a915a64.b1c598"]]},{"id":"aa8804ca.299348","type":"countdown","z":"aac2052a.d31d18","name":"","topic":"","payloadTimerStart":"true","payloadTimerStartType":"bool","payloadTimerStop":"false","payloadTimerStopType":"bool","timer":"30","resetWhileRunning":false,"setTimeToNewWhileRunning":true,"startCountdownOnControlMessage":false,"x":350,"y":180,"wires":[[],["5d84d31d.7fa3dc"]]},{"id":"5d84d31d.7fa3dc","type":"ui_text","z":"aac2052a.d31d18","group":"2cbbe9ad.d21546","order":2,"width":0,"height":0,"name":"","label":"Time:","format":"{{msg.payload}}","layout":"row-spread","x":550,"y":180,"wires":[]},{"id":"93e6bd6f.00c8a","type":"ui_switch","z":"aac2052a.d31d18","name":"","label":"switch","tooltip":"","group":"2cbbe9ad.d21546","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":170,"y":40,"wires":[["aa8804ca.299348"]]},{"id":"2cbbe9ad.d21546","type":"ui_group","z":"","name":"Default","tab":"13471ceb.be5043","order":1,"disp":true,"width":"6","collapse":false},{"id":"13471ceb.be5043","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 13:32 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/35 "2020-07-20T13:32:30Z")

</div>

Thanks a lot! One last thing. I need a function to convert it into min:sec type. How can I do that?

---

<div class="post-metadata">

### Author: ![kushan-athukorala](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kushan-athukorala/32/21830_2.png) [@kushan-athukorala](https://discourse.nodered.org/u/kushan-athukorala)
#### Post date: [20 July 2020 13:36 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/36 "2020-07-20T13:36:27Z")

</div>

Use a function node and follow this

> <https://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds>

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [20 July 2020 15:17 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/37 "2020-07-20T15:17:54Z")

</div>

Thanks a lot! I'll look into that. I don't know how I am going to get those values to the payload.

Also, I failed at the buzzer part. I wrote a function like this:

```auto
var cdtimer = msg.payload;
var buzz = 0;
if(cdtimer === 0)
{
    buzz = 1;
    msg.payload = buzz;
    return msg.payload;
}
msg.payload = buzz;
    return msg.payload;

```

It says that the node is trying to send message of type number. How can I fix this? I am trying to make the buzzer beep for 10 times, each beep lasting a second, then a second delay after each beep.

Edit: I did the formatting part. Now, only the buzzer part is left. I am using GPIO13 for it. Digital Output. Initial state is 0.

---

<div class="post-metadata">

### Author: ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)
#### Post date: [20 July 2020 18:59 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/38 "2020-07-20T18:59:51Z")

</div>

I had to come back to the remaining time formatting issue as it started bugging me. If you're running Node-RED 1.1.x, you can use a change node to set/change `msg.payload` to the following JSONata expression:

```auto
$moment(
  $moment()
    .add($$.payload, 'seconds')
    .diff($moment())
).utc().format('HH:mm:ss')

```

Example flow demonstrating this that uses `node-red-contrib-countdown-timer`:

```auto
[{"id":"f2eba734.051738","type":"inject","z":"b8fa20a2.14b8d","name":"start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"120","payloadType":"num","x":110,"y":60,"wires":[["a4fd2253.6ab0b"]]},{"id":"a4fd2253.6ab0b","type":"countdown","z":"b8fa20a2.14b8d","name":"","topic":"","payloadTimerStart":"120","payloadTimerStartType":"num","payloadTimerStop":"0","payloadTimerStopType":"num","timer":"120","resetWhileRunning":true,"setTimeToNewWhileRunning":true,"startCountdownOnControlMessage":false,"x":270,"y":80,"wires":[[],["34975603.a3d00a"]]},{"id":"34975603.a3d00a","type":"change","z":"b8fa20a2.14b8d","name":"format time","rules":[{"t":"set","p":"payload","pt":"msg","to":"$moment(\t $moment()\t .add($$.payload, 'seconds')\t .diff($moment())\t).utc().format('HH:mm:ss')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":160,"wires":[["11461e72.1c5e22"]]},{"id":"11461e72.1c5e22","type":"debug","z":"b8fa20a2.14b8d","name":"time remaining","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"time","statusType":"auto","x":480,"y":160,"wires":[]},{"id":"f54500c2.30ae5","type":"inject","z":"b8fa20a2.14b8d","name":"reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"120","payloadType":"num","x":110,"y":100,"wires":[["a4fd2253.6ab0b"]]}]

```

I don't know if this is the simplest way using JSONata but at least it seems to work. 🙂

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [21 July 2020 10:49 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/39 "2020-07-21T10:49:20Z")

</div>

This fixed the issue for 1+ hours. But now, I see 23:59:59 in off state. How can I make it 00:00:00, or just empty?

---

<div class="post-metadata">

### Author: ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)
#### Post date: [21 July 2020 21:45 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/40 "2020-07-21T21:45:15Z")

</div>

I noticed something similar. The countdown node allows setting an on and off payload that are sent from the first output. Experiment sending a value from that output to your dashboard?

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [23 July 2020 07:28 UTC](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387/41 "2020-07-23T07:28:33Z")

</div>

I didn't understand what you suggest.

[Previous page](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387.md?page=1)

[Next page](https://discourse.nodered.org/t/need-help-with-making-a-countdown-timer-display/30387.md?page=3)
