UNPKG

node-red-smithtek-hysteresis

Version:

Adds hysteresis function to node-red

26 lines (23 loc) 674 B
module.exports = function (RED) { function ThresholdFormatter(config) { RED.nodes.createNode(this, config); this.ThresholdType = config.ThresholdType || "upper"; var node = this; node.on("input", function (msg) { let value = msg.payload; let outdata = {}; if (this.ThresholdType === "upper") { outdata = { high: value }; } else if (this.ThresholdType === "lower") { outdata = { low: value }; } msg.payload = outdata; node.send(msg); }); } RED.nodes.registerType("smithtek_node_red_threshold_formatter", ThresholdFormatter); };