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
231 lines (226 loc) • 7.25 kB
HTML
<script type="text/javascript">
const hours = [
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
];
RED.nodes.registerType("ps-strategy-lowest-price", {
category: "Power Saver",
color: "#a6bbcf",
defaults: {
name: { value: "Lowest Price" },
fromTime: {
value: "00",
required: true,
},
toTime: {
value: "00",
required: true,
},
hoursOn: {
value: "12",
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-fromTime").typedInput({
types: [
{
value: "fromtime",
options: hours.map((h) => ({ value: h, label: h + ":00" })),
},
],
});
$("#node-input-toTime").typedInput({
types: [
{
value: "totime",
options: hours.map((h) => ({ value: h, label: h + ":00" })),
},
],
});
$("#node-input-hoursOn").typedInput({
types: [
{
value: "hourson",
options: (() => {
const res = hours.map((h) => ({ value: "" + parseInt(h), label: "" + parseInt(h) }));
res.push({ value: "24", label: "24" });
return res;
})(),
},
],
});
$("#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-fromTime"><i class="fa fa-clock-o"></i> From time</label>
<input type="text" id="node-input-fromTime" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-toTime"><i class="fa fa-clock-o"></i> To time</label>
<input type="text" id="node-input-toTime" style="width: 80px">
</div>
<div class="form-row">
<label for="node-input-hoursOn"><i class="fa fa-arrows-h"></i> Hours on</label>
<input type="text" id="node-input-hoursOn" 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>