@mschaeffler/node-red-logic 4.0.1 → 4.1.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,188 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('blinker',{
3
+ category: 'logic',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ onTime:{value:"1",required:true},
9
+ onTimeUnit:{value:"secs"},
10
+ offTime:{value:"1",required:true},
11
+ offTimeUnit:{value:"secs"},
12
+ outputFirst:{value:true},
13
+ outputFirstType:{value:"bool"},
14
+ outputOn:{value:true,required:true},
15
+ outputOnType:{value:"bool"},
16
+ outputOff:{value:false,required:true},
17
+ outputOffType:{value:"bool"},
18
+ outputLast:{value:false},
19
+ outputLastType:{value:"bool"},
20
+ filter:{value:false},
21
+ showState:{value:false}
22
+ },
23
+ inputs:1,
24
+ outputs:1,
25
+ icon: "font-awesome/fa-refresh",
26
+ label: function() {
27
+ return this.name||"blinker";
28
+ },
29
+ labelStyle: function() {
30
+ return this.name?"node_label_italic":"";
31
+ },
32
+ paletteLabel: "blinker",
33
+ inputLabels: 'input',
34
+ outputLabels: 'blinken',
35
+ oneditprepare: function() {
36
+ $("#node-input-property").typedInput({
37
+ type:"msg",
38
+ types:["msg"],
39
+ typeField: "#node-input-property-type"
40
+ })
41
+ var optionNothing = {value:"nul",label:"none",hasValue:false};
42
+ var optionMessage = {value:"msg",label:"message",hasValue:false};
43
+ $("#node-input-outputFirst").typedInput({
44
+ type:"bool",
45
+ types:["str","num","bool","json",optionNothing,optionMessage],
46
+ typeField: "#node-input-outputFirstType"
47
+ })
48
+ $("#node-input-outputOn").typedInput({
49
+ type:"bool",
50
+ types:["str","num","bool","json"],
51
+ typeField: "#node-input-outputOnType"
52
+ })
53
+ $("#node-input-outputOff").typedInput({
54
+ type:"bool",
55
+ types:["str","num","bool","json"],
56
+ typeField: "#node-input-outputOffType"
57
+ })
58
+ $("#node-input-outputLast").typedInput({
59
+ type:"bool",
60
+ types:["str","num","bool","json",optionNothing,optionMessage],
61
+ typeField: "#node-input-outputLastType"
62
+ })
63
+ }
64
+ });
65
+ </script>
66
+
67
+ <script type="text/html" data-template-name="blinker">
68
+ <div class="form-row">
69
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
70
+ <input type="text" id="node-input-name" placeholder="Name">
71
+ </div>
72
+ <div class="form-row">
73
+ <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
74
+ <input type="text" id="node-input-property">
75
+ <input type="hidden" id="node-input-property-type">
76
+ </div>
77
+ <div class="form-row">
78
+ <label for="node-input-onTime"><i class="fa fa-hourglass-start"></i> on time</label>
79
+ <input type="number" id="node-input-onTime" style="width:70px;" placeholder="Time">
80
+ <select id="node-input-onTimeUnit" style="width:140px;">
81
+ <option value="msecs">MilliSeconds</option>
82
+ <option value="secs">Seconds</option>
83
+ <option value="mins">Minutes</option>
84
+ <option value="hours">Hours</option>
85
+ </select>
86
+ </div>
87
+ <div class="form-row">
88
+ <label for="node-input-offTime"><i class="fa fa-hourglass-end"></i> off time</label>
89
+ <input type="number" id="node-input-offTime" style="width:70px;" placeholder="Time">
90
+ <select id="node-input-offTimeUnit" style="width:140px;">
91
+ <option value="msecs">MilliSeconds</option>
92
+ <option value="secs">Seconds</option>
93
+ <option value="mins">Minutes</option>
94
+ <option value="hours">Hours</option>
95
+ </select>
96
+ </div>
97
+ <div class="form-row">
98
+ <label for="node-input-outputFirst"><i class="fa fa-sign-out"></i> 1st Output</label>
99
+ <input type="text" id="node-input-outputFirst">
100
+ <input type="hidden" id="node-input-outputFirstType">
101
+ </div>
102
+ <div class="form-row">
103
+ <label for="node-input-outputOn"><i class="fa fa-sign-out"></i> on Output</label>
104
+ <input type="text" id="node-input-outputOn">
105
+ <input type="hidden" id="node-input-outputOnType">
106
+ </div>
107
+ <div class="form-row">
108
+ <label for="node-input-outputOff"><i class="fa fa-sign-out"></i> off Output</label>
109
+ <input type="text" id="node-input-outputOff">
110
+ <input type="hidden" id="node-input-outputOffType">
111
+ </div>
112
+ <div class="form-row">
113
+ <label for="node-input-outputLast"><i class="fa fa-sign-out"></i> last Output</label>
114
+ <input type="text" id="node-input-outputLast">
115
+ <input type="hidden" id="node-input-outputLastType">
116
+ </div>
117
+ <div class="form-row">
118
+ <label for="node-input-filter"><i class="fa fa-filter"></i> Filter</label>
119
+ <input type="checkbox" id="node-input-filter" style="display:inline-block; width:20px; vertical-align:baseline;">
120
+ </div>
121
+ <div class="form-row">
122
+ <label for="node-input-howStatus"><i class="fa fa-star-o"></i> Status</label>
123
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
124
+ </div>
125
+ </script>
126
+
127
+ <script type="text/html" data-help-name="blinker">
128
+
129
+ <p>.</p>
130
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
131
+
132
+ <table>
133
+ <tr> <th>type</th> <th>input</th> <th>output</th> </tr>
134
+ <tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
135
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
136
+ <tr> <td>number</td> <td>0</td> <td>false</td> </tr>
137
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
138
+ <tr> <td>string</td> <td>false</td> <td>false</td> </tr>
139
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
140
+ <tr> <td></td> <td>0</td> <td>false</td> </tr>
141
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
142
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
143
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
144
+ </table>
145
+
146
+ <h3>Input</h3>
147
+
148
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
149
+
150
+ <dl class="message-properties">
151
+ <dt>payload <span class="property-type"></span></dt>
152
+ <dd> input value.</dd>
153
+ </dl>
154
+
155
+ <h3>Output</h3>
156
+
157
+ <dl class="message-properties">
158
+ <dt>payload <span class="property-type">boolean</span></dt>
159
+ <dd> blinking signal.</dd>
160
+ <dt>state <span class="property-type">boolean</span></dt>
161
+ <dd> received boolean value.</dd>
162
+ </dl>
163
+
164
+ <h3>Parameter</h3>
165
+
166
+ <dl class="message-properties">
167
+ <dt>Property <span class="property-type">string</span></dt>
168
+ <dd> defines the message property to be used as payload.</dd>
169
+ <dt>on time <span class="property-type">number</span></dt>
170
+ <dd> time to be in on state.</dd>
171
+ <dt>off time <span class="property-type">number</span></dt>
172
+ <dd> time to be in off state.</dd>
173
+ <dt>first Output <span class="property-type">multi</span></dt>
174
+ <dd> value to be sent as first (on) mesage.</dd>
175
+ <dt>on Output <span class="property-type">multi</span></dt>
176
+ <dd> value to be sent in on case inside the sequence.</dd>
177
+ <dt>off Output <span class="property-type">multi</span></dt>
178
+ <dd> value to be sent in off case inside the sequence.</dd>
179
+ <dt>Status <span class="property-type">boolean</span></dt>
180
+ <dt>last Output <span class="property-type">multi</span></dt>
181
+ <dd> value to be sent as last (off) message.</dd>
182
+ <dt>Filter <span class="property-type">boolean</span></dt>
183
+ <dd> block sending of unchanged <code>property</code>.</dd>
184
+ <dt>Status <span class="property-type">boolean</span></dt>
185
+ <dd> shows the actual value as a node status.</dd>
186
+ </dl>
187
+
188
+ </script>
@@ -0,0 +1,159 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('blinker',{
3
+ category: 'logic',
4
+ color: "#C0DEED",
5
+ defaults: {
6
+ name:{value:""},
7
+ property:{value:"payload",required:true},
8
+ onTime:{value:"1",required:true},
9
+ onTimeUnit:{value:"secs"},
10
+ offTime:{value:"1",required:true},
11
+ offTimeUnit:{value:"secs"},
12
+ outputOn:{value:true,required:true},
13
+ outputOnType:{value:"bool"},
14
+ outputPause:{value:false,required:true},
15
+ outputPauseType:{value:"bool"},
16
+ outputOff:{value:false,required:true},
17
+ outputOffType:{value:"bool"},
18
+ showState:{value:false}
19
+ },
20
+ inputs:1,
21
+ outputs:1,
22
+ icon: "font-awesome/fa-refresh",
23
+ label: function() {
24
+ return this.name||"blinker";
25
+ },
26
+ labelStyle: function() {
27
+ return this.name?"node_label_italic":"";
28
+ },
29
+ paletteLabel: "blinker",
30
+ inputLabels: 'input',
31
+ outputLabels: 'blinken',
32
+ oneditprepare: function() {
33
+ $("#node-input-property").typedInput({
34
+ type:"msg",
35
+ types:["msg"],
36
+ typeField: "#node-input-property-type"
37
+ })
38
+ $("#node-input-outputOn").typedInput({
39
+ type:"bool",
40
+ types:["str","num","bool","json"],
41
+ typeField: "#node-input-outputOnType"
42
+ })
43
+ $("#node-input-outputOff").typedInput({
44
+ type:"bool",
45
+ types:["str","num","bool","json"],
46
+ typeField: "#node-input-outputOffType"
47
+ })
48
+ }
49
+ });
50
+ </script>7
51
+
52
+ <script type="text/html" data-template-name="blinker">
53
+ <div class="form-row">
54
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
55
+ <input type="text" id="node-input-name" placeholder="Name">
56
+ </div>
57
+ <div class="form-row">
58
+ <label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
59
+ <input type="text" id="node-input-property">
60
+ <input type="hidden" id="node-input-property-type">
61
+ </div>
62
+ <div class="form-row">
63
+ <label for="node-input-onTime"><i class="fa fa-hourglass-start"></i> on time</label>
64
+ <input type="number" id="node-input-onTime" style="width:70px;" placeholder="Time">
65
+ <select id="node-input-onTimeUnit" style="width:140px;">
66
+ <option value="msecs">MilliSeconds</option>
67
+ <option value="secs">Seconds</option>
68
+ <option value="mins">Minutes</option>
69
+ <option value="hours">Hours</option>
70
+ </select>
71
+ </div>
72
+ <div class="form-row">
73
+ <label for="node-input-pauseTime"><i class="fa fa-hourglass-end"></i> pause time</label>
74
+ <input type="number" id="node-input-ffTime" style="width:70px;" placeholder="Time">
75
+ <select id="node-input-offTimeUnit" style="width:140px;">
76
+ <option value="msecs">MilliSeconds</option>
77
+ <option value="secs">Seconds</option>
78
+ <option value="mins">Minutes</option>
79
+ <option value="hours">Hours</option>
80
+ </select>
81
+ </div>
82
+ <div class="form-row">
83
+ <label for="node-input-outputOn"><i class="fa fa-sign-out"></i> on Output</label>
84
+ <input type="text" id="node-input-outputOn">
85
+ <input type="hidden" id="node-input-outputOnType">
86
+ </div>
87
+ <div class="form-row">
88
+ <label for="node-input-outputPause"><i class="fa fa-sign-out"></i> pause Output</label>
89
+ <input type="text" id="node-input-outputPause">
90
+ <input type="hidden" id="node-input-outputPauseType">
91
+ </div>
92
+ <div class="form-row">
93
+ <label for="node-input-outputOff"><i class="fa fa-sign-out"></i> off Output</label>
94
+ <input type="text" id="node-input-outputOff">
95
+ <input type="hidden" id="node-input-outputOffType">
96
+ </div>
97
+ <div class="form-row">
98
+ <label for="node-input-howStatus"><i class="fa fa-star-o"></i> Status</label>
99
+ <input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
100
+ </div>
101
+ </script>
102
+
103
+ <script type="text/html" data-help-name="blinker">
104
+
105
+ <p>Sends the payload converted to boolean delayed. The delay time can de controlled for on and off switching individually.</p>
106
+ <p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
107
+
108
+ <table>
109
+ <tr> <th>type</th> <th>input</th> <th>output</th> </tr>
110
+ <tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
111
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
112
+ <tr> <td>number</td> <td>0</td> <td>false</td> </tr>
113
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
114
+ <tr> <td>string</td> <td>false</td> <td>false</td> </tr>
115
+ <tr> <td></td> <td>true</td> <td>true</td> </tr>
116
+ <tr> <td></td> <td>0</td> <td>false</td> </tr>
117
+ <tr> <td></td> <td>1</td> <td>true</td> </tr>
118
+ <tr> <td></td> <td>off</td> <td>false</td> </tr>
119
+ <tr> <td></td> <td>on</td> <td>true</td> </tr>
120
+ </table>
121
+
122
+ <h3>Input</h3>
123
+
124
+ <p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
125
+
126
+ <dl class="message-properties">
127
+ <dt>payload <span class="property-type"></span></dt>
128
+ <dd> input value.</dd>
129
+ </dl>
130
+
131
+ <h3>Output</h3>
132
+
133
+ <dl class="message-properties">
134
+ <dt>payload <span class="property-type">boolean</span></dt>
135
+ <dd> bool value of payload.</dd>
136
+ </dl>
137
+
138
+ <h3>Parameter</h3>
139
+
140
+ <dl class="message-properties">
141
+ <dt>Property <span class="property-type">string</span></dt>
142
+ <dd> defines the message property to be used as payload.</dd>
143
+ <dt>Delay <span class="property-type">number</span></dt>
144
+ <dd> delay time in msec for switching from off to on.</dd>
145
+ <dt>Postrun <span class="property-type">number</span></dt>
146
+ <dd> delay time in msec for switching from on to off.</dd>
147
+ <dt>min on time <span class="property-type">number</span></dt>
148
+ <dd> minimal time in msec to be in on state.</dd>
149
+ <dt>max on time <span class="property-type">number</span></dt>
150
+ <dd> maximal time in msec to be in on state; 0 is infinite.</dd>
151
+ <dt>on Output <span class="property-type">multi</span></dt>
152
+ <dd> Value to be sent in on case.</dd>
153
+ <dt>off Output <span class="property-type">multi</span></dt>
154
+ <dd> Value to be sent in off case.</dd>
155
+ <dt>Status <span class="property-type">boolean</span></dt>
156
+ <dd> shows the actual value as a node status.</dd>
157
+ </dl>
158
+
159
+ </script>
@@ -0,0 +1,130 @@
1
+ module.exports = function(RED) {
2
+ var tools = require('./tools.js');
3
+
4
+ function BlinkerNode(config) {
5
+ RED.nodes.createNode(this,config);
6
+ //this.config = config;
7
+ var node = this;
8
+ this.property = config.property || "payload";
9
+ this.onTime = Number( config.onTime ?? 1 ) * tools.timeUnits( config.onTimeUnit );
10
+ this.offTime = Number( config.offTime ?? 1 ) * tools.timeUnits( config.offTimeUnit );
11
+ this.firstType = config.outputFirstType ?? "bool";
12
+ this.lastType = config.outputLastType ?? "bool";
13
+ this.outputFirst = RED.util.evaluateNodeProperty( config.outputFirst ?? "true", this.firstType );
14
+ this.outputOn = RED.util.evaluateNodeProperty( config.outputOn ?? "true", config.outputOnType ?? "bool" );
15
+ this.outputOff = RED.util.evaluateNodeProperty( config.outputOff ?? "false", config.outputOffType ?? "bool" );
16
+ this.outputLast = RED.util.evaluateNodeProperty( config.outputLast ?? "false", this.lastType );
17
+ this.filter = Boolean( config.filter );
18
+ this.showState = Boolean( config.showState );
19
+ this.timerOn = null;
20
+ this.timerOff = null;
21
+ this.last = null;
22
+ node.status( "" );
23
+
24
+ function setStatus(color,text)
25
+ {
26
+ if( node.showState )
27
+ {
28
+ node.status( { text:text, shape:"dot", fill:color } );
29
+ }
30
+ }
31
+
32
+ function sendFirst()
33
+ {
34
+ clearTimeout( node.timerOn );
35
+ clearTimeout( node.timerOff );
36
+ switch( node.firstType )
37
+ {
38
+ case "nul":
39
+ break;
40
+ case "msg":
41
+ node.send( node.msg );
42
+ break;
43
+ default:
44
+ let msg = RED.util.cloneMessage( node.msg );
45
+ msg.payload = node.outputFirst;
46
+ node.send( msg );
47
+ }
48
+ setStatus( "green", "first" );
49
+ node.timerOn = null;
50
+ node.timerOff = setTimeout( sendOff, node.onTime );
51
+ }
52
+
53
+ function sendOn()
54
+ {
55
+ node.msg.payload = node.outputOn;
56
+ node.send( node.msg );
57
+ setStatus( "green", "on" );
58
+ node.timerOn = null;
59
+ node.timerOff = setTimeout( sendOff, node.onTime );
60
+ }
61
+
62
+ function sendOff()
63
+ {
64
+ node.msg.payload = node.outputOff;
65
+ node.send( node.msg );
66
+ setStatus( "gray", "off" );
67
+ node.timerOn = setTimeout( sendOn, node.offTime );
68
+ node.timerOff = null;
69
+ }
70
+
71
+ function sendLast()
72
+ {
73
+ clearTimeout( node.timerOn );
74
+ clearTimeout( node.timerOff );
75
+ node.timerOn = null;
76
+ node.timerOff = null;
77
+ switch( node.lastType )
78
+ {
79
+ case "nul":
80
+ break;
81
+ case "msg":
82
+ node.send( node.msg );
83
+ break;
84
+ default:
85
+ let msg = RED.util.cloneMessage( node.msg );
86
+ msg.payload = node.outputLast;
87
+ node.send( msg );
88
+ }
89
+ setStatus( "gray", "last" );
90
+ }
91
+
92
+ node.on('input', function(msg,send,done) {
93
+ if( msg.invalid )
94
+ {
95
+ done();
96
+ return;
97
+ }
98
+ node.state = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
99
+ if( node.state !== null )
100
+ {
101
+ if( !node.filter || node.state !== node.last )
102
+ {
103
+ node.last = node.state;
104
+ node.msg = msg;
105
+ node.msg.state = node.state;
106
+ if( node.state )
107
+ {
108
+ sendFirst();
109
+ }
110
+ else
111
+ {
112
+ sendLast();
113
+ }
114
+ }
115
+ }
116
+ else
117
+ {
118
+ setStatus( "red", "error" );
119
+ }
120
+ done();
121
+ });
122
+
123
+ node.on('close', function() {
124
+ clearTimeout( node.timerOn );
125
+ clearTimeout( node.timerOff );
126
+ });
127
+ }
128
+
129
+ RED.nodes.registerType("blinker",BlinkerNode);
130
+ }
@@ -79,7 +79,7 @@
79
79
  </div>
