@mschaeffler/node-red-logic 3.7.0 → 3.9.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.
@@ -0,0 +1,148 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('timerelay',{
3
+ category: 'logic',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ delay:{value:"0",required:true},
9
+ minOn:{value:"0",required:true},
10
+ maxOn:{value:"0",required:true},
11
+ postrun:{value:"0",required:true},
12
+ outputOn:{value:true,required:true},
13
+ outputOnType:{value:"bool"},
14
+ outputOff:{value:false,required:true},
15
+ outputOffType:{value:"bool"},
16
+ showState:{value:false}
17
+ },
18
+ inputs:1,
19
+ outputs:1,
20
+ icon: "font-awesome/fa-clock-o",
21
+ label: function() {
22
+ return this.name||"timerelay";
23
+ },
24
+ labelStyle: function() {
25
+ return this.name?"node_label_italic":"";
26
+ },
27
+ paletteLabel: "timerelay",
28
+ inputLabels: 'input',
29
+ outputLabels: 'boolean',
30
+ oneditprepare: function() {
31
+ $("#node-input-property").typedInput({
32
+ type:"msg",
33
+ types:["msg"],
34
+ typeField: "#node-input-property-type"
35
+ })
36
+ $("#node-input-outputOn").typedInput({
37
+ type:"bool",
38
+ types:["str","num","bool","json"],
39
+ typeField: "#node-input-outputOnType"
40
+ })
41
+ $("#node-input-outputOff").typedInput({
42
+ type:"bool",
43
+ types:["str","num","bool","json"],
44
+ typeField: "#node-input-outputOffType"
45
+ })
46
+ }
47
+ });
48
+ </script>
49
+
50
+ <script type="text/html" data-template-name="timerelay">
51
+ <div class="form-row">
52
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
53
+ <input type="text" id="node-input-name" placeholder="Name">
54
+ </div>
55
+ <div class="form-row">
56
+ <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
57
+ <input type="text" id="node-input-property">
58
+ <input type="hidden" id="node-input-property-type">
59
+ </div>
60
+ <div class="form-row">
61
+ <label for="node-input-delay"><i class="fa fa-play"></i> Delay</label>
62
+ <input type="text" id="node-input-delay">
63
+ </div>
64
+ <div class="form-row">
65
+ <label for="node-input-postrun"><i class="fa fa-stop"></i> Postrun</label>
66
+ <input type="text" id="node-input-postrun">
67
+ </div>
68
+ <div class="form-row">
69
+ <label for="node-input-minOn"><i class="fa fa-hourglass-start"></i> min on time</label>
70
+ <input type="text" id="node-input-minOn">
71
+ </div>
72
+ <div class="form-row">
73
+ <label for="node-input-maxOn"><i class="fa fa-hourglass-end"></i> max on time</label>
74
+ <input type="text" id="node-input-maxOn">
75
+ </div>
76
+ <div class="form-row">
77
+ <label for="node-input-outputOn"><i class="fa fa-sign-out"></i> on Output</label>
78
+ <input type="text" id="node-input-outputOn">
79
+ <input type="hidden" id="node-input-outputOnType">
80
+ </div>
81
+ <div class="form-row">
82
+ <label for="node-input-outputOff"><i class="fa fa-sign-out"></i> off Output</label>
83
+ <input type="text" id="node-input-outputOff">
84
+ <input type="hidden" id="node-input-outputOffType">
85
+ </div>
86
+ <div class="form-row">
87
+ <label for="node-input-howStatus"><i class="fa fa-star-o"></i> Status</label>
88
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
89
+ </div>
90
+ </script>
91
+
92
+ <script type="text/html" data-help-name="timerelay">
93
+
94
+ <p>Sends the payload converted to boolean delayed. The delay time can de controlled for on and off switching individually.</p>
95
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
96
+
97
+ <table>
98
+ <tr> <th>type</th> <th>input</th> <th>output</th> </tr>
99
+ <tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
100
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
101
+ <tr> <td>number</td> <td>0</td> <td>false</td> </tr>
102
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
103
+ <tr> <td>string</td> <td>false</td> <td>false</td> </tr>
104
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
105
+ <tr> <td></td> <td>0</td> <td>false</td> </tr>
106
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
107
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
108
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
109
+ </table>
110
+
111
+ <h3>Input</h3>
112
+
113
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
114
+
115
+ <dl class="message-properties">
116
+ <dt>payload <span class="property-type"></span></dt>
117
+ <dd> input value.</dd>
118
+ </dl>
119
+
120
+ <h3>Output</h3>
121
+
122
+ <dl class="message-properties">
123
+ <dt>payload <span class="property-type">boolean</span></dt>
124
+ <dd> bool value of payload.</dd>
125
+ </dl>
126
+
127
+ <h3>Parameter</h3>
128
+
129
+ <dl class="message-properties">
130
+ <dt>Property <span class="property-type">string</span></dt>
131
+ <dd> defines the message property to be used as payload.</dd>
132
+ <dt>Delay <span class="property-type">number</span></dt>
133
+ <dd> delay time in msec for switching from on to off.</dd>
134
+ <dt>Postrun <span class="property-type">number</span></dt>
135
+ <dd> delay time in msec for switching from off to on.</dd>
136
+ <dt>min on time <span class="property-type">number</span></dt>
137
+ <dd> minimal time in msec to be in on state.</dd>
138
+ <dt>max on time <span class="property-type">number</span></dt>
139
+ <dd> maximal time in msec to be in on state; 0 is infinite.</dd>
140
+ <dt>on Output <span class="property-type">multi</span></dt>
141
+ <dd> Value to be sent in on case.</dd>
142
+ <dt>off Output <span class="property-type">multi</span></dt>
143
+ <dd> Value to be sent in off case.</dd>
144
+ <dt>Status <span class="property-type">boolean</span></dt>
145
+ <dd> shows the actual value as a node status.</dd>
146
+ </dl>
147
+
148
+ </script>
@@ -0,0 +1,174 @@
1
+ module.exports = function(RED) {
2
+ var tools = require('./tools.js');
3
+
4
+ function TimeRelayNode(config) {
5
+ RED.nodes.createNode(this,config);
6
+ //this.config = config;
7
+ var node = this;
8
+ this.property = config.property || "payload";
9
+ this.delay = Number( config.delay ?? 0 );
10
+ this.postrun = Number( config.postrun ?? 0 );
11
+ this.minOn = Number( config.minOn ?? 0 );
12
+ this.maxOn = Number( config.maxOn ?? 0 );
13
+ this.outputOn = tools.convertTypedInput( config.outputOn ?? "true", config.outputOnType ?? "bool" );
14
+ this.outputOff = tools.convertTypedInput( config.outputOff ?? "false",config.outputOffType ?? "bool" );
15
+ this.showState = Boolean( config.showState );
16
+ this.state = null;
17
+ this.last = null;
18
+ this.msg = null;
19
+ this.timerDelay = null;
20
+ this.timerPostRun = null;
21
+ this.timerMinOn = null;
22
+ this.timerMaxOn = null;
23
+ node.status( "" );
24
+
25
+ function setStatus(color,text)
26
+ {
27
+ //console.log( text );
28
+ if( node.showState )
29
+ {
30
+ node.status( { text:text, shape:"dot", fill:color } );
31
+ }
32
+ }
33
+
34
+ function doswitch()
35
+ {
36
+ node.msg.payload = node.state ? node.outputOn : node.outputOff;
37
+ node.send( node.msg );
38
+ if( node.state )
39
+ {
40
+ if( node.minOn )
41
+ {
42
+ node.timerMinOn = setTimeout( function() { node.emit("minOn"); }, node.minOn );
43
+ }
44
+ if( node.maxOn )
45
+ {
46
+ node.timerMaxOn = setTimeout( function() { node.emit("maxOn"); }, node.maxOn );
47
+ }
48
+ }
49
+ else
50
+ {
51
+ clearTimeout( node.timerMinOn );
52
+ clearTimeout( node.timerMaxOn );
53
+ node.timerMinOn = null;
54
+ node.timerMaxOn = null;
55
+ node.msg = null;
56
+ }
57
+ }
58
+
59
+ node.on('input', function(msg,send,done) {
60
+ if( msg.invalid )
61
+ {
62
+ done();
63
+ return;
64
+ }
65
+ node.state = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
66
+ if( node.state !== null )
67
+ {
68
+ if( node.state !== node.last )
69
+ {
70
+ node.last = node.state;
71
+ node.msg = msg;
72
+ if( node.state )
73
+ {
74
+ if( node.timerPostrun )
75
+ {
76
+ clearTimeout( node.timerPostrun );
77
+ node.timerPostrun = null;
78
+ doswitch();
79
+ setStatus( "green", "on (change of mind)" );
80
+ }
81
+ else
82
+ {
83
+ if( node.delay > 0 )
84
+ {
85
+ node.timerDelay = setTimeout( function() { node.emit("sendOnMsg"); }, node.delay );
86
+ setStatus( "yellow", "startdelay" );
87
+ }
88
+ else
89
+ {
90
+ doswitch();
91
+ setStatus( "green", "on" );
92
+ }
93
+ }
94
+ }
95
+ else
96
+ {
97
+ if( node.timerDelay )
98
+ {
99
+ clearTimeout( node.timerDelay );
100
+ node.timerDelay = null;
101
+ doswitch();
102
+ setStatus( "gray", "off (change of mind)" );
103
+ }
104
+ else
105
+ {
106
+ if( node.postrun > 0 )
107
+ {
108
+ node.timerPostrun = setTimeout( function() { node.emit("sendOffMsg"); }, node.postrun );
109
+ setStatus( "yellow", "postrun" );
110
+ }
111
+ else if( node.timerMinOn )
112
+ {
113
+ setStatus( "yellow", "minimal on" );
114
+ }
115
+ else
116
+ {
117
+ doswitch();
118
+ setStatus( "gray", "off" );
119
+ }
120
+ }
121
+ }
122
+ }
123
+ else
124
+ {
125
+ setStatus( node.state ? "green" : "gray", "filter" );
126
+ }
127
+ }
128
+ else
129
+ {
130
+ //console.log("error")
131
+ setStatus( "red", "error" );
132
+ }
133
+ done();
134
+ });
135
+
136
+ node.on('sendOnMsg', function() {
137
+ node.timerDelay = null;
138
+ doswitch();
139
+ setStatus( "green", "on" );
140
+ });
141
+
142
+ node.on('sendOffMsg', function() {
143
+ node.timerPostrun = null;
144
+ doswitch();
145
+ setStatus( "gray", "off" );
146
+ });
147
+
148
+ node.on('minOn', function() {
149
+ node.timerMinOn = null;
150
+ if( ! node.state )
151
+ {
152
+ doswitch();
153
+ setStatus( "gray", "off (min time)" );
154
+ }
155
+ });
156
+
157
+ node.on('maxOn', function() {
158
+ node.timerMaxOn = null;
159
+ node.last = false;
160
+ node.state = false;
161
+ doswitch();
162
+ setStatus( "gray", "off (max time)" );
163
+ });
164
+
165
+ node.on('close', function() {
166
+ clearTimeout( node.timerDelay );
167
+ clearTimeout( node.timerPostrun );
168
+ clearTimeout( node.timerMinOn );
169
+ clearTimeout( node.timerMaxOn );
170
+ });
171
+ }
172
+
173
+ RED.nodes.registerType("timerelay",TimeRelayNode);
174
+ }
package/math_mean.html CHANGED
@@ -16,6 +16,7 @@
16
16
  filterVal:{value:0, validate:RED.validators.number()},
