diff --git a/function/rbe/README.md b/function/rbe/README.md index c9a5da06..c43946ff 100644 --- a/function/rbe/README.md +++ b/function/rbe/README.md @@ -32,4 +32,14 @@ same value. Saves bandwidth, etc... In deadband mode the incoming payload should contain a parseable *number* and is output only if greater than + or - the *band gap* away from the previous output. -Will accept numbers, or parseable strings like "18.4 C" or "$500" +The deadband value can be specified as a fixed number, or a percentage. E.g. 10 +or 5% . If % mode is used then the output will only get sent if the input payload +value is equal or more than the specified % away from the previously sent value. + +For example - if last sent value was 100, and deadband is set to 10% - a value +of 110 will pass - then the next value has to be 121 in order to pass (= 110 + 10% = 121). + +This is mainly useful if you want to operate across multiple topics at the same +time that may have widely differing input ranges. + +Will only accept numbers, or parseable strings like "18.4 C" or "$500" diff --git a/function/rbe/package.json b/function/rbe/package.json index a0dde101..82993da4 100644 --- a/function/rbe/package.json +++ b/function/rbe/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-rbe", - "version" : "0.0.5", + "version" : "0.0.6", "description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.", "dependencies" : { }, diff --git a/function/rbe/rbe.html b/function/rbe/rbe.html index 9788b4b7..f27cbffd 100644 --- a/function/rbe/rbe.html +++ b/function/rbe/rbe.html @@ -24,7 +24,7 @@
- +
@@ -38,6 +38,7 @@ different to the previous one. Works on numbers and strings.

In deadband mode the incoming payload should contain a parseable number and is output only if greater than + or - the band gap away from the previous output.

+

Deadband also supports % - only sends if the input differs by more than x% of the original value.

Note: This works on a per msg.topic basis. This means that a single rbe node can handle multiple topics at the same time.

@@ -49,7 +50,7 @@ handle multiple topics at the same time.

defaults: { name: {value:""}, func: {value:"rbe"}, - gap: {value:"",validate:RED.validators.regex(/^(\d*|)$/)} + gap: {value:"",validate:RED.validators.regex(/^(\d*|)(%|)$/)} }, inputs:1, outputs:1, diff --git a/function/rbe/rbe.js b/function/rbe/rbe.js index 057e4a89..06ded8a4 100644 --- a/function/rbe/rbe.js +++ b/function/rbe/rbe.js @@ -21,6 +21,13 @@ module.exports = function(RED) { RED.nodes.createNode(this,n); this.func = n.func || "rbe"; this.gap = n.gap || 0; + this.pc = false; + if (this.gap.substr(-1) === "%") { + this.pc = true; + this.gap = parseFloat(this.gap); + } + console.log(this.gap, this.pc); + this.g = this.gap; var node = this; node.previous = {}; @@ -36,6 +43,7 @@ module.exports = function(RED) { else { var n = parseFloat(msg.payload); if (!isNaN(n)) { + if (node.pc) { node.gap = (node.previous[t] * node.g / 100) || 0; } if (!node.previous.hasOwnProperty(t)) { node.previous[t] = n - node.gap; } if (Math.abs(n - node.previous[t]) >= node.gap) { node.previous[t] = n;