-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
561 lines (554 loc) · 22.4 KB
/
index.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
<!--
The MIT License (MIT)
Copyright (c) 2015 @biddster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<script type="text/javascript">
RED.nodes.registerType('schedex', {
category: 'input',
color: '#f37a33',
defaults: {
name: { value: '' },
passthroughunhandled: { value: false },
suspended: { value: false },
lat: { value: '' },
lon: { value: '' },
ontime: { value: '07:28' },
ontopic: { value: '' },
onpayload: { value: '' },
onoffset: { value: 0 },
onrandomoffset: { value: 0 },
offtime: { value: 'goldenHour' },
offtopic: { value: '' },
offpayload: { value: '' },
offoffset: { value: 0 },
offrandomoffset: { value: 0 },
mon: { value: true },
tue: { value: true },
wed: { value: true },
thu: { value: true },
fri: { value: true },
sat: { value: true },
sun: { value: true },
},
inputs: 1,
outputs: 1,
icon: 'datetime.png',
label: function () {
return this.name || this.ontime + ' - ' + this.offtime;
},
paletteLabel: 'schedex',
align: 'left',
oneditprepare: function () {
if (!$('#node-input-lat').val().trim() && !$('#node-input-lon').val().trim()) {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(function (position) {
$('#node-input-lat').val(Number(position.coords.latitude.toFixed(5)));
$('#node-input-lon').val(Number(position.coords.longitude.toFixed(5)));
});
}
}
},
});
</script>
<script type="text/x-red" data-template-name="schedex">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag" style="width: 16px"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<hr />
<div class="form-row">
<label for="node-input-lat"
><i class="fa fa-calendar" style="width: 16px"></i> Schedule</label
>
<table style="display: inline-block; position: relative; top: 5px; left: -5px;">
<tr>
<td>
<input
type="checkbox"
id="node-input-mon"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Mon
</td>
<td>
<input
type="checkbox"
id="node-input-tue"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Tue
</td>
<td>
<input
type="checkbox"
id="node-input-wed"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Wed
</td>
<td>
<input
type="checkbox"
id="node-input-thu"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Thu
</td>
<td>
<input
type="checkbox"
id="node-input-fri"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Fri
</td>
<td>
<input
type="checkbox"
id="node-input-sat"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Sat
</td>
<td>
<input
type="checkbox"
id="node-input-sun"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>Sun
</td>
</tr>
</table>
</div>
<div class="form-row">
<label style="margin-left: 100px; width: 70%">
<input
type="checkbox"
id="node-input-suspended"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>
Suspend scheduling
</label>
</div>
<hr />
<div class="form-row">
<label for="node-input-lat"><i class="fa fa-globe" style="width: 16px"></i> Latitude</label>
<input type="text" id="node-input-lat" placeholder="51.025" />
</div>
<div class="form-row">
<label for="node-input-lon"
><i class="fa fa-globe" style="width: 16px"></i> Longitude</label
>
<input type="text" id="node-input-lon" placeholder="-1.4" />
</div>
<hr />
<div class="form-row">
<label for="node-input-ontime"
><i class="fa fa-clock-o" style="width: 16px"></i> On time</label
>
<input type="text" id="node-input-ontime" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-ontopic"
><i class="fa fa-tasks" style="width: 20px"></i>On Topic</label
>
<input type="text" id="node-input-ontopic" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-onpayload"
><i class="fa fa-envelope" style="width: 20px"></i>On Payload</label
>
<input type="text" id="node-input-onpayload" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-onoffset"
><i class="fa fa-arrows-h" style="width: 20px"></i>On Offset</label
>
<input type="number" id="node-input-onoffset" placeholder="0" />
</div>
<div class="form-row">
<label style="margin-left: 100px; width: 70%">
<input
type="checkbox"
id="node-input-onrandomoffset"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>
Use random on time within offset period
</label>
</div>
<hr />
<div class="form-row">
<label for="node-input-offtime"
><i class="fa fa-clock-o" style="width: 16px"></i> Off time</label
>
<input type="text" id="node-input-offtime" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-offtopic"
><i class="fa fa-tasks" style="width: 20px"></i>Off Topic</label
>
<input type="text" id="node-input-offtopic" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-offpayload"
><i class="fa fa-envelope" style="width: 20px"></i>Off Payload</label
>
<input type="text" id="node-input-offpayload" placeholder="" />
</div>
<div class="form-row">
<label for="node-input-offoffset"
><i class="fa fa-arrows-h" style="width: 20px"></i>Off Offset</label
>
<input type="number" id="node-input-offoffset" placeholder="0" />
</div>
<div class="form-row">
<label style="margin-left: 100px; width: 70%">
<input
type="checkbox"
id="node-input-offrandomoffset"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;"
/>
Use random off time within offset period
</label>
</div>
<hr />
<div class="form-row">
<label title="If enabled, input messages that are not handled by Schedex are sent to the output."
><i class="fa fa-arrow-circle-right" style="width: 16px"></i>Passthrough</label
>
<label style="display: inline-block; position: relative; left: -4px; width: 70%">
<input
type="checkbox"
id="node-input-passthroughunhandled"
placeholder=""
style="width: 20px; margin: -4px 0 0 0;">
Passthrough unhandled messages
</label>
</div>
</script>
<script type="text/x-red" data-help-name="schedex">
<!-- START -->
<h1 id="schedex">Schedex</h1>
<p>Scheduler for node-red which allows you to enter on/off times as 24hr clock (e.g. 01:10) or suncalc events (e.g.<br>goldenHour). It also allows you to offset times and randomise the time within the offset.</p>
<p>Inspired by Pete Scargill's <a href="http://tech.scargill.net/big-timer/">BigTimer</a></p>
<p><strong>NOTE: When upgrading from versions prior to 1.0.0, you will see a message for each Schedex node in the Node-RED debug<br>window. This message is to advise that the Schedex configuration changed slightly in version 1.0.0 in order to<br>accomodate days of the week when scheduling. To remedy, simply edit each Schedex node, tick the days of the week you<br>want Schedex enabled and re-deploy.</strong></p>
<h1 id="installation">Installation</h1>
<p>This node requires node 10.x+. It's tested against 10.22.0.</p>
<pre><code>$ cd ~/.node-red
$ npm install node-red-contrib-schedex
</code></pre><h1 id="configuration">Configuration</h1>
<h2 id="schedule">Schedule</h2>
<p>The scheduling days allow you to choose which days of the week to schedule events. Unticking all days will suspend<br>scheduling.</p>
<h2 id="suspending-scheduling">Suspending scheduling</h2>
<p>The 'Suspend scheduling' checkbox allows you to disable time scheduling. If scheduling is suspended, Schedex will only<br>generate output events upon receipt of input 'on' and 'off' events (see below).</p>
<p>This setting is provided for the situation where you temporarily don't want time based activation and don't want to rewire your Node-RED flow.</p>
<blockquote>
<p>Note that scheduling is suspended if you do not enter an on or off time in the node configuration.</p>
</blockquote>
<h2 id="times">Times</h2>
<blockquote>
<p>Note that on and off times are independent. You only need to configure one or the other or both. You can leave the on or off time field blank in the node configuration and no output will be emitted.</p>
</blockquote>
<p>The times can be a 24 hour time or a <a href="https://github.com/mourner/suncalc">suncalc</a> event:</p>
<table>
<thead>
<tr>
<th>Time</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>00:00 ... 23:59</code></td>
<td>24hr time</td>
</tr>
<tr>
<td><code>sunrise</code></td>
<td>sunrise (top edge of the sun appears on the horizon)</td>
</tr>
<tr>
<td><code>sunriseEnd</code></td>
<td>sunrise ends (bottom edge of the sun touches the horizon)</td>
</tr>
<tr>
<td><code>goldenHourEnd</code></td>
<td>morning golden hour (soft light, best time for photography) ends</td>
</tr>
<tr>
<td><code>solarNoon</code></td>
<td>solar noon (sun is in the highest position)</td>
</tr>
<tr>
<td><code>goldenHour</code></td>
<td>evening golden hour starts</td>
</tr>
<tr>
<td><code>sunsetStart</code></td>
<td>sunset starts (bottom edge of the sun touches the horizon)</td>
</tr>
<tr>
<td><code>sunset</code></td>
<td>sunset (sun disappears below the horizon, evening civil twilight starts)</td>
</tr>
<tr>
<td><code>dusk</code></td>
<td>dusk (evening nautical twilight starts)</td>
</tr>
<tr>
<td><code>nauticalDusk</code></td>
<td>nautical dusk (evening astronomical twilight starts)</td>
</tr>
<tr>
<td><code>night</code></td>
<td>night starts (dark enough for astronomical observations)</td>
</tr>
<tr>
<td><code>nadir</code></td>
<td>nadir (darkest moment of the night, sun is in the lowest position)</td>
</tr>
<tr>
<td><code>nightEnd</code></td>
<td>night ends (morning astronomical twilight starts)</td>
</tr>
<tr>
<td><code>nauticalDawn</code></td>
<td>nautical dawn (morning nautical twilight starts)</td>
</tr>
<tr>
<td><code>dawn</code></td>
<td>dawn (morning nautical twilight ends, morning civil twilight starts)</td>
</tr>
</tbody>
</table>
<h2 id="offsets">Offsets</h2>
<p>The on and off time can have an offset. This is specified in minutes:</p>
<ul>
<li>-ve number brings the time forward. E.g. if the time is dusk and offset is -60, a message will be generated 60 minutes<br>before dusk.</li>
<li>+ve number delays the time by the specified number of minutes</li>
</ul>
<h2 id="randomisation-of-times">Randomisation of times</h2>
<p>Both on and off times can be randomised by ticking "Use random time within offset period". For example, if you specify<br>dusk with an offset of -60 minutes, every day a message will be generated at a random time in a 60 minute window before<br>dusk.</p>
<h2 id="message-passthrough">Message passthrough</h2>
<p>When <code>Passthrough unhandled messages</code> is enabled, any message that isn't explicitly handled by Schedex will be immediately emitted.<br>To clarify, if the input payload does not match any one of the programmatic options above, along with<br>the on|off|toggle|info|info_local commands, the message will be sent to output.</p>
<p>With <code>Passthough unhandled messages</code>disabled (the default), any message that isn't handled by Schedex will be dropped and an error reported.</p>
<h2 id="inputs">Inputs</h2>
<p>You can wire inject nodes to the input of this node and send the following in <code>msg.payload</code>.</p>
<table>
<thead>
<tr>
<th>msg.payload</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>on</code></td>
<td>Triggers manual on mode and causes Schedex to emit the configured on event. Manual mode is reset when the next on or off time is reached</td>
</tr>
<tr>
<td><code>off</code></td>
<td>Triggers manual off mode and causes Schedex to emit the configured off event. Manual mode is reset when the next on or off time is reached</td>
</tr>
<tr>
<td><code>toggle</code></td>
<td>Triggers either the manual on or manual off mode. If the last event was the on event, toggle will cause schedex to emit the off event and vice versa. State is not maintained over restarts and deploys. Schedex assumes off upon start so the first toggle will emit the on event.</td>
</tr>
<tr>
<td><code>info</code></td>
<td>Schedex emits an object containing the on and off times in UTC format. It also contains the state which is either on or off along with the rest of this node's configuration. Note that the output message contains the actuated state. This will be null (if an event hasn't happened yet) or 'on' or 'off'.</td>
</tr>
<tr>
<td><code>info_local</code></td>
<td>Emits the information exactly the same as the <code>info</code> command but with the on and off times in local ISO format.</td>
</tr>
<tr>
<td><code>send_state</code></td>
<td>Causes Schedex to emit the current state as a message with either the on or off topic/payload set. If Schedex is suspended, this command emits nothing.</td>
</tr>
</tbody>
</table>
<h2 id="programmatic-control">Programmatic Control</h2>
<p>This node supports programmatic time control as well as configuration via the NodeRED UI.</p>
<p><strong>It is very important to note that properties set programmatically in this manner are transient. They will not persist<br>over a NodeRED restart or redeploy!</strong></p>
<p>Note that both the property-based and string-based specifications are overrides that violate the usual behavior.<br>See here for further discussion <a href="https://github.com/node-red/node-red/issues/399">https://github.com/node-red/node-red/issues/399</a>.</p>
<p>You can set the following:</p>
<table>
<thead>
<tr>
<th>Property</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>msg.payload.suspended</code></td>
<td>Boolean: true will suspend scheduling, false will resume scheduling</td>
</tr>
<tr>
<td><code>msg.payload.ontime</code></td>
<td>String value as specified in the table above for time configuration</td>
</tr>
<tr>
<td><code>msg.payload.ontopic</code></td>
<td>String value emitted as the topic for the on event</td>
</tr>
<tr>
<td><code>msg.payload.onpayload</code></td>
<td>String value emitted as the payload for the on event</td>
</tr>
<tr>
<td><code>msg.payload.onoffset</code></td>
<td>Number value as specified above for Offset configuration</td>
</tr>
<tr>
<td><code>msg.payload.onrandomoffset</code></td>
<td>Boolean value as specified above in Randomisation of Times</td>
</tr>
<tr>
<td><code>msg.payload.offtime</code></td>
<td>String value as specified in the table above for time configuration</td>
</tr>
<tr>
<td><code>msg.payload.offtopic</code></td>
<td>String value emitted as the topic for the off event</td>
</tr>
<tr>
<td><code>msg.payload.offpayload</code></td>
<td>String value emitted as the payload for the off event</td>
</tr>
<tr>
<td><code>msg.payload.offoffset</code></td>
<td>Number value as specified above for Offset configuration</td>
</tr>
<tr>
<td><code>msg.payload.offrandomoffset</code></td>
<td>Boolean value as specified above in Randomisation of Times</td>
</tr>
<tr>
<td><code>msg.payload.mon</code></td>
<td>Boolean: true enables the schedule on a Monday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.tue</code></td>
<td>Boolean: true enables the schedule on a Tuesday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.wed</code></td>
<td>Boolean: true enables the schedule on a Wednesday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.thu</code></td>
<td>Boolean: true enables the schedule on a Thursday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.fri</code></td>
<td>Boolean: true enables the schedule on a Friday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.sat</code></td>
<td>Boolean: true enables the schedule on a Saturday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.sun</code></td>
<td>Boolean: true enables the schedule on a Sunday, false disables it.</td>
</tr>
<tr>
<td><code>msg.payload.passthroughunhandled</code></td>
<td>Boolean: true enables unhandled input messages to automatically be sent to output.</td>
</tr>
</tbody>
</table>
<p>Alternatively, you can send msg.payload as a string with the following values:</p>
<table>
<thead>
<tr>
<th>Example msg.payload</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>suspended true</code></td>
<td>true will suspend scheduling, false will resume scheduling</td>
</tr>
<tr>
<td><code>ontime 12:00</code></td>
<td>Time as specified in the table above for time configuration</td>
</tr>
<tr>
<td><code>ontopic my_topic</code></td>
<td>Sets the topic for the on event (no spaces)</td>
</tr>
<tr>
<td><code>onpayload my_payload</code></td>
<td>Sets the payload for the on event (no spaces)</td>
</tr>
<tr>
<td><code>onoffset 30</code></td>
<td>Sets the offset for the on event</td>
</tr>
<tr>
<td><code>onrandomoffset true</code></td>
<td>Sets the random offset for the on event</td>
</tr>
<tr>
<td><code>offtime dusk</code></td>
<td>Time as specified in the table above for time configuration</td>
</tr>
<tr>
<td><code>offtopic my_topic</code></td>
<td>Sets the topic for the off event (no spaces)</td>
</tr>
<tr>
<td><code>offpayload my_payload</code></td>
<td>Sets the payload for the off event (no spaces)</td>
</tr>
<tr>
<td><code>offoffset -30</code></td>
<td>Sets the offset for the off event</td>
</tr>
<tr>
<td><code>offrandomoffset false</code></td>
<td>Sets the random offset for the off event</td>
</tr>
<tr>
<td><code>mon false</code></td>
<td>Disables the schedule on a Monday</td>
</tr>
<tr>
<td><code>tue true</code></td>
<td>Enables the schedule on a Tuesday</td>
</tr>
<tr>
<td><code>ontime 16:30 onoffset 60 onrandomoffset true</code></td>
<td>Sets the time, offset and random offset for the on event</td>
</tr>
<tr>
<td><code>passthroughunhandled false</code></td>
<td>Disabled unhandled input messages automatically being sent to output</td>
</tr>
</tbody>
</table>
<h3 id="enabling-extra-debugging">Enabling extra debugging</h3>
<p>Install <code>node-red-contrib-config</code> and drag a config node into your workspace. Configure the node to set a global variable called <code>schedex</code><br>with a JSON value of <code>{"debug": true}</code>. Also make sure that the config tickbox for <code>active</code> is unchecked. Redeploy. Now click the button on the config node.<br>This will trigger all instances of <code>schedex</code> to write extra logging to the os syslog next time they're invoked.</p>
<!-- END -->
</script>