forked from anerdins/node-red-contrib-nibepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.html
executable file
·133 lines (129 loc) · 5.81 KB
/
weather.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
<script type="text/javascript">
RED.nodes.registerType('nibe-weather',{
category: 'input',
color: '#e32222',
defaults: {
server: {value:"", type:"nibe-config"},
name: {value:""},
system: {value:"s1"},
sun: {value:""},
wind: {value:""},
adjust: {value:"0"},
hours: {value:"6"}
},
inputs:1,
outputs:2,
inputLabels: ["Update"],
outputLabels: ["Weather","Data"],
icon: "inject.svg",
label: function() {
return this.name||"NibePi Weather";
},
oneditprepare: function() {
$.getJSON('/config', function(data) {
let system = $("#node-input-system").val();
$("#node-input-lat").val(data.home.lat);
$("#node-input-lon").val(data.home.lon);
$("#node-input-sun").val(data.weather.sun_enable);
$("#node-input-wind").val(data.weather.wind_enable);
$("#node-input-adjust").val(data.home[`adjust_${system}`]);
$("#node-input-hours").val(data.home[`hours_${system}`]);
$('#node-input-system').change(() => {
system = $("#node-input-system").val();
$("#node-input-adjust").val(data.home[`adjust_${system}`]);
$("#node-input-hours").val(data.home[`hours_${system}`]);
});
})
},
oneditsave: function() {
let node = this;
$.getJSON('/config', function(data) {
if ($('#node-input-wind').is(':checked')) {
data.weather.wind_enable = true;
} else {
data.weather.wind_enable = false;
}
if ($('#node-input-sun').is(':checked')) {
data.weather.sun_enable = true;
} else {
data.weather.sun_enable = false;
}
let system = $("#node-input-system").val();
if(data.home['hours_'+system]===undefined) data.home['hours_'+system] = 1;
if(data.home['adjust_'+system]===undefined) data.home['adjust_'+system] = 1;
data.home.lat = $("#node-input-lat").val();
data.home.lon = $("#node-input-lon").val();
data.home['hours_'+system] = $("#node-input-hours").val();
data.home['adjust_'+system] = $("#node-input-adjust").val();
$.ajax({
contentType: 'application/json',
data: JSON.stringify({config:data,data:node}),
dataType: 'json',
success: function(data){
app.log("device control succeeded");
},
error: function(){
app.log("Device control failed");
},
processData: false,
type: 'POST',
url: "config/"+node.id
});
})
}
});
</script>
<script type="text/x-red" data-template-name="nibe-weather">
<div class="form-row">
<label for="node-input-system"><i class="icon-bookmark"></i> System</label>
<select id="node-input-system">
<option value="s1">System 1</option>
<option value="s2">System 2</option>
<!-- <option value="s3">System 3</option> -->
<!-- <option value="s4">System 4</option> -->
<!-- <option value="s5">System 5</option> -->
<!-- <option value="s6">System 6</option> -->
<!-- <option value="s7">System 7</option> -->
<!-- <option value="s8">System 8</option> -->
</select>
</div>
<div class="form-row">
<label for="node-input-lat"><i class="icon-bookmark"></i> Latitude</label>
<input type="text" id="node-input-lat">
</div>
<div class="form-row">
<label for="node-input-lon"><i class="icon-bookmark"></i> Longitude</label>
<input type="text" id="node-input-lon">
</div>
<div class="form-row">
<label> Forecast</label>
<input type="checkbox" id="node-input-sun" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-sun"> Sun</label>
<label></label>
<input type="checkbox" id="node-input-wind" style="margin-left: 0px; vertical-align: top; width: auto !important;"> <label style="width:auto !important;" for="node-input-wind"> Wind</label>
</div>
<div class="form-row">
<label for="node-input-hours"><i class="icon-bookmark"></i> Forecast time</label>
<input type="number" id="node-input-hours" min="1" max="24">
</div>
<div class="form-row">
<label for="node-input-adjust"><i class="icon-bookmark"></i> Curve Adjust</label>
<select id="node-input-adjust">
<option value="2">+2</option>
<option value="1.5">+1.5</option>
<option value="1">+1</option>
<option value="0.5">+0.5</option>
<option value="0">0</option>
<option value="-0.5">-0.5</option>
<option value="-1">-1</option>
<option value="-1.5">-1.5</option>
<option value="-2">-2</option>
</select>
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-tag"></i> Server</label>
<input type="text" id="node-input-server" placeholder="Server">
</div>
</script>
<script type="text/x-red" data-help-name="nibe-weather">
<p>Weather node for NibePi</p>
</script>