node-red-contrib-countdown
is a simple countdown node.
It starts a countdown timer on a received input msg
and decreases the counter value (at the first output) until the countdown timer elapses. The countdown can be stopped at any time. Also the countdown timer can be set to any new countdown value at any time to reload the timer with a specific value.
The output can emit a msg
at its first output with an arbitrary msg.payload
contents at the start of the timer as well as at the stop of the countdown timer.
At the second Output the node emits the remaining counter value every second.
The node's output msg
can optionally contain an arbitrary topic string.
Loosely based on prior work by Neil Cherry: https://github.com/linuxha/node-red-contrib-mytimeout
Fig. 1: Node appearance
~/.node-red
npm install node-red-contrib-countdown
Fig. 2: Node properties
Set the Countdown value to the desired countdown time in seconds. The timer will start with this countdown value to decrease the timer value (countdown start value).
The Topic can be set to any string value. This string is added to the output msg
as an additional element msg.topic
.
Note: No value is given to the topic.
Set the Timer On payload to any payload type and value which is sent when the counter starts.
Set the Timer Off payload to any payload type and value which is sent when the counter elapses.
In both cases, also nothing to be emitted may be chosen.
You can configure the timer to
msg
is received at the node's input.msg
.msg
(i.e. a msg
with a control topic string).The node evaluates the following input msg
types:
msg
with a msg.payload
contents of false (boolean) or '0' (number).msg
type stops resp. finishes the timer. The Timer Off payload is emitted also in this case.msg
with a msg.topic
set to "control" and a msg.payload
set to an arbitrary number value. This reloads the timer with the desired msg.payload
value immediately and works at a running countdown as well as a non startet or elapsed countdown timer. msg
do start/restart the timer if it is stopped.The node contains two outputs:
msg
at the countdown start/stop instant of time. These msg.payload
contents are configurable. If Option "Send Outputmessage on Reset" ist set, the message is send, when the timer is stopped. Otherwise, the Stop message will only by send, if the timer reaches zero.msg.payload
holds the remaining counting valueThis example shows the basic behaviour with
msg
(inject node)Just activate the inject and look at the output debug node status messages.
basic flow
Fig. 3: Basic example flow
This example shows how to
Text messages are output on the first output at start and end of the countdown.
You can restart the timer by activating the inject node during the countdown runs.
messages and retriggering flow
Fig. 4: Message sending and retriggering example flow
This example shows the two options to stop the countdown timer.
stopping timer flow
Fig. 5: Timer stopping example flow
This example shows the functionality of reloading the countdown value during a running timer.
reloading timer flow
Fig. 6: Timer reload example flow