mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add % mode to rbe node deadband mode
This commit is contained in:
parent
6aa5500d34
commit
c09c58d729
@ -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"
|
||||
|
@ -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" : {
|
||||
},
|
||||
|
@ -24,7 +24,7 @@
|
||||
</div>
|
||||
<div class="form-row" id="node-bandgap">
|
||||
<label for="node-input-gap"><i class="fa fa-random"></i> Band gap</label>
|
||||
<input type="text" id="node-input-gap" placeholder="e.g. 10" style="width:71%;">
|
||||
<input type="text" id="node-input-gap" placeholder="e.g. 10 or 5%" style="width:71%;">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"/> Name</label>
|
||||
@ -38,6 +38,7 @@
|
||||
different to the previous one. Works on numbers and strings.</p>
|
||||
<p>In <b>deadband</b> mode the incoming payload should contain a parseable <i>number</i> and is
|
||||
output only if greater than + or - the <i>band gap</i> away from the previous output.</p>
|
||||
<p>Deadband also supports % - only sends if the input differs by more than x% of the original value.</p>
|
||||
<p><b>Note:</b> This works on a per <b>msg.topic</b> basis. This means that a single rbe node can
|
||||
handle multiple topics at the same time.</p>
|
||||
</script>
|
||||
@ -49,7 +50,7 @@ handle multiple topics at the same time.</p>
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
func: {value:"rbe"},
|
||||
gap: {value:"",validate:RED.validators.regex(/^(\d*|)$/)}
|
||||
gap: {value:"",validate:RED.validators.regex(/^(\d*|)(%|)$/)}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user