@mschaeffler/node-red-logic 1.2.1 → 1.4.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_falling.html +4 -3
- package/math_falling.js +61 -25
- package/math_hysteresis.html +4 -3
- package/math_hysteresis.js +76 -40
- package/math_mean.html +8 -1
- package/math_mean.js +17 -7
- package/math_raising.html +4 -3
- package/math_raising.js +61 -25
- package/package.json +3 -3
package/math_falling.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
7
|
property:{value:"payload",required:true},
|
|
8
|
+
propertyType:{value:"msg"},
|
|
8
9
|
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
9
10
|
showState:{value:false}
|
|
10
11
|
},
|
|
@@ -23,8 +24,8 @@
|
|
|
23
24
|
oneditprepare: function() {
|
|
24
25
|
$("#node-input-property").typedInput({
|
|
25
26
|
type:"msg",
|
|
26
|
-
types:["msg"],
|
|
27
|
-
typeField: "#node-input-
|
|
27
|
+
types:["msg","jsonata"],
|
|
28
|
+
typeField: "#node-input-propertyType"
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
});
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
<div class="form-row">
|
|
39
40
|
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
40
41
|
<input type="text" id="node-input-property">
|
|
41
|
-
<input type="hidden" id="node-input-
|
|
42
|
+
<input type="hidden" id="node-input-propertyType">
|
|
42
43
|
</div>
|
|
43
44
|
<div class="form-row">
|
|
44
45
|
<label for="node-input-threshold"><i class="fa fa-chevron-down"></i> Threshold</label>
|
package/math_falling.js
CHANGED
|
@@ -3,11 +3,22 @@ module.exports = function(RED) {
|
|
|
3
3
|
function FallingEdgeNode(config) {
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
//this.config = config;
|
|
6
|
-
var node
|
|
6
|
+
var node = this;
|
|
7
7
|
var context = this.context();
|
|
8
|
-
this.property
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
8
|
+
this.property = config.property ?? "payload";
|
|
9
|
+
this.propertyType = config.propertyType ?? "msg";
|
|
10
|
+
this.threshold = config.threshold;
|
|
11
|
+
this.showState = config.showState;
|
|
12
|
+
if( this.propertyType === "jsonata" )
|
|
13
|
+
{
|
|
14
|
+
try {
|
|
15
|
+
this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
node.error(RED._("debug.invalid-exp", {error: this.property}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
node.on('input', function(msg,send,done) {
|
|
13
24
|
if( msg.invalid )
|
|
@@ -19,37 +30,62 @@ module.exports = function(RED) {
|
|
|
19
30
|
{
|
|
20
31
|
context.set( "data", {} );
|
|
21
32
|
node.status( "" );
|
|
33
|
+
done();
|
|
22
34
|
}
|
|
23
35
|
else
|
|
24
36
|
{
|
|
25
|
-
|
|
26
|
-
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
27
|
-
|
|
28
|
-
if( ! isNaN( msg.payload ) )
|
|
37
|
+
function getPayload(callback)
|
|
29
38
|
{
|
|
30
|
-
|
|
31
|
-
const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
|
|
32
|
-
if( msg.payload < this.threshold && this.threshold <= last )
|
|
39
|
+
if( node.propertyPrepared )
|
|
33
40
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
|
|
42
|
+
{
|
|
43
|
+
if( err )
|
|
44
|
+
{
|
|
45
|
+
done( RED._("debug.invalid-exp", {error: editExpression}) );
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
{
|
|
49
|
+
callback( value );
|
|
50
|
+
}
|
|
51
|
+
} );
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
callback( RED.util.getMessageProperty( msg, node.property ) );
|
|
37
56
|
}
|
|
38
|
-
data[msg.topic] = msg.payload;
|
|
39
|
-
context.set( "data", data );
|
|
40
57
|
}
|
|
41
|
-
|
|
58
|
+
getPayload( function(value)
|
|
42
59
|
{
|
|
43
|
-
|
|
44
|
-
status
|
|
45
|
-
}
|
|
60
|
+
msg.payload = Number( value );
|
|
61
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
if( ! isNaN( msg.payload ) )
|
|
64
|
+
{
|
|
65
|
+
let data = context.get( "data" ) ?? {};
|
|
66
|
+
const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
|
|
67
|
+
if( msg.payload < this.threshold && this.threshold <= last )
|
|
68
|
+
{
|
|
69
|
+
status.fill = "green";
|
|
70
|
+
msg.edge = "falling";
|
|
71
|
+
send( msg );
|
|
72
|
+
}
|
|
73
|
+
data[msg.topic] = msg.payload;
|
|
74
|
+
context.set( "data", data );
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
{
|
|
78
|
+
status.fill = "red";
|
|
79
|
+
status.text = "not a Number";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if( node.showState )
|
|
83
|
+
{
|
|
84
|
+
node.status( status );
|
|
85
|
+
}
|
|
86
|
+
done();
|
|
87
|
+
} );
|
|
51
88
|
}
|
|
52
|
-
done();
|
|
53
89
|
});
|
|
54
90
|
}
|
|
55
91
|
|
package/math_hysteresis.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
7
|
property:{value:"payload",required:true},
|
|
8
|
+
propertyType:{value:"msg"},
|
|
8
9
|
threshold_raise:{value:"",required:true,validate:RED.validators.number()},
|
|
9
10
|
threshold_fall:{value:"",required:true,validate:function(v){
|
|
10
11
|
const raise = $("#node-input-threshold_raise").length ? $("#node-input-threshold_raise").val() : this.threshold_raise;
|
|
@@ -28,8 +29,8 @@
|
|
|
28
29
|
oneditprepare: function() {
|
|
29
30
|
$("#node-input-property").typedInput({
|
|
30
31
|
type:"msg",
|
|
31
|
-
types:["msg"],
|
|
32
|
-
typeField: "#node-input-
|
|
32
|
+
types:["msg","jsonata"],
|
|
33
|
+
typeField: "#node-input-propertyType"
|
|
33
34
|
})
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
<div class="form-row">
|
|
44
45
|
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
45
46
|
<input type="text" id="node-input-property">
|
|
46
|
-
<input type="hidden" id="node-input-
|
|
47
|
+
<input type="hidden" id="node-input-propertyType">
|
|
47
48
|
</div>
|
|
48
49
|
<div class="form-row">
|
|
49
50
|
<label for="node-input-threshold_raise"><i class="fa fa-chevron-up"></i> up threshold</label>
|
package/math_hysteresis.js
CHANGED
|
@@ -3,13 +3,24 @@ module.exports = function(RED) {
|
|
|
3
3
|
function HysteresisEdgeNode(config) {
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
//this.config = config;
|
|
6
|
-
var node
|
|
6
|
+
var node = this;
|
|
7
7
|
var context = this.context();
|
|
8
8
|
this.property = config.property ?? "payload";
|
|
9
|
+
this.propertyType = config.propertyType ?? "msg";
|
|
9
10
|
this.threshold_raise = config.threshold_raise;
|
|
10
11
|
this.threshold_fall = config.threshold_fall;
|
|
11
12
|
this.initial = config.initial;
|
|
12
13
|
this.showState = config.showState;
|
|
14
|
+
if( this.propertyType === "jsonata" )
|
|
15
|
+
{
|
|
16
|
+
try {
|
|
17
|
+
this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
node.error(RED._("debug.invalid-exp", {error: this.property}));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
|
|
14
25
|
node.on('input', function(msg,send,done) {
|
|
15
26
|
if( msg.invalid )
|
|
@@ -21,63 +32,88 @@ module.exports = function(RED) {
|
|
|
21
32
|
{
|
|
22
33
|
context.set( "data", {} );
|
|
23
34
|
node.status( "" );
|
|
35
|
+
done();
|
|
24
36
|
}
|
|
25
37
|
else
|
|
26
38
|
{
|
|
27
|
-
|
|
28
|
-
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
29
|
-
|
|
30
|
-
if( ! isNaN( msg.payload ) )
|
|
39
|
+
function getPayload(callback)
|
|
31
40
|
{
|
|
32
|
-
|
|
33
|
-
const last = data[msg.topic];
|
|
34
|
-
|
|
35
|
-
function sendMsg(edge)
|
|
41
|
+
if( node.propertyPrepared )
|
|
36
42
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
|
|
44
|
+
{
|
|
45
|
+
if( err )
|
|
46
|
+
{
|
|
47
|
+
done( RED._("debug.invalid-exp", {error: editExpression}) );
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
{
|
|
51
|
+
callback( value );
|
|
52
|
+
}
|
|
53
|
+
} );
|
|
41
54
|
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
callback( RED.util.getMessageProperty( msg, node.property ) );
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
getPayload( function(value)
|
|
61
|
+
{
|
|
62
|
+
msg.payload = Number( value );
|
|
63
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
42
64
|
|
|
43
|
-
if(
|
|
65
|
+
if( ! isNaN( msg.payload ) )
|
|
44
66
|
{
|
|
45
|
-
|
|
67
|
+
let data = context.get( "data" ) ?? {};
|
|
68
|
+
const last = data[msg.topic];
|
|
69
|
+
|
|
70
|
+
function sendMsg(edge)
|
|
71
|
+
{
|
|
72
|
+
status.fill = "green";
|
|
73
|
+
data[msg.topic].edge = edge;
|
|
74
|
+
msg.edge = edge;
|
|
75
|
+
send( msg );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if( last )
|
|
46
79
|
{
|
|
47
|
-
|
|
80
|
+
if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
|
|
81
|
+
{
|
|
82
|
+
sendMsg( 'rising' );
|
|
83
|
+
}
|
|
84
|
+
else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
|
|
85
|
+
{
|
|
86
|
+
sendMsg( 'falling' );
|
|
87
|
+
}
|
|
48
88
|
}
|
|
49
|
-
else
|
|
89
|
+
else
|
|
50
90
|
{
|
|
51
|
-
|
|
91
|
+
data[msg.topic] = {};
|
|
92
|
+
if( ['any','rising'].includes(this.initial) && msg.payload > this.threshold_raise )
|
|
93
|
+
{
|
|
94
|
+
sendMsg( 'rising' );
|
|
95
|
+
}
|
|
96
|
+
else if( ['any','falling'].includes(this.initial) && msg.payload < this.threshold_fall )
|
|
97
|
+
{
|
|
98
|
+
sendMsg( 'falling' );
|
|
99
|
+
}
|
|
52
100
|
}
|
|
101
|
+
data[msg.topic].value = msg.payload;
|
|
102
|
+
context.set( "data", data );
|
|
53
103
|
}
|
|
54
104
|
else
|
|
55
105
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
sendMsg( 'rising' );
|
|
60
|
-
}
|
|
61
|
-
else if( ['any','falling'].includes(this.initial) && msg.payload < this.threshold_fall )
|
|
62
|
-
{
|
|
63
|
-
sendMsg( 'falling' );
|
|
64
|
-
}
|
|
106
|
+
status.fill = "red";
|
|
107
|
+
status.text = "not a Number";
|
|
65
108
|
}
|
|
66
|
-
data[msg.topic].value = msg.payload;
|
|
67
|
-
context.set( "data", data );
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
{
|
|
71
|
-
status.fill = "red";
|
|
72
|
-
status.text = "not a Number";
|
|
73
|
-
}
|
|
74
109
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
110
|
+
if( node.showState )
|
|
111
|
+
{
|
|
112
|
+
node.status( status );
|
|
113
|
+
}
|
|
114
|
+
done();
|
|
115
|
+
} );
|
|
79
116
|
}
|
|
80
|
-
done();
|
|
81
117
|
});
|
|
82
118
|
}
|
|
83
119
|
|
package/math_mean.html
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
minData:{value:"1", required:true, validate:function(v){
|
|
12
12
|
return v!=='' && !isNaN(v) && Number(v)>0;}
|
|
13
13
|
},
|
|
14
|
-
filter:{value:"",
|
|
14
|
+
filter:{value:"0", validate:RED.validators.number()},
|
|
15
|
+
zeroIsZero:{value:false}
|
|
15
16
|
},
|
|
16
17
|
inputs:1,
|
|
17
18
|
outputs:1,
|
|
@@ -56,6 +57,10 @@
|
|
|
56
57
|
<label for="node-input-filter"><i class="fa fa-filter "></i> Filterzeit</label>
|
|
57
58
|
<input type="text" id="node-input-filter">
|
|
58
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>
|
|
59
64
|
</script>
|
|
60
65
|
|
|
61
66
|
<script type="text/html" data-help-name="mean">
|
|
@@ -93,5 +98,7 @@
|
|
|
93
98
|
<dd> min. amount of data points to generate an output.</dd>
|
|
94
99
|
<dt>Filterzeit <span class="property-type">number</span></dt>
|
|
95
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>
|
|
96
103
|
</dl>
|
|
97
104
|
</script>
|
package/math_mean.js
CHANGED
|
@@ -9,6 +9,7 @@ module.exports = function(RED) {
|
|
|
9
9
|
this.deltaTime= Number( config.deltaTime )*1000;
|
|
10
10
|
this.minData = Number( config.minData );
|
|
11
11
|
this.filter = Number( config.filter ?? 0 )*1000;
|
|
12
|
+
this.zeroIsZero = config.zeroIsZero ?? false;
|
|
12
13
|
|
|
13
14
|
node.on('input', function(msg,send,done) {
|
|
14
15
|
if( msg.invalid )
|
|
@@ -28,6 +29,7 @@ module.exports = function(RED) {
|
|
|
28
29
|
const payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
29
30
|
if( ! isNaN( payload ) )
|
|
30
31
|
{
|
|
32
|
+
let last = context.get( "last" ) ?? {};
|
|
31
33
|
let data = context.get( "data" ) ?? {};
|
|
32
34
|
let item = data[msg.topic] ?? [];
|
|
33
35
|
item.push( { time:now, value:payload } );
|
|
@@ -38,21 +40,29 @@ module.exports = function(RED) {
|
|
|
38
40
|
data[msg.topic] = item;
|
|
39
41
|
context.set( "data", data );
|
|
40
42
|
|
|
41
|
-
|
|
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 )
|
|
42
57
|
{
|
|
43
58
|
let sum = 0;
|
|
44
59
|
for( const value of item )
|
|
45
60
|
{
|
|
46
61
|
sum += value.value;
|
|
47
62
|
}
|
|
48
|
-
msg.payload = sum/item.length;
|
|
49
|
-
let last = context.get( "last" ) ?? {};
|
|
50
63
|
if( (last[msg.topic]??0)+this.filter < now )
|
|
51
64
|
{
|
|
52
|
-
|
|
53
|
-
context.set( "last", last );
|
|
54
|
-
node.status({fill:"green",shape:"dot",text:`${item.length} / ${msg.payload.toPrecision(4)}`});
|
|
55
|
-
send( msg );
|
|
65
|
+
sendValue( sum/item.length );
|
|
56
66
|
}
|
|
57
67
|
else
|
|
58
68
|
{
|
package/math_raising.html
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name:{value:""},
|
|
7
7
|
property:{value:"payload",required:true},
|
|
8
|
+
propertyType:{value:"msg"},
|
|
8
9
|
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
9
10
|
showState:{value:false}
|
|
10
11
|
},
|
|
@@ -23,8 +24,8 @@
|
|
|
23
24
|
oneditprepare: function() {
|
|
24
25
|
$("#node-input-property").typedInput({
|
|
25
26
|
type:"msg",
|
|
26
|
-
types:["msg"],
|
|
27
|
-
typeField: "#node-input-
|
|
27
|
+
types:["msg","jsonata"],
|
|
28
|
+
typeField: "#node-input-propertyType"
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
});
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
<div class="form-row">
|
|
39
40
|
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
40
41
|
<input type="text" id="node-input-property">
|
|
41
|
-
<input type="hidden" id="node-input-
|
|
42
|
+
<input type="hidden" id="node-input-propertyType">
|
|
42
43
|
</div>
|
|
43
44
|
<div class="form-row">
|
|
44
45
|
<label for="node-input-threshold"><i class="fa fa-chevron-up"></i> Threshold</label>
|
package/math_raising.js
CHANGED
|
@@ -3,11 +3,22 @@ module.exports = function(RED) {
|
|
|
3
3
|
function RaisingEdgeNode(config) {
|
|
4
4
|
RED.nodes.createNode(this,config);
|
|
5
5
|
//this.config = config;
|
|
6
|
-
var node
|
|
6
|
+
var node = this;
|
|
7
7
|
var context = this.context();
|
|
8
|
-
this.property
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
8
|
+
this.property = config.property ?? "payload";
|
|
9
|
+
this.propertyType = config.propertyType ?? "msg";
|
|
10
|
+
this.threshold = config.threshold;
|
|
11
|
+
this.showState = config.showState;
|
|
12
|
+
if( this.propertyType === "jsonata" )
|
|
13
|
+
{
|
|
14
|
+
try {
|
|
15
|
+
this.propertyPrepared = RED.util.prepareJSONataExpression( this.property, this );
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
node.error(RED._("debug.invalid-exp", {error: this.property}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
node.on('input', function(msg,send,done) {
|
|
13
24
|
if( msg.invalid )
|
|
@@ -19,37 +30,62 @@ module.exports = function(RED) {
|
|
|
19
30
|
{
|
|
20
31
|
context.set( "data", {} );
|
|
21
32
|
node.status( "" );
|
|
33
|
+
done();
|
|
22
34
|
}
|
|
23
35
|
else
|
|
24
36
|
{
|
|
25
|
-
|
|
26
|
-
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
27
|
-
|
|
28
|
-
if( ! isNaN( msg.payload ) )
|
|
37
|
+
function getPayload(callback)
|
|
29
38
|
{
|
|
30
|
-
|
|
31
|
-
const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
|
|
32
|
-
if( msg.payload > this.threshold && this.threshold >= last )
|
|
39
|
+
if( node.propertyPrepared )
|
|
33
40
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
RED.util.evaluateJSONataExpression( node.propertyPrepared, msg, function(err, value)
|
|
42
|
+
{
|
|
43
|
+
if( err )
|
|
44
|
+
{
|
|
45
|
+
done( RED._("debug.invalid-exp", {error: editExpression}) );
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
{
|
|
49
|
+
callback( value );
|
|
50
|
+
}
|
|
51
|
+
} );
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
callback( RED.util.getMessageProperty( msg, node.property ) );
|
|
37
56
|
}
|
|
38
|
-
data[msg.topic] = msg.payload;
|
|
39
|
-
context.set( "data", data );
|
|
40
57
|
}
|
|
41
|
-
|
|
58
|
+
getPayload( function(value)
|
|
42
59
|
{
|
|
43
|
-
|
|
44
|
-
status
|
|
45
|
-
}
|
|
60
|
+
msg.payload = Number( value );
|
|
61
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
if( ! isNaN( msg.payload ) )
|
|
64
|
+
{
|
|
65
|
+
let data = context.get( "data" ) ?? {};
|
|
66
|
+
const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
|
|
67
|
+
if( msg.payload > this.threshold && this.threshold >= last )
|
|
68
|
+
{
|
|
69
|
+
status.fill = "green";
|
|
70
|
+
msg.edge = "raising";
|
|
71
|
+
send( msg );
|
|
72
|
+
}
|
|
73
|
+
data[msg.topic] = msg.payload;
|
|
74
|
+
context.set( "data", data );
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
{
|
|
78
|
+
status.fill = "red";
|
|
79
|
+
status.text = "not a Number";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if( node.showState )
|
|
83
|
+
{
|
|
84
|
+
node.status( status );
|
|
85
|
+
}
|
|
86
|
+
done();
|
|
87
|
+
} );
|
|
51
88
|
}
|
|
52
|
-
done();
|
|
53
89
|
});
|
|
54
90
|
}
|
|
55
91
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschaeffler/node-red-logic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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",
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"url": "git+https://github.com/m-schaeffler/node-red-my-nodes.git"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
12
|
+
"node": ">=18"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"node-red"
|
|
16
16
|
],
|
|
17
17
|
"node-red": {
|
|
18
|
-
"version": ">=3.
|
|
18
|
+
"version": ">=3.1.0",
|
|
19
19
|
"nodes": {
|
|
20
20
|
"counter":"counter.js",
|
|
21
21
|
"tobool":"logic_bool.js",
|