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
22 lines (18 loc) • 647 B
JavaScript
const { getTariff, ping } = require("./elvia-api");
module.exports = function (RED) {
function PsElviaTariffNode(config) {
RED.nodes.createNode(this, config);
this.elviaConfig = RED.nodes.getNode(config.elviaConfig);
const key = this.elviaConfig.credentials.elviaSubscriptionKey;
this.tariffKey = config.tariffKey;
this.range = config.range;
const node = this;
ping(node, key);
node.on("input", function () {
getTariff(node, key, node.tariffKey, node.range).then((json) => {
node.send([{ payload: json }]);
});
});
}
RED.nodes.registerType("ps-elvia-tariff", PsElviaTariffNode);
};