-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscheduler.html
390 lines (372 loc) · 18 KB
/
scheduler.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
<!--
Mostly - apart from the Sunrise module on which this depends
this is copyright (c) Peter Scargill - but as I've had so
many ideas from others - consider it free to use for whatever
purpose you like. If you redesign it please remember to drop
my name and link in there somewhere. http://tech.scargill.net
This software puts out one of two messages on change of state
which could be sent to the MQTT node and can be triggered by
the INJECT module (should be triggered once every minute)
-->
<script type="text/x-red" data-template-name="scheduler">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-starttime"><i class="fa fa-clock-o"></i> On Time</label>
<select id="node-input-starttime" style="width:73% !important">
<option value= "0">00:00</option>
<option value= "15">00:15</option>
<option value= "30">00:30</option>
<option value= "45">00:45</option>
<option value= "60">01:00</option>
<option value= "75">01:15</option>
<option value= "90">01:30</option>
<option value="105">01:45</option>
<option value="120">02:00</option>
<option value="135">02:15</option>
<option value="150">02:30</option>
<option value="165">02:45</option>
<option value="180">03:00</option>
<option value="195">03:15</option>
<option value="210">03:30</option>
<option value="225">03:45</option>
<option value="240">04:00</option>
<option value="255">04:15</option>
<option value="270">04:30</option>
<option value="285">04:45</option>
<option value="300">05:00</option>
<option value="315">05:15</option>
<option value="330">05:30</option>
<option value="345">05:45</option>
<option value="360">06:00</option>
<option value="375">06:15</option>
<option value="390">06:30</option>
<option value="405">06:45</option>
<option value="420">07:00</option>
<option value="435">07:15</option>
<option value="450">07:30</option>
<option value="465">07:45</option>
<option value="480">08:00</option>
<option value="495">08:15</option>
<option value="510">08:30</option>
<option value="525">08:45</option>
<option value="540">09:00</option>
<option value="555">09:15</option>
<option value="570">09:30</option>
<option value="585">09:45</option>
<option value="600">10:00</option>
<option value="615">10:15</option>
<option value="630">10:30</option>
<option value="645">10:45</option>
<option value="660">11:00</option>
<option value="675">11:15</option>
<option value="690">11:30</option>
<option value="705">11:45</option>
<option value="720">12:00</option>
<option value="735">12:15</option>
<option value="750">12:30</option>
<option value="765">12:45</option>
<option value="780">13:00</option>
<option value="795">13:15</option>
<option value="810">13:30</option>
<option value="825">13:45</option>
<option value="840">14:00</option>
<option value="855">14:15</option>
<option value="870">14:30</option>
<option value="885">14:45</option>
<option value="900">15:00</option>
<option value="915">15:15</option>
<option value="930">15:30</option>
<option value="945">15:45</option>
<option value="960">16:00</option>
<option value="975">16:15</option>
<option value="990">16:30</option>
<option value="1005">16:45</option>
<option value="1020">17:00</option>
<option value="1035">17:15</option>
<option value="1050">17:30</option>
<option value="1065">17:45</option>
<option value="1080">18:00</option>
<option value="1095">18:15</option>
<option value="1110">18:30</option>
<option value="1125">18:45</option>
<option value="1140">19:00</option>
<option value="1155">19:15</option>
<option value="1170">19:30</option>
<option value="1185">19:45</option>
<option value="1200">20:00</option>
<option value="1215">20:15</option>
<option value="1230">20:30</option>
<option value="1245">20:45</option>
<option value="1260">21:00</option>
<option value="1275">21:15</option>
<option value="1290">21:30</option>
<option value="1315">21:45</option>
<option value="1330">22:00</option>
<option value="1345">22:15</option>
<option value="1360">22:30</option>
<option value="1375">22:45</option>
<option value="1390">23:00</option>
<option value="1405">23:15</option>
<option value="1420">23:30</option>
<option value="1435">23:45</option>
<option value="5000">Dawn</option>
<option value="6000">Dusk</option>
</select>
</div>
<div class="form-row">
<label for="node-input-endtime"><i class="fa fa-clock-o"></i> Off Time</label>
<select id="node-input-endtime" style="width:73% !important">
<option value= "0">00:00</option>
<option value= "15">00:15</option>
<option value= "30">00:30</option>
<option value= "45">00:45</option>
<option value= "60">01:00</option>
<option value= "75">01:15</option>
<option value= "90">01:30</option>
<option value="105">01:45</option>
<option value="120">02:00</option>
<option value="135">02:15</option>
<option value="150">02:30</option>
<option value="165">02:45</option>
<option value="180">03:00</option>
<option value="195">03:15</option>
<option value="210">03:30</option>
<option value="225">03:45</option>
<option value="240">04:00</option>
<option value="255">04:15</option>
<option value="270">04:30</option>
<option value="285">04:45</option>
<option value="300">05:00</option>
<option value="315">05:15</option>
<option value="330">05:30</option>
<option value="345">05:45</option>
<option value="360">06:00</option>
<option value="375">06:15</option>
<option value="390">06:30</option>
<option value="405">06:45</option>
<option value="420">07:00</option>
<option value="435">07:15</option>
<option value="450">07:30</option>
<option value="465">07:45</option>
<option value="480">08:00</option>
<option value="495">08:15</option>
<option value="510">08:30</option>
<option value="525">08:45</option>
<option value="540">09:00</option>
<option value="555">09:15</option>
<option value="570">09:30</option>
<option value="585">09:45</option>
<option value="600">10:00</option>
<option value="615">10:15</option>
<option value="630">10:30</option>
<option value="645">10:45</option>
<option value="660">11:00</option>
<option value="675">11:15</option>
<option value="690">11:30</option>
<option value="705">11:45</option>
<option value="720">12:00</option>
<option value="735">12:15</option>
<option value="750">12:30</option>
<option value="765">12:45</option>
<option value="780">13:00</option>
<option value="795">13:15</option>
<option value="810">13:30</option>
<option value="825">13:45</option>
<option value="840">14:00</option>
<option value="855">14:15</option>
<option value="870">14:30</option>
<option value="885">14:45</option>
<option value="900">15:00</option>
<option value="915">15:15</option>
<option value="930">15:30</option>
<option value="945">15:45</option>
<option value="960">16:00</option>
<option value="975">16:15</option>
<option value="990">16:30</option>
<option value="1005">16:45</option>
<option value="1020">17:00</option>
<option value="1035">17:15</option>
<option value="1050">17:30</option>
<option value="1065">17:45</option>
<option value="1080">18:00</option>
<option value="1095">18:15</option>
<option value="1110">18:30</option>
<option value="1125">18:45</option>
<option value="1140">19:00</option>
<option value="1155">19:15</option>
<option value="1170">19:30</option>
<option value="1185">19:45</option>
<option value="1200">20:00</option>
<option value="1215">20:15</option>
<option value="1230">20:30</option>
<option value="1245">20:45</option>
<option value="1260">21:00</option>
<option value="1275">21:15</option>
<option value="1290">21:30</option>
<option value="1305">21:45</option>
<option value="1320">22:00</option>
<option value="1335">22:15</option>
<option value="1350">22:30</option>
<option value="1365">22:45</option>
<option value="1380">23:00</option>
<option value="1395">23:15</option>
<option value="1410">23:30</option>
<option value="1425">23:45</option>
<option value="5000">Dawn</option>
<option value="6000">Dusk</option>
<option value="10001">1 minute</option>
<option value="10002">2 minutes</option>
<option value="10005">5 minutes</option>
<option value="10010">10 minutes</option>
<option value="10015">15 minutes</option>
<option value="10030">30 minutes</option>
<option value="10060">60 minutes</option>
<option value="10090">90 minutes</option>
<option value="10120">120 minutes</option>
</select>
</div>
<div class="form-row">
<label for="node-input-duskoff"><i class="fa fa-clock-o"></i> Dusk Offs</label>
<input type="text" id="node-input-duskoff" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-dawnoff"><i class="fa fa-clock-o"></i> Dawn Offs</label>
<input type="text" id="node-input-dawnoff" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-lat"><i class="fa fa-globe"></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"></i> Longitude</label>
<input type="text" id="node-input-lon" placeholder="-1.4">
</div>
<div class="form-row">
<label for="node-input-outtopic"><i class="fa fa-tag"></i> Topic Msg</label>
<input type="text" id="node-input-outtopic" placeholder="MQTT Topic">
</div>
<div class="form-row">
<label for="node-input-outpayload1"><i class="fa fa-tag"></i> ON Msg</label>
<input type="text" id="node-input-outpayload1" placeholder="MQTT Payload">
</div>
<div class="form-row">
<label for="node-input-outpayload2"><i class="fa fa-tag"></i> OFF Msg</label>
<input type="text" id="node-input-outpayload2" placeholder="MQTT Payload">
</div>
<style>
input[type=checkbox] { vertical-align:top; position:relative; bottom:1px; }
</style>
<div>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sun" placeholder="sun" >Sun</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-mon" placeholder="mon" >Mon</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-tue" placeholder="tue" >Tue</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-wed" placeholder="wed" >Wed</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-thu" placeholder="thu" >Thu</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-fri" placeholder="fri" >Fri</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sat" placeholder="sat" >Sat</span>
</div>
<br/><br/>
<div>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jan" placeholder="jan" >Jan</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-feb" placeholder="feb" >Feb</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-mar" placeholder="mar" >Mar</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-apr" placeholder="apr" >Apr</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-may" placeholder="may" >May</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jun" placeholder="jun" >Jun</span>
<br/><br/>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jul" placeholder="jul" >Jul</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-aug" placeholder="aug" >Aug</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sep" placeholder="sep" >Sep</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-oct" placeholder="oct" >Oct</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-nov" placeholder="nov" >Nov</span>
<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-dec" placeholder="dec" >Dec</span>
</div>
</script>
<script type="text/x-red" data-help-name="Scheduler">
<p>Uses the suncalc module and timing options to generate a topic and one of two messages from output 1 - checked every minute)</p>
<p>The Dawn and Dusk offsets can be both positive (+ve) for minutes later or negative (-ve) for minutes earlier.</p>
<p>Output 1 outputs only when the manual input is pressed or when the CHANGE occurs. Output 2 simply sends "1" or "0" to the payload every minute regardless</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('scheduler',{
category: 'advanced-input',
color:"#6699ff",
defaults: {
outtopic: {value:""},
outpayload1: {value:""},
outpayload2: {value:""},
name: {value:"My Scheduler"},
lat: {value:"", required:true, validate:RED.validators.number()},
lon: {value:"", required:true, validate:RED.validators.number()},
start: {value:"sunrise", required:true},
end: {value:"sunset", required:true},
starttime: {value:"5000", required: true},
endtime: {value:"1435", required: true},
duskoff: {value:"0", required: true},
dawnoff: {value:"0", required: true},
sun: {value:true},
mon: {value:true},
tue: {value:true},
wed: {value:true},
thu: {value:true},
fri: {value:true},
sat: {value:true},
jan: {value:true},
feb: {value:true},
mar: {value:true},
apr: {value:true},
may: {value:true},
jun: {value:true},
jul: {value:true},
aug: {value:true},
sep: {value:true},
oct: {value:true},
nov: {value:true},
dec: {value:true}
},
inputs:0,
outputs:2,
icon: "timer.png",
label: function() {
return this.name||"scheduler";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
if (($("#node-input-lat").val() === "") && ($("#node-input-lon").val() === "")) {
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)));
});
}
}
},
button: {
onclick: function() {
$.ajax({
url: "scheduler/"+this.id,
type:"POST",
success: function(resp) {
RED.notify("Successfully injected: "+label,"success");
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify("<strong>Error</strong>: scheduler node not deployed","error");
} else if (jqXHR.status == 500) {
RED.notify("<strong>Error</strong>: scheduler reset failed, see log for details.","error");
} else if (jqXHR.status == 0) {
RED.notify("<strong>Error</strong>: no response from server","error");
} else {
RED.notify("<strong>Error</strong>: unexpected error: ("+jqXHR.status+") "+textStatus,"error");
}
}
});
}
}
});
</script>