80
80
  <div class="form-row">
81
81
  <label for="node-input-delay"><i class="fa fa-play"></i> Delay</label>
82
- <input type="text" id="node-input-delay" style="width:70px;" placeholder="Time">
82
+ <input type="number" id="node-input-delay" style="width:70px;" placeholder="Time">
83
83
  <select id="node-input-delayUnit" style="width:140px;">
84
84
  <option value="msecs">MilliSeconds</option>
85
85
  <option value="secs">Seconds</option>
@@ -89,7 +89,7 @@
89
89
  </div>
90
90
  <div class="form-row">
91
91
  <label for="node-input-postrun"><i class="fa fa-stop"></i> Postrun</label>
92
- <input type="text" id="node-input-postrun" style="width:70px;" placeholder="Time">
92
+ <input type="number" id="node-input-postrun" style="width:70px;" placeholder="Time">
93
93
  <select id="node-input-postrunUnit" style="width:140px;">
94
94
  <option value="msecs">MilliSeconds</option>
95
95
  <option value="secs">Seconds</option>
@@ -99,7 +99,7 @@
99
99
  </div>
100
100
  <div class="form-row">
101
101
  <label for="node-input-minOn"><i class="fa fa-hourglass-start"></i> min on time</label>
102
- <input type="text" id="node-input-minOn" style="width:70px;" placeholder="Time">
102
+ <input type="number" id="node-input-minOn" style="width:70px;" placeholder="Time">
103
103
  <select id="node-input-minOnUnit" style="width:140px;">
