node-red-contrib-solar-power-forecast
Version:
A node-red node to forecast the output of a solar system at a specified time.
121 lines (109 loc) • 6.35 kB
HTML
<!--
Copyright 2016 Dean Cording <dean@cording.id.au>.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- First, the content of the edit dialog is defined. -->
<script type="text/x-red" data-template-name="solar power forecast">
<!-- data-template-name identifies the node type this is for -->
<!-- Each of the following divs creates a field in the edit dialog. -->
<!-- Generally, there should be an input for each property of the node. -->
<!-- The for and id attributes identify the corresponding property -->
<!-- (with the 'node-input-' prefix). -->
<div class="form-row">
<label for="node-input-lat"><i class="icon-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="icon-globe"></i> Longitude</label>
<input type="text" id="node-input-lon" placeholder="-1.4">
</div>
<div class="form-row">
<label for="node-input-altitude"><i class="icon-arrow-up"></i> Altitude (m)</label>
<input type="text" id="node-input-altitude" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-tilt"><i class="icon-resize-vertical"></i> Panel Tilt</label>
<input type="text" id="node-input-tilt" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-orientation"><i class="icon-repeat"></i> Panel Orientation</label>
<input type="text" id="node-input-orientation" placeholder="0">
</div>
<div class="form-row">
<label for="node-input-area"><i class="icon-stop"></i> Panel Area (sq m)</label>
<input type="text" id="node-input-area" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-number"><i class="icon-th"></i> Number of Panels</label>
<input type="text" id="node-input-number" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-efficiency"><i class="icon-cog"></i> Panel Efficiency (%)</label>
<input type="text" id="node-input-efficiency" placeholder="15">
</div>
<!-- By convention, most nodes have a 'name' property. The following div -->
<!-- provides the necessary field. -->
<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>
</script>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="solar power forecast">
<p>Calculates solar irradiance in watts per square meter (W/m^2) on a solar panel and the maximum power generated by a solar panel array under ideal conditions.</p>
<p>Input message payload contains the timestamp for solar power output to be calculated at.</p>
<p>Uses the <i><a href = "https://github.com/mourner/suncalc" target="_new">suncalc</a></i> to calculate the current sun position.</p>
<p>Power forecast is adjusted for panel tilt, orientation, altitude, panel area, number of panels and panel efficiency.</p>
<p>Tilt is degrees from the horizontal. Orientation is the bearing in degrees from North. Altitude is in metres above sea level.</p>
<p> msg.payload contains:
<ul><li>timestamp: Time of calculation</li>
<li>powerforecast: Forecast of electrical power generated by the system under ideal conditions.</li>
</ul>
<p> See <a href="http://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-radiation-at-earths-surface">PV Education</a> for details of calculation.</p>
</script>
<!-- Finally, the node type is registered along with all of its properties -->
<!-- The example below shows a small subset of the properties that can be set-->
<script type="text/javascript">
RED.nodes.registerType('solar power forecast',{
category: 'advanced', // the palette category
color:"#ffcc66",
defaults: { // defines the editable properties of the node
name: {value:""}, // along with default values.
lat: {value:"0", required:true, validate:RED.validators.number()},
lon: {value:"0", required:true, validate:RED.validators.number()},
tilt: {value:"0", required:true, validate:RED.validators.number()},
orientation: {value:"0", required:true, validate:RED.validators.number()},
altitude: {value:"0", required:true, validate:RED.validators.number()},
area: {value:"1", required:true, validate:RED.validators.number()},
number: {value:"1", required:true, validate:RED.validators.number()},
efficiency: {value:"0.15", required:true, validate:RED.validators.number()},
},
inputs:1, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
icon: "sun.png", // set the icon (held in public/icons)
label: function() { // sets the default label contents
return this.name||"Solar Power Forecast";
},
labelStyle: function() { // sets the class to apply to the label
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)));
});
}
}
}
});
</script>