-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
258 lines (248 loc) · 10.3 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
<!--
The MIT License (MIT)
Copyright (c) 2016 @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('time-range-switch', {
category: 'function',
color: '#f37a33',
defaults: {
name: {
value: ''
},
lat: {
value: ''
},
lon: {
value: ''
},
startTime: {
value: '07:28'
},
endTime: {
value: 'goldenHour'
},
startOffset: {
value: 0
},
endOffset: {
value: 0
}
},
inputs: 1,
outputs: 2,
outputLabels: function(index) {
if (index === 0) return "within";
if (index === 1) return "outside";
},
icon: 'switch.png',
label: function () {
return this.name || this.startTime + ' - ' + this.endTime;
},
paletteLabel: 'time range',
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="time-range-switch">
<div class="form-row">
<label for="node-input-name">
<i class="icon-tag"></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-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>
<hr>
<div class="form-row">
<label for="node-input-startTime">
<i class="icon-tag"></i>Start time</label>
<input type="text" id="node-input-startTime" placeholder="">
</div>
<div class="form-row">
<label for="node-input-startOffset">
<i class="icon-tag"></i>Start time offset</label>
<input type="text" id="node-input-startOffset" placeholder="">
</div>
<div class="form-row">
<label for="node-input-endTime">
<i class="icon-tag"></i> End time</label>
<input type="text" id="node-input-endTime" placeholder="">
</div>
<div class="form-row">
<label for="node-input-endOffset">
<i class="icon-tag"></i> End time offset</label>
<input type="text" id="node-input-endOffset" placeholder="">
</div>
</script>
<script type="text/x-red" data-help-name="time-range-switch">
<h1>Time Range Switch</h1>
<p>A simple node that routes messages depending on the time. If the current time falls within the range specified in the
node configuration, the message is routed to output 1. Otherwise the message is routed to output 2.
</p>
<p>The times can be a 24 hour time or a
<a href="https://github.com/mourner/suncalc" target="newWindow">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>a 24h time in hours and minutes</td>
</tr>
<tr>
<td>
<code>00:00:01 ... 23:59:13</code>
</td>
<td>a 24h time in hours, minutes and seconds</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 start and end 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, the start time will be 60
minutes before dusk.</li>
<li>+ve number delays the time by the specified number of minutes</li>
</ul>
<h2 id="offsets">Programmatic Configuration</h2>
<p>This node can be controlled programmatically by sending configuration settings to the node input.</p>
<p><em>It is very important to note that properties set programmatically in this manner are transient. They will not persist over a NodeRED restart or redeploy!</em></p>
<p>E.g. send the following to the input:</p>
<pre>
msg.__config = {
startTime: '12:35',
endTime: 'dusk',
startOffset: 0,
endOffset: 0,
lat: 51.33411,
lon: -0.83716
}
</pre>
<p>You can send any combination of those configuration properties. For example, you might just want to set `startTime` and `endTime`, so you only include those properties in the configuration object.</p>
<p>If you send a message to the input with only the __config object included, the node will consume the message and emit no output. </p>
<p>If you send a message to the input with the __config object included and/or a payload/topic, the node will firstly process the __config object, remove it from the message and allow the remainder of the message to be emitted as per the configured rules.</p>
</script>