-
Notifications
You must be signed in to change notification settings - Fork 0
/
SonoffRF.html
177 lines (174 loc) · 6.64 KB
/
SonoffRF.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
<script type="text/javascript">
RED.nodes.registerType("Sonoff RF", {
category: "Sonoff",
color: "#28AFB0",
defaults: {
broker: { type: "mqtt-broker", required: true },
device: { value: "sonoff", required: true },
lightDepend: { value: "always" },
rfType: { value: "button" },
lat: {
value: "52.6706437",
validate: function(v) {
return v >= -90 && v <= 90;
}
},
lon: {
value: "6.2900917",
validate: function(v) {
return v >= -180 && v <= 180;
}
},
start: { value: "sunrise", required: true },
startOffset: { value: 0, required: true },
end: { value: "sunset", required: true },
endOffset: { value: 0, required: true },
offAfter: {
value: 300,
required: true,
validate: function(v) {
return v == 0 || (v >= 5 && v <= 24 * 60 * 60);
}
},
offObey: { value: 30, required: true },
name: { value: "" },
cmdPrefix: { value: "cmnd" },
telePrefix: { value: "tele" },
keyIds: { required: false }
},
icon: "sun.png",
inputs: 1,
outputs: 1,
label: function() {
return this.name || this.device;
},
oneditprepare: function() {
var timStr = function(time) {
return (
time.getHours() +
":" +
time
.getMinutes()
.toString()
.padStart(2, "0")
);
};
let addTimes = () => {
var times = SunCalc.getTimes(
Date.now(),
$("#node-input-lat").val(),
$("#node-input-lon").val()
);
$("#node-input-start option, #node-input-end option").each(function(
idx,
elem
) {
var html = $(elem).html();
html += ` (${timStr(times[$(elem).val()])})`;
$(elem).html(html);
});
};
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))
);
});
}
} else {
$.getScript("node-red-sonoff/js/suncalc.js").done(addTimes);
}
let daylightMode = () => {
let always = $("#node-input-lightDepend").val() == "always";
$(".dayLight").toggleClass("hidden", always);
};
$("#node-input-lightDepend").on("change", daylightMode);
}
});
</script>
<script type="text/x-red" data-template-name="Sonoff RF">
<div class="form-row">
<label for="node-input-rfType"><i class="fa fa-microchip"></i>Type</label>
<select id="node-input-rfType" style='width:70%'>
<option value="button">Button</option>
<option value="pir">Motion sensor</option>
</select>
</div>
<div class="form-row">
<label for="node-input-device"><i class="fa fa-wifi"></i>Receiver</label>
<input type="text" id="node-input-device" placeholder="Sonoff id (Default: sonoff)">
</div>
<div class="form-row">
<label for="node-input-broker"><i class="fa fa-globe"></i> Mqtt</label>
<input type="text" id="node-input-broker">
</div>
<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>
<div class="form-row">
<label for="node-input-keyIds"><i class="fa fa-key"></i> key-id(s)</label>
<input type="text" id="node-input-keyIds" placeholder="key-ids">
</div>
<div class="form-row">
<label for="node-input-offAfter"><i class="fa fa-toggle-off"></i>Auto-off after</label>
<input type="number" id="node-input-offAfter" placeholder="in seconds">
</div>
<div class="form-row">
<label for="node-input-offObey"><i class="fa fa-shield"></i>Obey-off</label>
<input type="number" id="node-input-offObey" placeholder="keep off in seconds..">
</div>
<div class="form-row">
<label for="node-input-lightDepend"><i class="fa fa-moon-o"></i>Switch when</label>
<select id="node-input-lightDepend" style='width:70%'>
<option value="always">Always, day and night</option>
<option value="night">Only at night</option>
<option value="day">Only during the day</option>
</select>
</div>
<div class="form-row dayLight">
<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 dayLight">
<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 dayLight">
<label for="node-input-start"><i class="fa fa-sun-o"></i> Sunrise</label>
<select id="node-input-start" style='width:70%'>
<option value="sunrise">Sunrise start</option>
<option value="sunriseEnd">Sunrise end</option>
<option value="dawn">Dawn, morning civil twilight starts</option>
<option value="goldenHourEnd">End of morning golden hour</option>
<option value="nauticalDawn">Morning nautical twilight starts</option>
<option value="nightEnd">Morning astronomical twilight starts</option>
</select>
</div>
<div class="form-row dayLight">
<label for="node-input-startOffset"><i class="fa fa-plus-square"></i>Sunrise delay</label>
<input type="number" id="node-input-startOffset" placeholder=" + or - in minutes">
</div>
<div class="form-row dayLight">
<label for="node-input-end"><i class="fa fa-moon-o"></i> Sunset</label>
<select id="node-input-end" style='width:70%'>
<option value="sunset">Sunset, civil twilight starts</option>
<option value="sunsetStart">Sunset start</option>
<option value="goldenHour">Start of evening golden hour</option>
<option value="dusk">Dusk, Evening astronomical twilight starts</option>
<option value="nauticalDusk">Evening nautical twilight starts</option>
<option value="night">Dark enough for astronomy</option>
</select>
</div>
<div class="form-row dayLight">
<label for="node-input-endOffset"><i class="fa fa-plus-square"></i>Sunset delay</label>
<input type="number" id="node-input-endOffset" placeholder="min int">
</div>
</script>