17
17
  filterMul:{value:10, validate:RED.validators.number()},
18
18
  zeroIsZero:{value:false},
19
+ decimals:{validate:RED.validators.number()},
19
20
  showState:{value:false}
20
21
  },
21
22
  inputs:1,
@@ -54,21 +55,25 @@
54
55
  <input type="text" id="node-input-deltaTime">
55
56
  </div>
56
57
  <div class="form-row">
57
- <label for="node-input-minData"><i class="fa fa-check-square-o "></i> min. Data</label>
58
+ <label for="node-input-minData"><i class="fa fa-check-square-o"></i> min. Data</label>
58
59
  <input type="text" id="node-input-minData">
59
60
  </div>
60
61
  <div class="form-row">
61
- <label for="node-input-filter"><i class="fa fa-filter "></i> Filterzeit</label>
62
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filterzeit</label>
62
63
  <input type="number" id="node-input-filter">
63
64
  </div>
64
65
  <div class="form-row">
65
- <label for="node-input-filterVal"><i class="fa fa-filter "></i> Filter Wert</label>
66
+ <label for="node-input-filterVal"><i class="fa fa-filter"></i> Filter Wert</label>
66
67
  <input type="text" id="node-input-filterVal">
67
68
  </div>
68
69
  <div class="form-row">