104
104
  <option value="msecs">MilliSeconds</option>
105
105
  <option value="secs">Seconds</option>
@@ -109,7 +109,7 @@
109
109
  </div>
110
110
  <div class="form-row">
111
111
  <label for="node-input-maxOn"><i class="fa fa-hourglass-end"></i> max on time</label>
112
- <input type="text" id="node-input-maxOn" style="width:70px;" placeholder="Time">
112
+ <input type="number" id="node-input-maxOn" style="width:70px;" placeholder="Time">
113
113
  <select id="node-input-maxOnUnit" style="width:140px;">
114
114
  <option value="msecs">MilliSeconds</option>
115
115
  <option value="secs">Seconds</option>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-logic",
3
- "version": "4.0.1",
3
+ "version": "4.1.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",
@@ -23,6 +23,7 @@
23
23
  "or": "logic_or.js",
24
24
  "and": "logic_and.js",
25
25
  "timerelay": "logic_timerelay.js",
26
+ "blinker": "logic_blinker.js",
26
27
  "tonumber": "math_number.js",
27
28
  "negate": "math_minus.js",
28
29
  "reduce": "math_reduce.js",
package/tools.js CHANGED
@@ -1,4 +1,4 @@
1
- // general functions
1
+ // general functions
2
2
 
3
3
  exports.property2boolean = function(input)
4
4
  {