@mschaeffler/node-red-logic 0.3.0 → 0.4.2
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/README.md +89 -0
- package/counter.js +3 -0
- package/icons/falling-edge.png +0 -0
- package/icons/hysteresis.png +0 -0
- package/icons/raising-edge.png +0 -0
- package/logic_and.js +30 -22
- package/logic_bool.html +1 -1
- package/logic_or.js +30 -22
- package/math_falling.html +81 -0
- package/math_falling.js +51 -0
- package/math_hysteresis.html +103 -0
- package/math_hysteresis.js +81 -0
- package/math_number.html +1 -1
- package/math_raising.html +81 -0
- package/math_raising.js +51 -0
- package/math_reduce.html +9 -2
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -186,6 +186,90 @@ The message property to be used as payload can be defined with the `Property` pr
|
|
|
186
186
|
|
|
187
187
|
#### Algorithms
|
|
188
188
|
|
|
189
|
+
|
|
190
|
+
## fallingEdge
|
|
191
|
+
|
|
192
|
+
Message is only forwarded, if the payload falls below a threshold value.
|
|
193
|
+
|
|
194
|
+
Each `topic` is treated seperatly.
|
|
195
|
+
|
|
196
|
+
### Input
|
|
197
|
+
|
|
198
|
+
The message property to be used as payload can be defined with the `Property` property.
|
|
199
|
+
|
|
200
|
+
|msg. | type | description |
|
|
201
|
+
|:-------|:-------|:----------------------------------|
|
|
202
|
+
|topic | string | name of the input channel. |
|
|
203
|
+
|payload | number | input value for `topic`. |
|
|
204
|
+
|
|
205
|
+
### Output
|
|
206
|
+
|
|
207
|
+
Trigger message, in case a falling edge is detected.
|
|
208
|
+
|
|
209
|
+
### Parameter
|
|
210
|
+
|
|
211
|
+
|config| type | description |
|
|
212
|
+
|:-----|:-------|:----------------------------------|
|
|
213
|
+
|Property| string | defines the message property to be used as payload.|
|
|
214
|
+
|Threshold|number|threshold value for the edge detection.|
|
|
215
|
+
|Status|boolean|shows the actual value as a node status.|
|
|
216
|
+
|
|
217
|
+
## raisingEdge
|
|
218
|
+
|
|
219
|
+
Message is only forwarded, if the payload raises above a threshold value.
|
|
220
|
+
|
|
221
|
+
Each `topic` is treated seperatly.
|
|
222
|
+
|
|
223
|
+
### Input
|
|
224
|
+
|
|
225
|
+
The message property to be used as payload can be defined with the `Property` property.
|
|
226
|
+
|
|
227
|
+
|msg. | type | description |
|
|
228
|
+
|:-------|:-------|:----------------------------------|
|
|
229
|
+
|topic | string | name of the input channel. |
|
|
230
|
+
|payload | number | input value for `topic`. |
|
|
231
|
+
|
|
232
|
+
### Output
|
|
233
|
+
|
|
234
|
+
Trigger message, in case a raising edge is detected.
|
|
235
|
+
|
|
236
|
+
### Parameter
|
|
237
|
+
|
|
238
|
+
|config| type | description |
|
|
239
|
+
|:-----|:-------|:----------------------------------|
|
|
240
|
+
|Property| string | defines the message property to be used as payload.|
|
|
241
|
+
|Threshold|number|threshold value for the edge detection.|
|
|
242
|
+
|Status|boolean|shows the actual value as a node status.|
|
|
243
|
+
|
|
244
|
+
## hysteresis
|
|
245
|
+
|
|
246
|
+
Message is only forwarded, if the payload raises above an upper limit or falls below a lower limit.
|
|
247
|
+
|
|
248
|
+
Each `topic` is treated seperatly.
|
|
249
|
+
|
|
250
|
+
### Input
|
|
251
|
+
|
|
252
|
+
The message property to be used as payload can be defined with the `Property` property.
|
|
253
|
+
|
|
254
|
+
|msg. | type | description |
|
|
255
|
+
|:-------|:-------|:----------------------------------|
|
|
256
|
+
|topic | string | name of the input channel. |
|
|
257
|
+
|payload | number | input value for `topic`. |
|
|
258
|
+
|
|
259
|
+
### Output
|
|
260
|
+
|
|
261
|
+
Trigger message, in case an edge is detected.
|
|
262
|
+
|
|
263
|
+
### Parameter
|
|
264
|
+
|
|
265
|
+
|config| type | description |
|
|
266
|
+
|:-----|:-------|:----------------------------------|
|
|
267
|
+
|Property| string | defines the message property to be used as payload.|
|
|
268
|
+
|up Threshold|number|threshold value for the raising edge detection.|
|
|
269
|
+
|d(ow)n Threshold|number|threshold value for the falling edge detection.|
|
|
270
|
+
|1st message|string|initial behaviour (None, Rising, Falling, Any).|
|
|
271
|
+
|Status|boolean|shows the actual value as a node status.|
|
|
272
|
+
|
|
189
273
|
## Example Flow
|
|
190
274
|
|
|
191
275
|
[example flow](https://github.com/m-schaeffler/node-red-my-nodes/raw/main/node-red-logic/examples/logic.json)
|
|
@@ -194,6 +278,11 @@ The message property to be used as payload can be defined with the `Property` pr
|
|
|
194
278
|
|
|
195
279
|
[Mathias Schäffler](https://github.com/m-schaeffler)
|
|
196
280
|
|
|
281
|
+
## Contributors
|
|
282
|
+
|
|
283
|
+
for `falling edge`, `raising edge` and `hysteresis`:
|
|
284
|
+
* [Eugene Schava](https://github.com/eschava/node-red-contrib-edge-trigger)
|
|
285
|
+
|
|
197
286
|
## License
|
|
198
287
|
|
|
199
288
|
LGPL-2.1
|
package/counter.js
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/logic_and.js
CHANGED
|
@@ -11,34 +11,42 @@ module.exports = function(RED) {
|
|
|
11
11
|
this.minData = Number( config.minData );
|
|
12
12
|
|
|
13
13
|
node.on('input', function(msg,send,done) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
if( msg.reset || msg.topic==="init" )
|
|
15
|
+
{
|
|
16
|
+
context.set( "data", {} );
|
|
17
|
+
node.status( "" );
|
|
18
|
+
}
|
|
19
|
+
else
|
|
17
20
|
{
|
|
18
|
-
|
|
19
|
-
data[msg.topic] = payload;
|
|
20
|
-
context.set( "data", data );
|
|
21
|
+
const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
msg.payload = true;
|
|
24
|
-
msg.count = 0;
|
|
25
|
-
for( const item in data )
|
|
23
|
+
if( payload !== null )
|
|
26
24
|
{
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
let data = context.get( "data" ) ?? {};
|
|
26
|
+
data[msg.topic] = payload;
|
|
27
|
+
context.set( "data", data );
|
|
28
|
+
|
|
29
|
+
msg.topic = node.topic;
|
|
30
|
+
msg.payload = true;
|
|
31
|
+
msg.count = 0;
|
|
32
|
+
for( const item in data )
|
|
29
33
|
{
|
|
30
|
-
|
|
34
|
+
msg.count++;
|
|
35
|
+
if( ! data[item] )
|
|
36
|
+
{
|
|
37
|
+
msg.payload = false;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
|
-
}
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if( msg.count >= node.minData )
|
|
42
|
+
{
|
|
43
|
+
node.status( msg.payload );
|
|
44
|
+
send( msg );
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
node.status( "waiting for data" );
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
package/logic_bool.html
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
<input type="hidden" id="node-input-property-type">
|
|
38
38
|
</div>
|
|
39
39
|
<div class="form-row">
|
|
40
|
-
<label for="node-input-showStatus"><i class="fa-star-o"></i> Status</label>
|
|
40
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
41
41
|
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
42
42
|
</div>
|
|
43
43
|
</script>
|
package/logic_or.js
CHANGED
|
@@ -11,34 +11,42 @@ module.exports = function(RED) {
|
|
|
11
11
|
this.minData = Number( config.minData );
|
|
12
12
|
|
|
13
13
|
node.on('input', function(msg,send,done) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
if( msg.reset || msg.topic==="init" )
|
|
15
|
+
{
|
|
16
|
+
context.set( "data", {} );
|
|
17
|
+
node.status( "" );
|
|
18
|
+
}
|
|
19
|
+
else
|
|
17
20
|
{
|
|
18
|
-
|
|
19
|
-
data[msg.topic] = payload;
|
|
20
|
-
context.set( "data", data );
|
|
21
|
+
const payload = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
msg.payload = false;
|
|
24
|
-
msg.count = 0;
|
|
25
|
-
for( const item in data )
|
|
23
|
+
if( payload !== null )
|
|
26
24
|
{
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
let data = context.get( "data" ) ?? {};
|
|
26
|
+
data[msg.topic] = payload;
|
|
27
|
+
context.set( "data", data );
|
|
28
|
+
|
|
29
|
+
msg.topic = node.topic;
|
|
30
|
+
msg.payload = false;
|
|
31
|
+
msg.count = 0;
|
|
32
|
+
for( const item in data )
|
|
29
33
|
{
|
|
30
|
-
msg.
|
|
34
|
+
msg.count++;
|
|
35
|
+
if( data[item] )
|
|
36
|
+
{
|
|
37
|
+
msg.payload = true;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
|
-
}
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if( msg.count >= node.minData )
|
|
42
|
+
{
|
|
43
|
+
node.status( msg.payload );
|
|
44
|
+
send( msg );
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
node.status( "waiting for data" );
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('fallingEdge',{
|
|
3
|
+
category: 'function',
|
|
4
|
+
color: "#C0DEED",
|
|
5
|
+
defaults: {
|
|
6
|
+
name:{value:""},
|
|
7
|
+
property:{value:"payload",required:true},
|
|
8
|
+
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
9
|
+
showState:{value:false}
|
|
10
|
+
},
|
|
11
|
+
inputs:1,
|
|
12
|
+
outputs:1,
|
|
13
|
+
icon: "falling-edge.png",
|
|
14
|
+
label: function() {
|
|
15
|
+
return this.name||"falling";
|
|
16
|
+
},
|
|
17
|
+
paletteLabel: "falling edge",
|
|
18
|
+
inputLabels: 'input',
|
|
19
|
+
outputLabels: 'edge trigger',
|
|
20
|
+
oneditprepare: function() {
|
|
21
|
+
$("#node-input-property").typedInput({
|
|
22
|
+
type:"msg",
|
|
23
|
+
types:["msg"],
|
|
24
|
+
typeField: "#node-input-property-type"
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script type="text/html" data-template-name="fallingEdge">
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
33
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
37
|
+
<input type="text" id="node-input-property">
|
|
38
|
+
<input type="hidden" id="node-input-property-type">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-input-threshold"><i class="fa fa-chevron-down"></i> Threshold</label>
|
|
42
|
+
<input type="text" id="node-input-threshold">
|
|
43
|
+
</div>
|
|
44
|
+
<div class="form-row">
|
|
45
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
46
|
+
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
47
|
+
</div>
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<script type="text/html" data-help-name="fallingEdge">
|
|
51
|
+
|
|
52
|
+
<p>Message is only forwarded, if the payload falls below a threshold value.</p>
|
|
53
|
+
<p>Each <code>topic</code> is treated seperatly.</p>
|
|
54
|
+
|
|
55
|
+
<h3>Input</h3>
|
|
56
|
+
|
|
57
|
+
<p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
|
|
58
|
+
|
|
59
|
+
<dl class="message-properties">
|
|
60
|
+
<dt>topic <span class="property-type">string</span></dt>
|
|
61
|
+
<dd> name of the input channel.</dd>
|
|
62
|
+
<dt>payload <span class="property-type"></span></dt>
|
|
63
|
+
<dd> input value for <code>topic</code>.</dd>
|
|
64
|
+
</dl>
|
|
65
|
+
|
|
66
|
+
<h3>Output</h3>
|
|
67
|
+
|
|
68
|
+
<p>Trigger message, in case a falling edge is detected.</p>
|
|
69
|
+
|
|
70
|
+
<h3>Parameter</h3>
|
|
71
|
+
|
|
72
|
+
<dl class="message-properties">
|
|
73
|
+
<dt>Property <span class="property-type">string</span></dt>
|
|
74
|
+
<dd> defines the message property to be used as payload.</dd>
|
|
75
|
+
<dt>Threshold <span class="property-type">number</span></dt>
|
|
76
|
+
<dd> threshold value for the edge detection.</dd>
|
|
77
|
+
<dt>Status <span class="property-type">boolean</span></dt>
|
|
78
|
+
<dd> shows the actual value as a node status.</dd>
|
|
79
|
+
</dl>
|
|
80
|
+
|
|
81
|
+
</script>
|
package/math_falling.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
|
|
3
|
+
function FallingEdgeNode(config) {
|
|
4
|
+
RED.nodes.createNode(this,config);
|
|
5
|
+
//this.config = config;
|
|
6
|
+
var node = this;
|
|
7
|
+
var context = this.context();
|
|
8
|
+
this.property = config.property ?? "payload";
|
|
9
|
+
this.threshold = config.threshold;
|
|
10
|
+
this.showState = config.showState;
|
|
11
|
+
|
|
12
|
+
node.on('input', function(msg,send,done) {
|
|
13
|
+
if( msg.reset || msg.topic==="init" )
|
|
14
|
+
{
|
|
15
|
+
context.set( "data", {} );
|
|
16
|
+
node.status( "" );
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
{
|
|
20
|
+
msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
21
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
22
|
+
|
|
23
|
+
if( ! isNaN( msg.payload ) )
|
|
24
|
+
{
|
|
25
|
+
let data = context.get( "data" ) ?? {};
|
|
26
|
+
const last = data[msg.topic] ?? Number.MIN_SAFE_INTEGER;
|
|
27
|
+
if( msg.payload < this.threshold && this.threshold <= last )
|
|
28
|
+
{
|
|
29
|
+
status.fill = "green";
|
|
30
|
+
send( msg );
|
|
31
|
+
}
|
|
32
|
+
data[msg.topic] = msg.payload;
|
|
33
|
+
context.set( "data", data );
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
status.fill = "red";
|
|
38
|
+
status.text = "not a Number";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if( node.showState )
|
|
42
|
+
{
|
|
43
|
+
node.status( status );
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
RED.nodes.registerType("fallingEdge",FallingEdgeNode);
|
|
51
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('hysteresisEdge',{
|
|
3
|
+
category: 'function',
|
|
4
|
+
color: "#C0DEED",
|
|
5
|
+
defaults: {
|
|
6
|
+
name:{value:""},
|
|
7
|
+
property:{value:"payload",required:true},
|
|
8
|
+
threshold_raise:{value:"",required:true,validate:RED.validators.number()},
|
|
9
|
+
threshold_fall:{value:"",required:true,validate:function(v){
|
|
10
|
+
const raise = $("#node-input-threshold_raise").length ? $("#node-input-threshold_raise").val() : this.threshold_raise;
|
|
11
|
+
return v!=='' && !isNaN(v) && Number(v)<raise;}
|
|
12
|
+
},
|
|
13
|
+
initial:{value:"none"},
|
|
14
|
+
showState:{value:false}
|
|
15
|
+
},
|
|
16
|
+
inputs:1,
|
|
17
|
+
outputs:1,
|
|
18
|
+
icon: "hysteresis.png",
|
|
19
|
+
label: function() {
|
|
20
|
+
return this.name||"hysteresis";
|
|
21
|
+
},
|
|
22
|
+
paletteLabel: "hysteresis",
|
|
23
|
+
inputLabels: 'input',
|
|
24
|
+
outputLabels: 'hysteresis trigger',
|
|
25
|
+
oneditprepare: function() {
|
|
26
|
+
$("#node-input-property").typedInput({
|
|
27
|
+
type:"msg",
|
|
28
|
+
types:["msg"],
|
|
29
|
+
typeField: "#node-input-property-type"
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<script type="text/html" data-template-name="hysteresisEdge">
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
38
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
42
|
+
<input type="text" id="node-input-property">
|
|
43
|
+
<input type="hidden" id="node-input-property-type">
|
|
44
|
+
</div>
|
|
45
|
+
<div class="form-row">
|
|
46
|
+
<label for="node-input-threshold_raise"><i class="fa fa-chevron-up"></i> up threshold</label>
|
|
47
|
+
<input type="text" id="node-input-threshold_raise">
|
|
48
|
+
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-threshold_fall"><i class="fa fa-chevron-down"></i> dn threshold</label>
|
|
51
|
+
<input type="text" id="node-input-threshold_fall">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-initial"><i class="fa fa-play"></i> 1st message</label>
|
|
55
|
+
<select id="node-input-initial">
|
|
56
|
+
<option value="none">None</option>
|
|
57
|
+
<option value="rising">Rising</option>
|
|
58
|
+
<option value="falling">Falling</option>
|
|
59
|
+
<option value="any">Any</option>
|
|
60
|
+
</select>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="form-row">
|
|
63
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
64
|
+
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
65
|
+
</div>
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-help-name="hysteresisEdge">
|
|
69
|
+
|
|
70
|
+
<p>Message is only forwarded, if the payload raises above an upper limit or falls below a lower limit.</p>
|
|
71
|
+
<p>Each <code>topic</code> is treated seperatly.</p>
|
|
72
|
+
|
|
73
|
+
<h3>Input</h3>
|
|
74
|
+
|
|
75
|
+
<p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
|
|
76
|
+
|
|
77
|
+
<dl class="message-properties">
|
|
78
|
+
<dt>topic <span class="property-type">string</span></dt>
|
|
79
|
+
<dd> name of the input channel.</dd>
|
|
80
|
+
<dt>payload <span class="property-type"></span></dt>
|
|
81
|
+
<dd> input value for <code>topic</code>.</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
|
|
84
|
+
<h3>Output</h3>
|
|
85
|
+
|
|
86
|
+
<p>Trigger message, in case an edge is detected.</p>
|
|
87
|
+
|
|
88
|
+
<h3>Parameter</h3>
|
|
89
|
+
|
|
90
|
+
<dl class="message-properties">
|
|
91
|
+
<dt>Property <span class="property-type">string</span></dt>
|
|
92
|
+
<dd> defines the message property to be used as payload.</dd>
|
|
93
|
+
<dt>up Threshold <span class="property-type">number</span></dt>
|
|
94
|
+
<dd> threshold value for the raising edge detection.</dd>
|
|
95
|
+
<dt>d(ow)n Threshold <span class="property-type">number</span></dt>
|
|
96
|
+
<dd> threshold value for the falling edge detection.</dd>
|
|
97
|
+
<dt>1st message <span class="property-type">string</span></dt>
|
|
98
|
+
<dd> initial behaviour (None, Rising, Falling, Any).</dd>
|
|
99
|
+
<dt>Status <span class="property-type">boolean</span></dt>
|
|
100
|
+
<dd> shows the actual value as a node status.</dd>
|
|
101
|
+
</dl>
|
|
102
|
+
|
|
103
|
+
</script>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
|
|
3
|
+
function HysteresisEdgeNode(config) {
|
|
4
|
+
RED.nodes.createNode(this,config);
|
|
5
|
+
//this.config = config;
|
|
6
|
+
var node = this;
|
|
7
|
+
var context = this.context();
|
|
8
|
+
this.property = config.property ?? "payload";
|
|
9
|
+
this.threshold_raise = config.threshold_raise;
|
|
10
|
+
this.threshold_fall = config.threshold_fall;
|
|
11
|
+
this.initial = config.initial;
|
|
12
|
+
this.showState = config.showState;
|
|
13
|
+
|
|
14
|
+
node.on('input', function(msg,send,done) {
|
|
15
|
+
|
|
16
|
+
if( msg.reset || msg.topic==="init" )
|
|
17
|
+
{
|
|
18
|
+
context.set( "data", {} );
|
|
19
|
+
node.status( "" );
|
|
20
|
+
}
|
|
21
|
+
else
|
|
22
|
+
{
|
|
23
|
+
msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
24
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
25
|
+
|
|
26
|
+
if( ! isNaN( msg.payload ) )
|
|
27
|
+
{
|
|
28
|
+
let data = context.get( "data" ) ?? {};
|
|
29
|
+
const last = data[msg.topic];
|
|
30
|
+
|
|
31
|
+
function sendMsg(edge)
|
|
32
|
+
{
|
|
33
|
+
status.fill = "green";
|
|
34
|
+
data[msg.topic].edge = edge;
|
|
35
|
+
msg.edge = edge;
|
|
36
|
+
send( msg );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if( last )
|
|
40
|
+
{
|
|
41
|
+
if( msg.payload > this.threshold_raise && this.threshold_raise >= last.value && last.edge != 'rising')
|
|
42
|
+
{
|
|
43
|
+
sendMsg( 'rising' );
|
|
44
|
+
}
|
|
45
|
+
else if( msg.payload < this.threshold_fall && this.threshold_fall <= last.value && last.edge != 'falling')
|
|
46
|
+
{
|
|
47
|
+
sendMsg( 'falling' );
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
{
|
|
52
|
+
data[msg.topic] = {};
|
|
53
|
+
if( ( this.initial == 'any' || this.initial == 'rising' ) && msg.payload > this.threshold_raise )
|
|
54
|
+
{
|
|
55
|
+
sendMsg( 'rising' );
|
|
56
|
+
}
|
|
57
|
+
else if( ( this.initial == 'any' || this.initial == 'falling' ) && msg.payload < this.threshold_fall )
|
|
58
|
+
{
|
|
59
|
+
sendMsg( 'falling' );
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
data[msg.topic].value = msg.payload;
|
|
63
|
+
context.set( "data", data );
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
status.fill = "red";
|
|
68
|
+
status.text = "not a Number";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if( node.showState )
|
|
72
|
+
{
|
|
73
|
+
node.status( status );
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
done();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
RED.nodes.registerType("hysteresisEdge",HysteresisEdgeNode);
|
|
81
|
+
}
|
package/math_number.html
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
<input type="hidden" id="node-input-property-type">
|
|
38
38
|
</div>
|
|
39
39
|
<div class="form-row">
|
|
40
|
-
<label for="node-input-showStatus"><i class="fa-star-o"></i> Status</label>
|
|
40
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
41
41
|
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
42
42
|
</div>
|
|
43
43
|
</script>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('raisingEdge',{
|
|
3
|
+
category: 'function',
|
|
4
|
+
color: "#C0DEED",
|
|
5
|
+
defaults: {
|
|
6
|
+
name:{value:""},
|
|
7
|
+
property:{value:"payload",required:true},
|
|
8
|
+
threshold:{value:"",required:true,validate:RED.validators.number()},
|
|
9
|
+
showState:{value:false}
|
|
10
|
+
},
|
|
11
|
+
inputs:1,
|
|
12
|
+
outputs:1,
|
|
13
|
+
icon: "raising-edge.png",
|
|
14
|
+
label: function() {
|
|
15
|
+
return this.name||"raising";
|
|
16
|
+
},
|
|
17
|
+
paletteLabel: "raising edge",
|
|
18
|
+
inputLabels: 'input',
|
|
19
|
+
outputLabels: 'edge trigger',
|
|
20
|
+
oneditprepare: function() {
|
|
21
|
+
$("#node-input-property").typedInput({
|
|
22
|
+
type:"msg",
|
|
23
|
+
types:["msg"],
|
|
24
|
+
typeField: "#node-input-property-type"
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script type="text/html" data-template-name="raisingEdge">
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
33
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-input"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
37
|
+
<input type="text" id="node-input-property">
|
|
38
|
+
<input type="hidden" id="node-input-property-type">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-input-threshold"><i class="fa fa-chevron-up"></i> Threshold</label>
|
|
42
|
+
<input type="text" id="node-input-threshold">
|
|
43
|
+
</div>
|
|
44
|
+
<div class="form-row">
|
|
45
|
+
<label for="node-input-showStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
46
|
+
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
47
|
+
</div>
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<script type="text/html" data-help-name="raisingEdge">
|
|
51
|
+
|
|
52
|
+
<p>Message is only forwarded, if the payload raises above a threshold value.</p>
|
|
53
|
+
<p>Each <code>topic</code> is treated seperatly.</p>
|
|
54
|
+
|
|
55
|
+
<h3>Input</h3>
|
|
56
|
+
|
|
57
|
+
<p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
|
|
58
|
+
|
|
59
|
+
<dl class="message-properties">
|
|
60
|
+
<dt>topic <span class="property-type">string</span></dt>
|
|
61
|
+
<dd> name of the input channel.</dd>
|
|
62
|
+
<dt>payload <span class="property-type"></span></dt>
|
|
63
|
+
<dd> input value for <code>topic</code>.</dd>
|
|
64
|
+
</dl>
|
|
65
|
+
|
|
66
|
+
<h3>Output</h3>
|
|
67
|
+
|
|
68
|
+
<p>Trigger message, in case a raising edge is detected.</p>
|
|
69
|
+
|
|
70
|
+
<h3>Parameter</h3>
|
|
71
|
+
|
|
72
|
+
<dl class="message-properties">
|
|
73
|
+
<dt>Property <span class="property-type">string</span></dt>
|
|
74
|
+
<dd> defines the message property to be used as payload.</dd>
|
|
75
|
+
<dt>Threshold <span class="property-type">number</span></dt>
|
|
76
|
+
<dd> threshold value for the edge detection.</dd>
|
|
77
|
+
<dt>Status <span class="property-type">boolean</span></dt>
|
|
78
|
+
<dd> shows the actual value as a node status.</dd>
|
|
79
|
+
</dl>
|
|
80
|
+
|
|
81
|
+
</script>
|
package/math_raising.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
|
|
3
|
+
function RaisingEdgeNode(config) {
|
|
4
|
+
RED.nodes.createNode(this,config);
|
|
5
|
+
//this.config = config;
|
|
6
|
+
var node = this;
|
|
7
|
+
var context = this.context();
|
|
8
|
+
this.property = config.property ?? "payload";
|
|
9
|
+
this.threshold = config.threshold;
|
|
10
|
+
this.showState = config.showState;
|
|
11
|
+
|
|
12
|
+
node.on('input', function(msg,send,done) {
|
|
13
|
+
if( msg.reset || msg.topic==="init" )
|
|
14
|
+
{
|
|
15
|
+
context.set( "data", {} );
|
|
16
|
+
node.status( "" );
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
{
|
|
20
|
+
msg.payload = Number( RED.util.getMessageProperty( msg, node.property ) );
|
|
21
|
+
let status = { fill:"gray", shape:"dot", text:msg.payload };
|
|
22
|
+
|
|
23
|
+
if( ! isNaN( msg.payload ) )
|
|
24
|
+
{
|
|
25
|
+
let data = context.get( "data" ) ?? {};
|
|
26
|
+
const last = data[msg.topic] ?? Number.MAX_SAFE_INTEGER;
|
|
27
|
+
if( msg.payload > this.threshold && this.threshold >= last )
|
|
28
|
+
{
|
|
29
|
+
status.fill = "green";
|
|
30
|
+
send( msg );
|
|
31
|
+
}
|
|
32
|
+
data[msg.topic] = msg.payload;
|
|
33
|
+
context.set( "data", data );
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
{
|
|
37
|
+
status.fill = "red";
|
|
38
|
+
status.text = "not a Number";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if( node.showState )
|
|
42
|
+
{
|
|
43
|
+
node.status( status );
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
RED.nodes.registerType("raisingEdge",RaisingEdgeNode);
|
|
51
|
+
}
|
package/math_reduce.html
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
types:["msg"],
|
|
43
43
|
typeField: "#node-input-property-type"
|
|
44
44
|
});
|
|
45
|
+
/*
|
|
45
46
|
$("#node-input-algo").typedInput({
|
|
46
47
|
types:[{
|
|
47
48
|
value:"algo",
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
{ value: "max", label: "Maximum" }
|
|
54
55
|
]
|
|
55
56
|
}]
|
|
56
|
-
})
|
|
57
|
+
})*/
|
|
57
58
|
}
|
|
58
59
|
});
|
|
59
60
|
</script>
|
|
@@ -86,7 +87,13 @@
|
|
|
86
87
|
</div>
|
|
87
88
|
<div class="form-row">
|
|
88
89
|
<label for="node-input-algo"><i class="fa fa-flask"></i> Algorithm</label>
|
|
89
|
-
<
|
|
90
|
+
<select type="text" id="node-input-algo">
|
|
91
|
+
<option value="add">Adition</option>
|
|
92
|
+
<option value="mean">Mean Value</option>
|
|
93
|
+
<option value="prod">Product</option>
|
|
94
|
+
<option value="min">Minimum</option>
|
|
95
|
+
<option value="max">Maximum</option>
|
|
96
|
+
</select>
|
|
90
97
|
</div>
|
|
91
98
|
</script>
|
|
92
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschaeffler/node-red-logic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "nodes for simple mathematical operations.",
|
|
5
5
|
"license": "LGPL-2.1",
|
|
6
6
|
"homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"tonumber":"math_number.js",
|
|
23
23
|
"or":"logic_or.js",
|
|
24
24
|
"and":"logic_and.js",
|
|
25
|
+
"fallingEdge":"math_falling.js",
|
|
26
|
+
"raisingEdge":"math_raising.js",
|
|
27
|
+
"hysteresisEdge":"math_hysteresis.js",
|
|
25
28
|
"reduce":"math_reduce.js"
|
|
26
29
|
}
|
|
27
30
|
},
|