node-red-contrib-power-saver
Version:
A module for Node-RED that you can use to turn on and off a switch based on power prices
230 lines (225 loc) • 7.83 kB
HTML
<script type="text/javascript">
const hours = Array.from({ length: 24 }, (_, i) => i.toString().padStart(2, "0"));
const minutes = Array.from({ length: 60 }, (_, i) => i.toString().padStart(2, "0"));
RED.nodes.registerType("ps-strategy-lowest-price", {
category: "Power Saver",
color: "#a6bbcf",
defaults: {
name: { value: "Lowest Price" },
fromHour: {
value: "00",
required: true,
},
fromMinute: {
value: "00",
required: true,
},
toHour: {
value: "00",
required: true,
},
toMinute: {
value: "00",
required: true,
},
minutesOn: {
value: "720",
required: true,
},
maxPrice: {
value: null,
required: false,
validate: function (v) {
return v == null || v == "" || (!isNaN(parseFloat(v)) && isFinite(v));
},
},
doNotSplit: {
value: "false",
required: true,
align: "left",
},
sendCurrentValueWhenRescheduling: {
value: "true",
required: true,
align: "left",
},
outputValueForOn: {
value: true,
required: true,
validate: RED.validators.typedInput("outputValueForOntype", false),
},
outputValueForOff: {
value: false,
required: true,
validate: RED.validators.typedInput("outputValueForOfftype", false),
},
outputValueForOntype: {
value: "bool",
required: true,
},
outputValueForOfftype: {
value: "bool",
required: true,
},
outputIfNoSchedule: { value: "true", required: true, align: "left" },
outputOutsidePeriod: { value: "false", required: true, align: "left" },
contextStorage: { value: "default", required: false, align: "left" },
},
inputs: 1,
outputs: 3,
icon: "font-awesome/fa-bar-chart",
color: "#FFCC66",
label: function () {
return this.name || "Lowest Price";
},
outputLabels: ["on", "off", "schedule"],
oneditprepare: function () {
$("#node-input-outputIfNoSchedule").typedInput({
types: [
{
value: "onoff",
options: [
{ value: "true", label: "On" },
{ value: "false", label: "Off" },
],
},
],
});
$("#node-input-outputOutsidePeriod").typedInput({
types: [
{
value: "onoff",
options: [
{ value: "true", label: "On" },
{ value: "false", label: "Off" },
],
},
],
});
$("#node-input-fromHour").typedInput({
types: [
{
value: "fromhour",
options: hours.map((h) => ({ value: h, label: h })),
},
],
});
$("#node-input-toHour").typedInput({
types: [
{
value: "tohour",
options: hours.map((h) => ({ value: h, label: h })),
},
],
});
$("#node-input-fromMinute").typedInput({
types: [
{
value: "fromminute",
options: minutes.map((h) => ({ value: h, label: h })),
},
],
});
$("#node-input-toMinute").typedInput({
types: [
{
value: "tominute",
options: minutes.map((h) => ({ value: h, label: h })),
},
],
});
$("#node-input-minutesOn").typedInput({
type: "num",
});
$("#node-input-contextStorage").typedInput({
types: [
{
value: "storages",
options: RED.settings.context.stores.map((s) => ({ value: s, label: s })),
},
],
});
$("#node-input-outputValueForOn").typedInput({
default: "bool",
typeField: $("#node-input-outputValueForOntype"),
types: ["bool", "num", "str"],
});
$("#node-input-outputValueForOff").typedInput({
default: "bool",
typeField: $("#node-input-outputValueForOfftype"),
types: ["bool", "num", "str"],
});
},
});
</script>
<script type="text/html" data-template-name="ps-strategy-lowest-price">
<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" style="width: 240px">
</div>
<div class="form-row">
<label for="node-input-fromHour"><i class="fa fa-clock-o"></i> From hour</label>
<input type="text" id="node-input-fromHour" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-fromMinute"><i class="fa fa-clock-o"></i> From minute</label>
<input type="text" id="node-input-fromMinute" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-toHour"><i class="fa fa-clock-o"></i> To hour</label>
<input type="text" id="node-input-toHour" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-toMinute"><i class="fa fa-clock-o"></i> To minute</label>
<input type="text" id="node-input-toMinute" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-minutesOn"><i class="fa fa-arrows-h"></i> Minutes on</label>
<input type="text" id="node-input-minutesOn" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-maxPrice"><i class="fa fa-minus"></i> Max price</label>
<input type="text" id="node-input-maxPrice" placeholder="Max price" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-doNotSplit">Consecutive on-period</label>
<input type="checkbox" id="node-input-doNotSplit" style="display:inline-block; width:22px; vertical-align:top;">
</label>
</div>
<div class="form-row">
<label for="node-input-outputValueForOn">Output value for on</label>
<input type="text" id="node-input-outputValueForOn" style="text-align: left; width: 120px">
<input type="hidden" id="node-input-outputValueForOntype">
</div>
<div class="form-row">
<label for="node-input-outputValueForOff">Output value for off</label>
<input type="text" id="node-input-outputValueForOff" style="text-align: left; width: 120px">
<input type="hidden" id="node-input-outputValueForOfftype">
</div>
<div class="form-row">
<label for="node-input-sendCurrentValueWhenRescheduling" style="width:240px">
<input type="checkbox"
id="node-input-sendCurrentValueWhenRescheduling"
style="display:inline-block; width:22px; vertical-align:top;"
autocomplete="off"><span>Send when rescheduling</span>
</label>
</div>
<div class="form-row">
<label for="node-input-outputIfNoSchedule">If no schedule, send</label>
<input type="text" id="node-input-outputIfNoSchedule" style="width: 80px">
</label>
</div>
<div class="form-row">
<label for="node-input-outputIfNoSchedule">Outside period, send</label>
<input type="text" id="node-input-outputOutsidePeriod" style="width: 80px">
</label>
</div>
<div class="form-row">
<label for="node-input-contextStorage"><i class="fa fa-archive"></i> Context storage</label>
<input type="text" id="node-input-contextStorage" style="width: 160px">
</div>
</script>
<script type="text/markdown" data-help-name="ps-strategy-lowest-price">
A node to turn on a switch the hours when the price is lowest.
Please read more in the [node documentation](https://powersaver.no/nodes/ps-strategy-lowest-price)
</script>