forked from marc-gist/node-red-contrib-countdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countdown.html
229 lines (204 loc) · 10.7 KB
/
countdown.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<script type="text/x-red" data-template-name="countdown">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="node-red:common.label.topic"></span></label>
<input type="text" id="node-input-topic">
</div>
<div class="form-row">
<label for="node-input-payloadTimerStart"><i class="fa fa-tag"></i> Timer On payload</label>
<input style="width:70%" type="text" id="node-input-payloadTimerStart">
<input type="hidden" id="node-input-payloadTimerStartType">
</div>
<div class="form-row">
<label for="node-input-payloadTimerStop"><i class="fa fa-tag"></i> Timer Off payload</label>
<input style="width:70%" type="text" id="node-input-payloadTimerStop">
<input type="hidden" id="node-input-payloadTimerStopType">
</div>
<div class="form-row">
<label for="node-input-timer"><i class="fa fa-clock-o"></i> Countdown </label>
<input style="width:15%" type="text" id="node-input-timer" placeholder="30">
</div>
<div class="form-row">
<label for="node-input-minuteCounter"> </label>
<input style="display:inline-block; width:15px; vertical-align:baseline;" type="checkbox" id="node-input-minuteCounter">
<span>Counter is in Minutes (checked. Default is Seconds)</span>
</div>
<div class="form-row">
<label for="node-input-resetWhileRunning"> </label>
<input style="display:inline-block; width:15px; vertical-align:baseline;" type="checkbox" id="node-input-resetWhileRunning">
<span>Restart countdown if message is received while running</span>
</div>
<div class="form-row">
<label for="node-input-setTimeToNewWhileRunning"> </label>
<input style="display:inline-block; width:15px; vertical-align:top;" type="checkbox" id="node-input-setTimeToNewWhileRunning">
<span style="display:inline-block; width:70%">Set time to new duration if control message is received while running</span>
</div>
<div class="form-row">
<label for="node-input-startCountdownOnControlMessage"> </label>
<input style="display:inline-block; width:15px; vertical-align:top;" type="checkbox" id="node-input-startCountdownOnControlMessage">
<span style="display:inline-block; width:70%">Start countdown if control message is received while not running</span>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
</script>
<script type="text/x-red" data-help-name="countdown">
<p>
Countdown-3000 - A simple countdown node. It starts countdown on any input. The countdown timer can be stopped immediately or can be reloaded with a
new counter value while it running.
</p>
<h3>Input</h3>
<h4>Starting the timer</h4>
<dl class="message-properties">
<dt>payload
<span class="property-type"></span>
</dt>
<dd>any <code>msg.payload</code> that does not stop the timer or reload the timer starts the timer.</dd>
</dl>
<h4>Starting the timer (formal values - see above too)</h4>
<dl class="message-properties">
<dt>payload
<span class="property-type">boolean | number</span>
</dt>
<dd>if <code>true</code> or <code>1</code> or <code>start</code> or <code>on</code>: Immediately starts the timer and sends output as per configuration </dd>
</dl>
<h4>Stopping the timer</h4>
<dl class="message-properties">
<dt>payload
<span class="property-type">boolean | number</span>
</dt>
<dd>if <code>false</code> or <code>0</code> or <code>stop</code> or <code>off</code>: Immediately stops the timer and sends output as per configuration </dd>
</dl>
<h4><B>Cancelling or reloading the timer and alternative stop and start methods</B></h4>
<P>For all the commands below, the message topic is set to <code><B>control</B></code>. Values are NOT case sensitive.<br /></P>
<dl class="message-properties">
<dt>payload
<span class="property-type">string</span>
</dt>
<dd>Payload = <code>cancel</code>: Timer is stopped and <b>NO</b> output is sent.</dd>
</dl>
<dl class="message-properties">
<dt>payload
<span class="property-type">string</span>
</dt>
<dd>Payload = <code>reset</code>: Timer restarts using the default (GUI) timer value.</dd>
</dl>
<dl class="message-properties">
<dt>payload
<span class="property-type">string</span>
</dt>
<dd>Payload = <code>preload</code>: Timer restarts using the currently set count value.<br /><br /></dd>
<P>The 'preload' command will restart a count at the current set value provided the<br />
value is not zero and the count is NOT currently running.<br /></P>
</dl>
<dl class="message-properties">
<dt>payload
<span class="property-type">string</span>
</dt>
<dd>Payload = <code>pause</code>: Timer countdown is paused.<br /><br /></dd>
<P>While the timer is paused, the node will still output the current<br />
(paused) countdown value every second.<br /></P>
</dl>
<h4><B>Reloading the timer</B></h4>
<P>The timer can be loaded with a new value at any time as below. To override the GUI set<br />
value, stop or cancel the counter, set a new value and then start the counter with the 'preload' command.<br /></P>
<dl class="message-properties">
<dt>payload
<span class="property-type">number | string</span>
</dt>
<dd>
if <code>Number</code>: reloads the timer with the desired <code>msg.payload</code> value.<br />
if <code>Negative integer</code>: Timer will subtract the <code>msg.payload</code> value from the current countdown.<br />
if <code>Signed string</code>: timer will add or subtract the <code>msg.payload</code> value from the current countdown.<br />
if <code>Positive or negative number with fraction</code>: timer will add or subtract the <code>msg.payload</code><br >
whole number part from the current countdown. Examples: -10.1, 12.2, "-3.4", "11.2"<br /><br /></dd>
<p>Numbers can be input as integers, numbers with fractional parts or strings in number format. The<br />
only exception is integers with a positive sign (eg: +12), where the sign is ignored.<br />
If you want to add a positive value to the count, make it a fraction or a string - eg: 12.1 or "+12".<br /><br />
If any adjustment makes the count value less than zero, the count ends.</p>
<dt>topic <span class="property-type">integer|fraction|string</span></dt>
<dd>set to <code>control</code>.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Primary output
<dl class="message-properties">
<dt>payload <span class="property-type"></span></dt>
<dd>Configurable output <code>msg</code> at the countdown start/stop.</dd>
</dl>
</li>
<li>Second output
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>Outputs the remaining time scaled to seconds or minutes depending on the node's setting in the GUI.<br >
Also outputs <code>true</code> when the counter starts and <code>false</code> when the counter reaches zero.<br /><br />
The first counter numeric value is output 1 second after the count starts, so if the node is set to count from<br />
25 seconds, the first output is 24. The last counter output is 0.<br /></dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>
<code>node-red-contrib-countdown-3000 </code> starts a countdown timer on a received input
<code>msg</code> and decreases the counter value until the countdown timer elapses.
The countdown can be stopped at any time.The countdown timer can be set to a new<br />
countdown value at any time to restart the timer with a specific value.
</p>
<p>
At the <b>first output</b> the node can emit a <code>msg</code> with an arbitrary <code>msg.payload</code> contents at<br />
the start and end of the timer.<br /><br />
At the <b>second output</b> the node emits true and false values when the timer starts and ends. During the count, <br />
the remaining time is output every second. The outout will be in seconds or minutes according to the related node<br />
setting in the GUI.
</p>
<p>
The node's output <code>msg</code> can optionally contain an arbitrary topic string.<br /><br />
This code is based on node-red-contrib-countdown-2 V1.4.2 by Marc, with bug fixes and<br />
enhancements, while retaining broad compatibility with that version.<br /><br />
Released under the MIT licence by linker3000 (Nigel Kendrick https://github.com/linker3000).<br /><br />
No warranties, use at your own risk etc.<br />
</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('countdown', {
category: "function",
color:"#ffaaaa",
inputLabels: "Any input starts the timer",
outputLabels: ["Countdown start/stop messages", "Remaining time in seconds"],
defaults: {
name: { value: "" },
topic: { value: "" },
payloadTimerStart: { value: true, validate: RED.validators.typedInput('payloadTimerStartType')},
payloadTimerStartType: { value: 'bool' },
payloadTimerStop: { value: false, validate: RED.validators.typedInput('payloadTimerStopType')},
payloadTimerStopType: { value: 'bool' },
timer: { value: 30, validate:RED.validators.number() },
resetWhileRunning: { value: false },
setTimeToNewWhileRunning: { value: true },
startCountdownOnControlMessage: { value: false },
minuteCounter: { value: false }
},
inputs: 1,
outputs: 2,
icon: "stopwatch.png",
label: function() {
return this.name || "countdown";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
var optionNothing = { value: "nul", label: "Nothing", hasValue: false};
$('#node-input-payloadTimerStart').typedInput({
default: 'bool',
typeField: $("#node-input-payloadTimerStartType"),
types: ['str','num','bool','json','bin','re','date','env', optionNothing]
});
$('#node-input-payloadTimerStop').typedInput({
default: 'bool',
typeField: $("#node-input-payloadTimerStopType"),
types: ['msg','str','num','bool','json','bin','re','date','env', optionNothing]
});
}
});
</script>