69
- <label for="node-input-filterMul"><i class="fa fa-filter "></i> Filter Wiederholungsfaktor</label>
70
+ <label for="node-input-filterMul"><i class="fa fa-filter"></i> Filter Wiederholungsfaktor</label>
70
71
  <input type="text" id="node-input-filterMul">
71
72
  </div>
73
+ <div class="form-row">
74
+ <label for="node-input-decimals"><i class="fa fa-sort-numeric-asc"></i> Nachkommastellen</label>
75
+ <input type="text" id="node-input-decimals">
76
+ </div>
72
77
  <div class="form-row">
73
78
  <label for="node-input-zeroIsZero"><i class="fa fa-exclamation-circle"></i> Null ist Null</label>
74
79
  <input type="checkbox" id="node-input-zeroIsZero" style="display:inline-block; width:20px; vertical-align:baseline;">
@@ -118,6 +123,8 @@
118
123
  <dd> send output only if change is bigger.</dd>
119
124
  <dt>Filter Wiederholungsfaktor <span class="property-type">number</span></dt>
120
125
  <dd> do send output if change is lower then <code>Filter Wert</code> after n times <code>Filterzeit</code>.</dd>
126
+ <dt>Nachkommastellen <span class="property-type">number</span></dt>
127
+ <dd> Anzahl an Nachkommastellen..</dd>
121
128
  <dt>Null ist NUll <span class="property-type">boolean</span></dt>
