@mschaeffler/node-red-logic 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/math_mean.html CHANGED
@@ -10,7 +10,9 @@
10
10
  },
11
11
  minData:{value:"1", required:true, validate:function(v){
12
12
  return v!=='' && !isNaN(v) && Number(v)>0;}
13
- }
13
+ },
14
+ filter:{value:"0", validate:RED.validators.number()},
15
+ zeroIsZero:{value:false}
14
16
  },
15
17
  inputs:1,
16
18
  outputs:1,
@@ -51,6 +53,14 @@
51
53
  <label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
52
54
  <input type="text" id="node-input-minData">
53
55
  </div>
56
+ <div class="form-row">
57
+ <label for="node-input-filter"><i class="fa fa-filter "></i> Filterzeit</label>
58
+ <input type="text" id="node-input-filter">
59
+ </div>
60
+ <div class="form-row">
61
+ <label for="node-input-zeroIsZero"><i class="fa fa-exclamation-circle"></i> Null ist Null</label>
62
+ <input type="checkbox" id="node-input-zeroIsZero" style="display:inline-block; width:20px; vertical-align:baseline;">
63
+ </div>
54
64
  </script>
55
65
 
56
66
  <script type="text/html" data-help-name="mean">
@@ -86,5 +96,9 @@
86
96
  <dd> time frame to collect the data for the analysis.</dd>
87
97
  <dt>min. Data <span class="property-type">number</span></dt>
88
98
  <dd> min. amount of data points to generate an output.</dd>
99
+ <dt>Filterzeit <span class="property-type">number</span></dt>
100
+ <dd> send output only after this time.</dd>
101
+ <dt>Null ist NUll <span class="property-type">boolean</span></dt>
102
+ <dd> If 0 is received, 0 is send immediately.</dd>
89
103
  </dl>
90
104
  </script>
package/math_mean.js CHANGED
@@ -8,6 +8,8 @@ module.exports = function(RED) {
8
8
  this.property = config.property || "payload";
9
9
  this.deltaTime= Number( config.deltaTime )*1000;
10
10
  this.minData = Number( config.minData );
11
+ this.filter = Number( config.filter ?? 0 )*1000;
12
+ this.zeroIsZero = config.zeroIsZero ?? false;
11
13
 
12
14
  node.on('input', function(msg,send,done) {
13
15
  if( msg.invalid )
@@ -27,6 +29,7 @@ module.exports = function(RED) {
27
29
  const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
28
30
  if( ! isNaN( payload ) )
29
31
  {
32
+ let last = context.get( "last" ) ?? {};
30
33
  let data = context.get( "data" ) ?? {};
31
34
  let item = data[msg.topic] ?? [];
32
35
  item.push( { time:now, value:payload } );
@@ -37,16 +40,34 @@ module.exports = function(RED) {
37
40
  data[msg.topic] = item;
38
41
  context.set( "data", data );
39
42
 
40
- if( item.length >= this.minData )
43
+ function sendValue(value)
44
+ {
45
+ msg.payload = value;
46
+ last[msg.topic] = now;
47
+ context.set( "last", last );
48
+ node.status({fill:"green",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
49
+ send( msg );
50
+ }
51
+
52
+ if( this.zeroIsZero && payload === 0 )
53
+ {
54
+ sendValue( 0 );
55
+ }
56
+ else if( item.length >= this.minData )
41
57
  {
42
58
  let sum = 0;
43
59
  for( const value of item )
44
60
  {
45
61
  sum += value.value;
46
62
  }
47
- msg.payload = sum/item.length;
48
- node.status({fill:"green",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
49
- send( msg );
63
+ if( (last[msg.topic]??0)+this.filter < now )
64
+ {
65
+ sendValue( sum/item.length );
66
+ }
67
+ else
68
+ {
69
+ node.status({fill:"gray",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
70
+ }
50
71
  }
51
72
  else
52
73
  {
@@ -18,7 +18,6 @@ module.exports = function(RED) {
18
18
  if( msg.reset || msg.topic==="init" )
19
19
  {
20
20
  context.set( "data", {} );
21
- context.set( "last", {} );
22
21
  node.status( "" );
23
22
  }
24
23
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "nodes for simple operations.",
5
5
  "license": "LGPL-2.1",
6
6
  "homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",