122
129
  <dd> If 0 is received, 0 is send immediately.</dd>
123
130
  <dt>Status <span class="property-type">boolean</span></dt>
package/math_mean.js CHANGED
@@ -14,6 +14,7 @@ module.exports = function(RED) {
14
14
  this.filterValue = Number( config.filterVal ?? 0 );
15
15
  this.filterLongTime = this.filterTime * Number( config.filterMul ?? 10 );
16
16
  this.zeroIsZero = Boolean( config.zeroIsZero );
17
+ this.round = config.decimals ? Math.pow( 10, Number( config.decimals ) ) : null;
17
18
  this.showState = Boolean( config.showState );
18
19
  if( this.propertyType === "jsonata" )
19
20
  {
@@ -109,11 +110,15 @@ module.exports = function(RED) {
109
110
  sum += value.value;
110
111
  }
111
112
  const help = last[msg.topic];
112
- const value = sum/item.length;
113
+ let value = sum/item.length;
113
114
  if( help === undefined ||
114
115
  ( help.time + node.filterTime < now && tools.distance( help.value, value ) >= node.filterValue ) ||
115
116
  ( node.filterLongTime > 0 && help.time + node.filterLongTime < now ) )
116
117
  {
118
+ if( node.round )
119
+ {
120
+ value = Math.round( value * node.round ) / node.round;
121
+ }
117
122
  sendValue( value, item.length );
118
123
  }
119
124
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "3.7.0",
3
+ "version": "3.9.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",
@@ -22,6 +22,7 @@
22
22
  "not": "logic_not.js",
23
23
  "or": "logic_or.js",
24
24
  "and": "logic_and.js",
25
+ "timerelay": "logic_timerelay.js",
25
26
  "tonumber": "math_number.js",
26
27
  "negate": "math_minus.js",
27
28
  "reduce": "math_reduce.js",