node-red-contrib-boolean-logic-ultimate 1.0.53 → 1.0.56
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/CHANGELOG.md +11 -0
- package/README.md +120 -56
- package/boolean-logic-ultimate/BlinkerUltimate.html +9 -1
- package/boolean-logic-ultimate/BlinkerUltimate.js +6 -28
- package/boolean-logic-ultimate/BooleanLogicUltimate.html +10 -1
- package/boolean-logic-ultimate/BooleanLogicUltimate.js +13 -31
- package/boolean-logic-ultimate/FilterUltimate.html +10 -1
- package/boolean-logic-ultimate/FilterUltimate.js +7 -28
- package/boolean-logic-ultimate/ImpulseUltimate.html +7 -0
- package/boolean-logic-ultimate/ImpulseUltimate.js +5 -2
- package/boolean-logic-ultimate/InterruptFlowUltimate.html +13 -5
- package/boolean-logic-ultimate/InterruptFlowUltimate.js +4 -28
- package/boolean-logic-ultimate/InvertUltimate.html +10 -1
- package/boolean-logic-ultimate/InvertUltimate.js +7 -33
- package/boolean-logic-ultimate/RailwaySwitchUltimate.html +15 -6
- package/boolean-logic-ultimate/RailwaySwitchUltimate.js +7 -29
- package/boolean-logic-ultimate/SumUltimate.html +6 -2
- package/boolean-logic-ultimate/toggleUltimate.html +10 -1
- package/boolean-logic-ultimate/toggleUltimate.js +5 -29
- package/boolean-logic-ultimate/utils.js +45 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
# CHANGELOG
|
|
5
5
|
|
|
6
|
+
<p>
|
|
7
|
+
<b>Version 1.0.56</b> August 2022<br/>
|
|
8
|
+
- NEW: added string conversion from "true", "false", "0", "1", "close" to boolean.</br>
|
|
9
|
+
- Updated the README</br>
|
|
10
|
+
</p>
|
|
11
|
+
<p>
|
|
12
|
+
<b>Version 1.0.55</b> July 2022<br/>
|
|
13
|
+
- NEW: you can now specify the input property name from witch the node picks up the payload.</br>
|
|
14
|
+
- NEW: added more Homeassistant string compatibility values.</br>
|
|
15
|
+
- Updated the README</br>
|
|
16
|
+
</p>
|
|
6
17
|
<p>
|
|
7
18
|
<b>Version 1.0.53</b> June 2022<br/>
|
|
8
19
|
- NEW: Math Ultimate. The old "Sum" node, now has become a math node, you can peform multipication other than sum.</br>
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[](https://www.paypal.me/techtoday)
|
|
11
11
|
[![youtube][youtube-image]][youtube-url]
|
|
12
12
|
|
|
13
|
-
A set of Node-RED enhanced boolean logic and utility nodes, with persistent values after reboot. Compatible also with Homeassistant
|
|
13
|
+
A set of Node-RED enhanced boolean logic and utility nodes, with persistent values after reboot. Compatible also with Homeassistant values.
|
|
14
14
|
|
|
15
15
|
<br/>
|
|
16
16
|
<br/>
|
|
@@ -21,6 +21,26 @@ A set of Node-RED enhanced boolean logic and utility nodes, with persistent valu
|
|
|
21
21
|
<br/>
|
|
22
22
|
<br/>
|
|
23
23
|
|
|
24
|
+
### COMPATIBLES INPUT VALUES
|
|
25
|
+
Other than true/false, all nodes accepts these strings and convert it to true/false. All nodes are compatible with Homeassistant output strings.
|
|
26
|
+
|Input|Translated into|
|
|
27
|
+
|--|--|
|
|
28
|
+
| "on" | true |
|
|
29
|
+
| "off" | false |
|
|
30
|
+
| "active" | true |
|
|
31
|
+
| "inactive" | false |
|
|
32
|
+
| "open" | true |
|
|
33
|
+
| "closed" or "close" | false |
|
|
34
|
+
| "true" | true |
|
|
35
|
+
| "false" | false |
|
|
36
|
+
| "1" | true |
|
|
37
|
+
| "0" | false |
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<br/>
|
|
41
|
+
<br/>
|
|
42
|
+
|
|
43
|
+
|
|
24
44
|
# BOOLEAN LOGIC
|
|
25
45
|
|
|
26
46
|
<img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/bl1.png' width='60%'>
|
|
@@ -53,50 +73,24 @@ If you need ***"NAND"*** or ***"NOR"*** gate, just put an **InvertUltimate** nod
|
|
|
53
73
|
|
|
54
74
|
The node can have a persistent input: the input values are retained after a node-red reboot. That means, that if you reboot your node-red, you don't need to wait all inputs to arrive and initialize the node, before the node can output a payload.<br/>
|
|
55
75
|
You can also set the default values of the topic inputs.<br/>
|
|
56
|
-
The node can convert arbitrary input values to true/false. It supports Homeassistant
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
### CONFIGURATION
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
**Inputs count**
|
|
64
|
-
|
|
65
|
-
Set the number of different topics to be evaluated. The node will output a message to the flow, after this number of *different* topics arrives.<br/>
|
|
66
|
-
*Remember: each input topic must be different. For example, if you set this field to 3, the node expects 3 different topics.*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
**Filter output**
|
|
70
|
-
|
|
71
|
-
- Output both 'true' and 'false' results: Standard behaviour, the node will output <b>true</b> and <b>false</b> whenever it receives an input and calculate the boolean logics as output.
|
|
72
|
-
- Output only 'true' results: whenever the node receives an input, it outputs a payload <b>true</b> only if the result of the logic is true. <b>False</b> results are filtered out.
|
|
73
|
-
|
|
74
|
-
**Trigger mode**
|
|
75
|
-
|
|
76
|
-
- All topics: standard behaviour, the node will evaluate each input topic and ouputs the values. At each input change, it will output a msg on the flow.
|
|
77
|
-
- Single topic + eval other inputs: the node evaluates all the input topics, but only whenever it receives a msg input with the **specified topic**, it outputs a msg to the flow.
|
|
76
|
+
The node can convert arbitrary input values to true/false. It supports Homeassistant string to boolean conversion as well. For enabling auto conversion, please be sure to disable **Reject non boolean (true/false) input values** <br/>
|
|
78
77
|
|
|
79
|
-
**If input states are undefined**
|
|
80
78
|
|
|
81
|
-
Every time you create a node or modify the node, all inputs are set to undefined. This means that the node will wait the arrive of all topics (for example 3 topics, if you've selected 3 topics in the option), before it can output a payload. This can be a problem if your logic must be operative as soon as you deploy the flow. To overcome this problem, you can "initialize" all the undefined inputs with True or False.
|
|
82
|
-
- Leave undefined: Standard behaviour, the node will wait all the "undefined" topics to arrive, then starts a flow with the result.
|
|
83
|
-
- True or False: The node is immediately operative, by force the initialization of the "undefined" inputs with "true" or "false".
|
|
84
79
|
|
|
85
|
-
|
|
80
|
+
### NODE CONFIGURATION
|
|
86
81
|
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
|Property|Description|
|
|
83
|
+
|--|--|
|
|
84
|
+
| Inputs count | Set the number of different topics to be evaluated. The node will output a message to the flow, after this number of *different* topics arrives. *Remember: each input topic must be different. For example, if you set this field to 3, the node expects 3 different topics.* |
|
|
85
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
86
|
+
| Filter output | **Output both 'true' and 'false'** results: Standard behaviour, the node will output <b>true</b> and <b>false</b> whenever it receives an input and calculate the boolean logics as output. **Output only 'true'** results: whenever the node receives an input, it outputs a payload <b>true</b> only if the result of the logic is true. <b>False</b> results are filtered out. |
|
|
87
|
+
| Trigger mode | **All topics**: standard behaviour, the node will evaluate each input topic and ouputs the values. At each input change, it will output a msg on the flow. **Single topic + eval other inputs**: the node evaluates all the input topics, but only whenever it receives a msg input with the **specified topic**, it outputs a msg to the flow.|
|
|
88
|
+
| If input states are undefined | Every time you create a node or modify the node, all inputs are set to undefined. This means that the node will wait the arrive of all topics (for example 3 topics, if you've selected 3 topics in the option), before it can output a payload. This can be a problem if your logic must be operative as soon as you deploy the flow. To overcome this problem, you can "initialize" all the undefined inputs with True or False. **Leave undefined**: Standard behaviour, the node will wait all the "undefined" topics to arrive, then starts a flow with the result. **True or False**: The node is immediately operative, by force the initialization of the "undefined" inputs with "true" or "false".|
|
|
89
|
+
| Remember latest input values after reboot | If checked, the input values are retained after a node-red reboot. That means, that if you reboot your node-red, you don't need to wait all inputs to arrive and initialize the node, before the node can output a payload. Every time you modify the node's config, <b>the retained values are cleared</b>.|
|
|
90
|
+
| Reject non boolean (true/false) input values | If checked, the node will accept only boolean true/false values. Otherwise, it will try to convert the payload value to a logic true/false boolean. |
|
|
91
|
+
| Delay evaluation (ms) | Delays the evaluation until this time (in milliseconds) is elapsed. Each time a message or "topic trigger message" (see **Trigger mode**) arrives, the delay is restarted. This option is useful for debouncing pourposes or simply for adding some delay. For example, you can turn on a light if the room is occupied for a long time, allowing people to fast transit repeatedly, without the need of turning the light on. Another example, if you have many sensors changing state rapidly, you can wait until these sensor reach a quiet state, then evaluate the inputs.|
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
If checked, the node will accept only boolean true/false values. Otherwise, it will try to convert the payload to a logic value true/false (including "on" and "off" values, sent, for example, from HomeAssistant).<br/>
|
|
93
|
-
|
|
94
|
-
**Delay evaluation (ms)**
|
|
95
|
-
|
|
96
|
-
Delays the evaluation until this time (in milliseconds) is elapsed. Each time a message or "topic trigger message" (see **Trigger mode**) arrives, the delay is restarted.<br/>
|
|
97
|
-
This option is useful for debouncing pourposes or simply for adding some delay.<br/>
|
|
98
|
-
For example, you can turn on a light if the room is occupied for a long time, allowing people to fast transit repeatedly, without the need of turning the light on.<br/>
|
|
99
|
-
Another example, if you have many sensors changing state rapidly, you can wait until these sensor reach a quiet state, then evaluate the inputs.<br/>
|
|
93
|
+
<br/>
|
|
100
94
|
|
|
101
95
|
**INPUT MSG TO THE NODE**
|
|
102
96
|
|
|
@@ -115,17 +109,21 @@ Resets all inputs to undefined.
|
|
|
115
109
|
|
|
116
110
|
The interrupt flows is able to stop the input messages to exiting the node.
|
|
117
111
|
|
|
118
|
-
|
|
112
|
+
### NODE CONFIGURATION
|
|
113
|
+
|
|
114
|
+
|Property|Description|
|
|
115
|
+
|--|--|
|
|
116
|
+
| Trigger by topic | Whenever the node receives a payload = false from this topic,it stops output messages to the flow. As soon it receives payload = true from this topic, the output messages start to flow out again. The node will output the current stored message plus an added property "isReplay = true", as soon as it receives a ***msg.play = true*** from this topic. The node will clear the current stored message, as soon as it receives a ***msg.reset = true*** from this topic. |
|
|
117
|
+
| With Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
118
|
+
| Then | This property, allow you to auto toggle the selected start state (pass or block) after a timer has elapsed. You can choose from some pre-defined delays. If you have, for example, an Homekit-Bridged nodeset with a thermostat node or security system node in your flow, once node-red restarts, these homekit nodes output a default message to the flow. Just put an InterruptFlow node with a "block at start" behaviour and a toggle delay enabled behind homekit nodes, to temporary stop the chained nodes to receive the unwanted startup message.|
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
<br/>
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
119
125
|
|
|
120
|
-
Whenever the node receives a payload = false from this topic,it stops output messages to the flow.<br/>
|
|
121
|
-
As soon it receives payload = true from this topic, the output messages start to flow out again. <br/>
|
|
122
|
-
The node will output the current stored message plus an added property "isReplay = true", as soon as it receives a ***msg.play = true*** from this topic.<br/>
|
|
123
|
-
The node will clear the current stored message, as soon as it receives a ***msg.reset = true*** from this topic.<br/>
|
|
124
|
-
The node tries to convert any arbitrary input value to a valid boolean value. It converts Homeassistant ***"on"*** and ***"off"*** to true/false values as well.<br/>
|
|
125
126
|
|
|
126
|
-
**Then**
|
|
127
|
-
This property, allow you to auto toggle the selected start state (pass or block) after a timer has elapsed. You can choose from some pre-defined delays. If you have, for example, an Homekit-Bridged nodeset with a thermostat node or security system node in your flow, once node-red restarts, these homekit nodes output a default message to the flow. Just put an InterruptFlow node with a "block at start" behaviour and a toggle delay enabled behind homekit nodes, to temporary stop the chained nodes to receive the unwanted startup message.</br>
|
|
128
|
-
</br>
|
|
129
127
|
|
|
130
128
|
**INPUT MSG WITH "TRIGGER" TOPIC**
|
|
131
129
|
|
|
@@ -183,7 +181,15 @@ This allow to save the state of a node and then replay it back whenever you want
|
|
|
183
181
|
|
|
184
182
|
Outputs the inverted input. For example true -> false<br />
|
|
185
183
|
The input message is preserved and passed to the output pin, changing only the topic and the payload. If the input message has it's own topic, it'll be preserved as well.<br/>
|
|
186
|
-
|
|
184
|
+
|
|
185
|
+
### NODE CONFIGURATION
|
|
186
|
+
|
|
187
|
+
|Property|Description|
|
|
188
|
+
|--|--|
|
|
189
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
190
|
+
|
|
191
|
+
<br/>
|
|
192
|
+
|
|
187
193
|
|
|
188
194
|
<br/>
|
|
189
195
|
<br/>
|
|
@@ -197,7 +203,15 @@ This node has 2 outputs.<br />
|
|
|
197
203
|
If the input payload is true, the node will send <code>true</code> on output 1 and nothing on oputput 2<br />
|
|
198
204
|
If the input payload is false, the node will send nothing on output 1, and <code>false</code> on oputput 2<br />
|
|
199
205
|
The input message is preserved and passed to the output pin, changing only the topic and the payload. If the input message has it's own topic, it'll be preserved as well.<br/>
|
|
200
|
-
|
|
206
|
+
|
|
207
|
+
### NODE CONFIGURATION
|
|
208
|
+
|
|
209
|
+
|Property|Description|
|
|
210
|
+
|--|--|
|
|
211
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
212
|
+
|
|
213
|
+
<br/>
|
|
214
|
+
|
|
201
215
|
|
|
202
216
|
<br/>
|
|
203
217
|
<br/>
|
|
@@ -212,6 +226,15 @@ Output PIN1 : outputs the value true/false<br/>
|
|
|
212
226
|
Output PIN2 : outputs the inverted value false/true<br/>
|
|
213
227
|
<br/>
|
|
214
228
|
|
|
229
|
+
### NODE CONFIGURATION
|
|
230
|
+
|
|
231
|
+
|Property|Description|
|
|
232
|
+
|--|--|
|
|
233
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
234
|
+
|
|
235
|
+
<br/>
|
|
236
|
+
|
|
237
|
+
|
|
215
238
|
Pass <code>msg.payload = true</code> to start blinking</br>
|
|
216
239
|
Pass <code>msg.payload = false</code> to stop blinking</br>
|
|
217
240
|
Pass <code>msg.interval = 2000</code> to change the blinking interval</br>
|
|
@@ -239,6 +262,15 @@ Pass <code>msg.interval = 2000</code> to change the blinking interval</br>
|
|
|
239
262
|
The pourpose of this node is to send a message with payload TRUE on the first pin and FALSE on second pin, independently from the msg input.<br />
|
|
240
263
|
This is useful if you need to simply send a true or false payload.
|
|
241
264
|
|
|
265
|
+
### NODE CONFIGURATION
|
|
266
|
+
|
|
267
|
+
|Property|Description|
|
|
268
|
+
|--|--|
|
|
269
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
270
|
+
|
|
271
|
+
<br/>
|
|
272
|
+
|
|
273
|
+
|
|
242
274
|
<img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/SimpleOutput.png' width='60%'>
|
|
243
275
|
|
|
244
276
|
<details><summary>CLICK HERE, copy and paste it into your flow</summary>
|
|
@@ -304,6 +336,15 @@ The pourpose of this node is to send a sequence of pulsed commands to for exampl
|
|
|
304
336
|
</code>
|
|
305
337
|
</details>
|
|
306
338
|
|
|
339
|
+
### NODE CONFIGURATION
|
|
340
|
+
|
|
341
|
+
|Property|Description|
|
|
342
|
+
|--|--|
|
|
343
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
344
|
+
|
|
345
|
+
<br/>
|
|
346
|
+
|
|
347
|
+
|
|
307
348
|
**Avaiable Commands**<br />
|
|
308
349
|
Commands are to be wrote in the format: command:value. For example ***send:200***, ***wait:2000***. Each row represents a command.<br />
|
|
309
350
|
<br /><b>send</b><br />
|
|
@@ -332,6 +373,7 @@ Pass <code>msg.payload = false</code> to the node to stop the running sequence</
|
|
|
332
373
|
|
|
333
374
|
The pourpose of this node is to do maths on the incoming values. Each incoming message MUST HAVE OWN TOPIC.<br />
|
|
334
375
|
|
|
376
|
+
|
|
335
377
|
<img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/sum.png' width='60%'>
|
|
336
378
|
<details><summary>CLICK HERE, copy and paste it into your flow</summary>
|
|
337
379
|
<code>
|
|
@@ -339,6 +381,15 @@ The pourpose of this node is to do maths on the incoming values. Each incoming m
|
|
|
339
381
|
</code>
|
|
340
382
|
</details>
|
|
341
383
|
|
|
384
|
+
### NODE CONFIGURATION
|
|
385
|
+
|
|
386
|
+
|Property|Description|
|
|
387
|
+
|--|--|
|
|
388
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
389
|
+
|
|
390
|
+
<br/>
|
|
391
|
+
|
|
392
|
+
|
|
342
393
|
**INPUT**<br />
|
|
343
394
|
|
|
344
395
|
<br /><b>msg.reset</b><br />
|
|
@@ -365,8 +416,16 @@ br/>
|
|
|
365
416
|
|
|
366
417
|
# TOGGLE ULTIMATE
|
|
367
418
|
|
|
368
|
-
The pourpose of this node is to toggle between true/false
|
|
419
|
+
The pourpose of this node is to toggle between true/false, everytime an inboud message arrives.<br />
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
### NODE CONFIGURATION
|
|
423
|
+
|
|
424
|
+
|Property|Description|
|
|
425
|
+
|--|--|
|
|
426
|
+
| Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
369
427
|
|
|
428
|
+
<br/>
|
|
370
429
|
|
|
371
430
|
**INPUT**<br />
|
|
372
431
|
|
|
@@ -384,12 +443,17 @@ The railway switcher, switches the input msg flow to one ot the two output pins
|
|
|
384
443
|
|
|
385
444
|
<img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/railroadSwitchScambio.png' width='80%'>
|
|
386
445
|
|
|
387
|
-
|
|
446
|
+
### NODE CONFIGURATION
|
|
447
|
+
|
|
448
|
+
|Property|Description|
|
|
449
|
+
|--|--|
|
|
450
|
+
| Switcher topic | Whenever the node receives a payload from this **topic**, it switches the input messages to an output PIN. |
|
|
451
|
+
| With Input | Set the property where the input payload is. *By default, it is "payload", but you can also specify other properties, for example "payload.value"* |
|
|
452
|
+
| Then | This property, allow you to auto toggle the selected start state after some time. |
|
|
388
453
|
|
|
389
|
-
|
|
454
|
+
<br/>
|
|
390
455
|
|
|
391
|
-
|
|
392
|
-
This property, allow you to auto toggle the selected start state after some time.</br>
|
|
456
|
+
</br>
|
|
393
457
|
</br>
|
|
394
458
|
|
|
395
459
|
**INPUT MSG WITH "TRIGGER" TOPIC**
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
stopbehaviorPIN2: { value: "0" },
|
|
9
9
|
blinkfrequency: { value: "500" },
|
|
10
10
|
initializewith: { value: "0" },
|
|
11
|
+
payloadPropName: { value: "payload", required: false }
|
|
11
12
|
},
|
|
12
13
|
inputs: 1,
|
|
13
14
|
outputs: 2,
|
|
@@ -30,6 +31,10 @@
|
|
|
30
31
|
},
|
|
31
32
|
paletteLabel: function () {
|
|
32
33
|
return "BlinkerUltimate";
|
|
34
|
+
},
|
|
35
|
+
oneditprepare: function () {
|
|
36
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
37
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
33
38
|
}
|
|
34
39
|
});
|
|
35
40
|
</script>
|
|
@@ -45,7 +50,10 @@
|
|
|
45
50
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
46
51
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
47
52
|
</div>
|
|
48
|
-
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
55
|
+
<input type="text" id="node-input-payloadPropName">
|
|
56
|
+
</div>
|
|
49
57
|
<div class="form-row">
|
|
50
58
|
<label for="node-input-blinkfrequency"><i class="fa fa-clock-o"></i> Blink every (in milliseconds)</label>
|
|
51
59
|
<input type="text" id="node-input-blinkfrequency" placeholder="Example: 500">
|
|
@@ -41,9 +41,13 @@ module.exports = function (RED) {
|
|
|
41
41
|
setNodeStatus({ fill: "red", shape: "dot", text: "Invalid interval received" });
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
const utils = require("./utils.js");
|
|
46
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
47
|
+
|
|
48
|
+
if (sPayload !== undefined) {
|
|
45
49
|
// 06/11/2019
|
|
46
|
-
if (ToBoolean(
|
|
50
|
+
if (utils.ToBoolean(sPayload) === true) {
|
|
47
51
|
if (node.tBlinker !== null) clearInterval(node.tBlinker);
|
|
48
52
|
node.tBlinker = setInterval(handleTimer, node.blinkfrequency); // Start the timer that handles the queue of telegrams
|
|
49
53
|
node.isBlinking = true;
|
|
@@ -68,32 +72,6 @@ module.exports = function (RED) {
|
|
|
68
72
|
});
|
|
69
73
|
|
|
70
74
|
|
|
71
|
-
function ToBoolean(value) {
|
|
72
|
-
let res = false;
|
|
73
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
74
|
-
|
|
75
|
-
if (typeof value === 'boolean') {
|
|
76
|
-
res = value;
|
|
77
|
-
}
|
|
78
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
79
|
-
|
|
80
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
81
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// Is it formated as a decimal number?
|
|
85
|
-
if (decimal.test(value)) {
|
|
86
|
-
res = parseFloat(value) != 0;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
res = value.toLowerCase() === "true";
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return res;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
|
|
97
75
|
function handleTimer() {
|
|
98
76
|
node.curPayload = !node.curPayload;
|
|
99
77
|
node.send([{ payload: node.curPayload }, { payload: !node.curPayload }]);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
name: {
|
|
7
7
|
value: ""
|
|
8
8
|
},
|
|
9
|
+
payloadPropName: { value: "payload", required: false },
|
|
9
10
|
filtertrue: { value: "both" },
|
|
10
11
|
persist: { value: true },
|
|
11
12
|
sInitializeWith: { value: "WaitForPayload" },
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
return v !== undefined && v.length > 0;
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
|
-
restrictinputevaluation: { value:
|
|
37
|
+
restrictinputevaluation: { value: false },
|
|
37
38
|
delayEvaluation: { value: 0 }
|
|
38
39
|
},
|
|
39
40
|
inputs: 1,
|
|
@@ -77,6 +78,10 @@
|
|
|
77
78
|
return "BooleanLogicUltimate";
|
|
78
79
|
},
|
|
79
80
|
oneditprepare: function () {
|
|
81
|
+
|
|
82
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
83
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
84
|
+
|
|
80
85
|
// Add write and response as default for existing nodes like was default before
|
|
81
86
|
if (this.outputtriggeredby === 'all') {
|
|
82
87
|
$("#triggertopic").hide()
|
|
@@ -131,6 +136,10 @@
|
|
|
131
136
|
<div class="form-row">
|
|
132
137
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
133
138
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
139
|
+
</div>
|
|
140
|
+
<div class="form-row">
|
|
141
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
142
|
+
<input type="text" id="node-input-payloadPropName">
|
|
134
143
|
</div>
|
|
135
144
|
<div class="form-row">
|
|
136
145
|
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
|
|
@@ -94,23 +94,27 @@ module.exports = function (RED) {
|
|
|
94
94
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid topic!" });
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var topic = msg.topic;
|
|
100
|
+
const utils = require("./utils.js");
|
|
101
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
102
102
|
|
|
103
103
|
// 12/08/2021 Restrict only to true/false
|
|
104
104
|
if (node.restrictinputevaluation) {
|
|
105
|
-
if (
|
|
105
|
+
if (sPayload !== true && sPayload !== false) {
|
|
106
106
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received non boolean value from " + msg.topic });
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
var value = utils.ToBoolean(sPayload);
|
|
112
|
+
|
|
113
|
+
// 15/11/2021 inform user about undefined topic or payload
|
|
114
|
+
if (sPayload === undefined) {
|
|
115
|
+
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
114
118
|
|
|
115
119
|
// 14/08/2019 if inputs are initialized, remove a "dummy" item from the state's array, as soon as new topic arrives
|
|
116
120
|
if (node.sInitializeWith !== "WaitForPayload") {
|
|
@@ -277,29 +281,7 @@ module.exports = function (RED) {
|
|
|
277
281
|
return res;
|
|
278
282
|
}
|
|
279
283
|
|
|
280
|
-
function ToBoolean(value) {
|
|
281
|
-
let res = false;
|
|
282
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
283
|
-
|
|
284
|
-
if (typeof value === 'boolean') {
|
|
285
|
-
res = value;
|
|
286
|
-
}
|
|
287
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
288
|
-
|
|
289
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
290
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
291
284
|
|
|
292
|
-
// Is it formated as a decimal number?
|
|
293
|
-
if (decimal.test(value)) {
|
|
294
|
-
res = parseFloat(value) != 0;
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
res = value.toLowerCase() === "true";
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return res;
|
|
302
|
-
};
|
|
303
285
|
|
|
304
286
|
function outputResult() {
|
|
305
287
|
let optionalTopic = node.config.topic;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {
|
|
7
7
|
value: "Filter"
|
|
8
|
-
}
|
|
8
|
+
},
|
|
9
|
+
payloadPropName: { value: "payload", required: false }
|
|
9
10
|
},
|
|
10
11
|
inputs: 1,
|
|
11
12
|
outputs: 2,
|
|
@@ -29,6 +30,10 @@
|
|
|
29
30
|
},
|
|
30
31
|
paletteLabel: function () {
|
|
31
32
|
return "FilterUltimate";
|
|
33
|
+
},
|
|
34
|
+
oneditprepare: function () {
|
|
35
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
36
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
32
37
|
}
|
|
33
38
|
});
|
|
34
39
|
</script>
|
|
@@ -44,6 +49,10 @@
|
|
|
44
49
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
45
50
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
46
51
|
</div>
|
|
52
|
+
<div class="form-row">
|
|
53
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
54
|
+
<input type="text" id="node-input-payloadPropName">
|
|
55
|
+
</div>
|
|
47
56
|
</script>
|
|
48
57
|
|
|
49
58
|
<script type="text/x-red" data-help-name="FilterUltimate">
|
|
@@ -13,20 +13,24 @@ module.exports = function (RED) {
|
|
|
13
13
|
setNodeStatus({ fill: "grey", shape: "dot", text: "Waiting" });
|
|
14
14
|
this.on('input', function (msg) {
|
|
15
15
|
|
|
16
|
+
const utils = require("./utils.js");
|
|
17
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
18
|
+
|
|
16
19
|
// 15/11/2021 inform user about undefined topic or payload
|
|
17
|
-
if (
|
|
20
|
+
if (sPayload=== undefined ) {
|
|
18
21
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
19
22
|
return;
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
|
|
22
26
|
var bRes = null;
|
|
23
27
|
try {
|
|
24
|
-
bRes = ToBoolean(
|
|
28
|
+
bRes = utils.ToBoolean(sPayload);
|
|
25
29
|
} catch (error) {
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
if (bRes === undefined || bRes === null) {
|
|
29
|
-
setNodeStatus({ fill: "red", shape: "dot", text: "Received non convertible boolean value " +
|
|
33
|
+
setNodeStatus({ fill: "red", shape: "dot", text: "Received non convertible boolean value " + sPayload + " from " + msg.topic });
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -44,31 +48,6 @@ module.exports = function (RED) {
|
|
|
44
48
|
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function ToBoolean(value) {
|
|
50
|
-
let res = false;
|
|
51
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
52
|
-
|
|
53
|
-
if (typeof value === 'boolean') {
|
|
54
|
-
res = value;
|
|
55
|
-
}
|
|
56
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
57
|
-
|
|
58
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
59
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
60
|
-
|
|
61
|
-
// Is it formated as a decimal number?
|
|
62
|
-
if (decimal.test(value)) {
|
|
63
|
-
res = parseFloat(value) != 0;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
res = value.toLowerCase() === "true";
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return res;
|
|
71
|
-
};
|
|
72
51
|
}
|
|
73
52
|
|
|
74
53
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name: { value: "" },
|
|
7
7
|
commandText: { value: "// Open garage door\nsend:true\nwait:1000\nsend:false" },
|
|
8
|
+
payloadPropName: { value: "payload", required: false }
|
|
8
9
|
},
|
|
9
10
|
inputs: 1,
|
|
10
11
|
outputs: 1,
|
|
@@ -30,6 +31,8 @@
|
|
|
30
31
|
mode: 'ace/mode/text',
|
|
31
32
|
value: node.commandText
|
|
32
33
|
});
|
|
34
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
35
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
33
36
|
},
|
|
34
37
|
oneditsave: function () {
|
|
35
38
|
var node = this;
|
|
@@ -57,6 +60,10 @@
|
|
|
57
60
|
<div class="form-row">
|
|
58
61
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
59
62
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
63
|
+
</div>
|
|
64
|
+
<div class="form-row">
|
|
65
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
66
|
+
<input type="text" id="node-input-payloadPropName">
|
|
60
67
|
</div>
|
|
61
68
|
<div class="form-row" >
|
|
62
69
|
<label style="width:300px;" for="node-input-commandText"><i class="fa fa-tasks"></i> Commands (one command per row)</label>
|
|
@@ -90,15 +90,18 @@ module.exports = function (RED) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
this.on('input', function (msg) {
|
|
93
|
+
|
|
94
|
+
const utils = require("./utils.js");
|
|
95
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
93
96
|
|
|
94
|
-
if (
|
|
97
|
+
if (sPayload === true) {
|
|
95
98
|
if (node.isPlaying) {
|
|
96
99
|
node.setNodeStatus({ fill: "yellow", shape: "ring", text: "Already running. Stop me first." });
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
102
|
avvio();
|
|
100
103
|
|
|
101
|
-
} else if (
|
|
104
|
+
} else if (sPayload === false) {
|
|
102
105
|
if (node.timerWait !== null) clearTimeout(node.timerWait);
|
|
103
106
|
node.isPlaying = false;
|
|
104
107
|
node.setNodeStatus({ fill: "red", shape: "dot", text: "Forced stop" });
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
name: { value: "Interrupt Flow" },
|
|
7
7
|
triggertopic: { value: "trigger" },
|
|
8
8
|
initializewith: { value: "1" },
|
|
9
|
-
autoToggle: { value: "0" }
|
|
9
|
+
autoToggle: { value: "0" },
|
|
10
|
+
payloadPropName: { value: "payload", required: false }
|
|
10
11
|
},
|
|
11
12
|
inputs: 1,
|
|
12
13
|
outputs: 1,
|
|
@@ -30,6 +31,10 @@
|
|
|
30
31
|
},
|
|
31
32
|
paletteLabel: function () {
|
|
32
33
|
return "InterruptFlowUltimate";
|
|
34
|
+
},
|
|
35
|
+
oneditprepare: function () {
|
|
36
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
37
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
33
38
|
}
|
|
34
39
|
});
|
|
35
40
|
</script>
|
|
@@ -45,16 +50,19 @@
|
|
|
45
50
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
46
51
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
47
52
|
</div>
|
|
48
|
-
|
|
49
53
|
<div class="form-row">
|
|
50
54
|
<label for="node-input-triggertopic"><i class="icon-tag"></i> Trigger by topic</label>
|
|
51
55
|
<input type="text" id="node-input-triggertopic" placeholder="Name">
|
|
52
|
-
|
|
56
|
+
</div>
|
|
57
|
+
<div class="form-row">
|
|
58
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> With Input</label>
|
|
59
|
+
<input type="text" id="node-input-payloadPropName">
|
|
60
|
+
</div>
|
|
61
|
+
<div><i>Whenever the node receives a msg with false from this topic,<br/> it stops output messages to the flow.<br/>As soon it receives a message with true from this topic,<br/>the output messages start to flow out again.
|
|
53
62
|
<br/>The node will output the current stored message<br/>plus an added property "isReplay = true",<br/>as soon as it receives a "play" = true from this topic.</br>
|
|
54
63
|
The node will clear the current stored message, as soon as it receives a "msg.reset = true" from this topic.
|
|
55
64
|
</i></div>
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
<br/>
|
|
58
66
|
<div class="form-row">
|
|
59
67
|
<label style="width:160px" for="node-input-initializewith"><i class="fa fa-home"></i> At node-red start</label>
|
|
60
68
|
<select type="text" id="node-input-initializewith" placeholder="">
|
|
@@ -43,13 +43,14 @@ module.exports = function (RED) {
|
|
|
43
43
|
sIncomingTopic = msg.topic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, ''); // Cut unwanted Characters
|
|
44
44
|
if (sIncomingTopic === node.sTriggerTopic) {
|
|
45
45
|
|
|
46
|
+
const utils = require("./utils.js");
|
|
47
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
46
48
|
// 15/11/2021 inform user about undefined topic or payload
|
|
47
|
-
if (
|
|
49
|
+
if (sPayload === undefined ) {
|
|
48
50
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
49
51
|
return;
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
msg.payload = ToBoolean(msg.payload); // 15/11/2021 Convert input to boolean.
|
|
53
|
+
msg.payload = utils.ToBoolean(sPayload); // 15/11/2021 Convert input to boolean.
|
|
53
54
|
|
|
54
55
|
// 28/01/2022 Stop autotoggle
|
|
55
56
|
if (node.timerAutoToggle !== null) clearInterval(node.timerAutoToggle);
|
|
@@ -93,31 +94,6 @@ module.exports = function (RED) {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function ToBoolean(value) {
|
|
99
|
-
let res = false;
|
|
100
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
101
|
-
|
|
102
|
-
if (typeof value === 'boolean') {
|
|
103
|
-
res = value;
|
|
104
|
-
}
|
|
105
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
106
|
-
|
|
107
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
108
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
109
|
-
|
|
110
|
-
// Is it formated as a decimal number?
|
|
111
|
-
if (decimal.test(value)) {
|
|
112
|
-
res = parseFloat(value) != 0;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
res = value.toLowerCase() === "true";
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return res;
|
|
120
|
-
};
|
|
121
97
|
}
|
|
122
98
|
|
|
123
99
|
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
defaults: {
|
|
6
6
|
name: {
|
|
7
7
|
value: "Invert"
|
|
8
|
-
}
|
|
8
|
+
},
|
|
9
|
+
payloadPropName: { value: "payload", required: false }
|
|
9
10
|
},
|
|
10
11
|
inputs:1,
|
|
11
12
|
outputs:1,
|
|
@@ -16,6 +17,10 @@
|
|
|
16
17
|
},
|
|
17
18
|
paletteLabel: function() {
|
|
18
19
|
return "InvertUltimate";
|
|
20
|
+
},
|
|
21
|
+
oneditprepare: function () {
|
|
22
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
23
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
19
24
|
}
|
|
20
25
|
});
|
|
21
26
|
</script>
|
|
@@ -31,6 +36,10 @@
|
|
|
31
36
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
32
37
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
33
38
|
</div>
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
41
|
+
<input type="text" id="node-input-payloadPropName">
|
|
42
|
+
</div>
|
|
34
43
|
</script>
|
|
35
44
|
|
|
36
45
|
<script type="text/x-red" data-help-name="InvertUltimate">
|
|
@@ -15,21 +15,23 @@ module.exports = function (RED) {
|
|
|
15
15
|
this.on('input', function (msg) {
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
// 11/11/2021 Clone input message and replace only relevant topics
|
|
19
|
+
const utils = require("./utils.js");
|
|
20
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
21
|
+
|
|
18
22
|
// 15/11/2021 inform user about undefined topic or payload
|
|
19
|
-
if (
|
|
23
|
+
if (sPayload === undefined ) {
|
|
20
24
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
// 11/11/2021 Clone input message and replace only relevant topics
|
|
26
28
|
var bRes = null;
|
|
27
29
|
try {
|
|
28
|
-
bRes = ToBoolean(
|
|
30
|
+
bRes = utils.ToBoolean(sPayload);
|
|
29
31
|
} catch (error) {
|
|
30
32
|
}
|
|
31
33
|
if (bRes === undefined || bRes === null) {
|
|
32
|
-
setNodeStatus({ fill: "red", shape: "dot", text: "Received non convertible boolean value " +
|
|
34
|
+
setNodeStatus({ fill: "red", shape: "dot", text: "Received non convertible boolean value " + sPayload + " from " + msg.topic });
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -44,34 +46,6 @@ module.exports = function (RED) {
|
|
|
44
46
|
|
|
45
47
|
});
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function ToBoolean(value) {
|
|
50
|
-
let res = false;
|
|
51
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
52
|
-
|
|
53
|
-
if (typeof value === 'boolean') {
|
|
54
|
-
res = value;
|
|
55
|
-
}
|
|
56
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
57
|
-
|
|
58
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
59
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
60
|
-
|
|
61
|
-
// Is it formated as a decimal number?
|
|
62
|
-
if (decimal.test(value)) {
|
|
63
|
-
res = parseFloat(value) != 0;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
res = value.toLowerCase() === "true";
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return res;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
49
|
}
|
|
76
50
|
|
|
77
51
|
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
name: { value: "Railway Switch" },
|
|
7
7
|
triggertopic: { value: "trigger" },
|
|
8
8
|
initializewith: { value: "0" },
|
|
9
|
-
autoToggle: { value: "0" }
|
|
9
|
+
autoToggle: { value: "0" },
|
|
10
|
+
payloadPropName: { value: "payload", required: false }
|
|
10
11
|
},
|
|
11
12
|
inputs: 1,
|
|
12
13
|
outputs: 2,
|
|
@@ -30,6 +31,10 @@
|
|
|
30
31
|
},
|
|
31
32
|
paletteLabel: function () {
|
|
32
33
|
return "RailwaySwitchUltimate";
|
|
34
|
+
},
|
|
35
|
+
oneditprepare: function () {
|
|
36
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
37
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
33
38
|
}
|
|
34
39
|
});
|
|
35
40
|
</script>
|
|
@@ -49,12 +54,16 @@
|
|
|
49
54
|
<div class="form-row">
|
|
50
55
|
<label for="node-input-triggertopic"><i class="icon-tag"></i> Switcher topic</label>
|
|
51
56
|
<input type="text" id="node-input-triggertopic" placeholder="Name">
|
|
52
|
-
<div><i>An input msg having this topic and payload true or false<br/>will trigger the railway switch between the two output PINs<br/>
|
|
53
|
-
msg.payload = false switches to the upper PIN<br/>
|
|
54
|
-
msg.payload = true switches to the lower PIN<br/>
|
|
55
|
-
</i></div>
|
|
56
57
|
</div>
|
|
57
|
-
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> With Input</label>
|
|
60
|
+
<input type="text" id="node-input-payloadPropName">
|
|
61
|
+
</div>
|
|
62
|
+
<div><i>An input msg having this topic and msg true or false<br/>will trigger the railway switch between the two output PINs<br/>
|
|
63
|
+
false switches to the upper PIN<br/>
|
|
64
|
+
true switches to the lower PIN<br/>
|
|
65
|
+
</i></div>
|
|
66
|
+
<br/>
|
|
58
67
|
<div class="form-row">
|
|
59
68
|
<label style="width:160px" for="node-input-initializewith"><i class="fa fa-home"></i> At node-red start</label>
|
|
60
69
|
<select type="text" id="node-input-initializewith" placeholder="" style="width:250px">
|
|
@@ -41,13 +41,17 @@ module.exports = function (RED) {
|
|
|
41
41
|
sIncomingTopic = msg.topic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, ''); // Cut unwanted Characters
|
|
42
42
|
if (sIncomingTopic === node.sTriggerTopic) {
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
const utils = require("./utils.js");
|
|
46
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
47
|
+
|
|
44
48
|
// 15/11/2021 inform user about undefined topic or payload
|
|
45
|
-
if (
|
|
49
|
+
if (sPayload === undefined ) {
|
|
46
50
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
msg.payload = ToBoolean(
|
|
53
|
+
|
|
54
|
+
msg.payload = utils.ToBoolean(sPayload); // 15/11/2021 Convert input to boolean.
|
|
51
55
|
|
|
52
56
|
// 28/01/2022 Stop autotoggle
|
|
53
57
|
if (node.timerAutoToggle !== null) clearInterval(node.timerAutoToggle);
|
|
@@ -70,32 +74,6 @@ module.exports = function (RED) {
|
|
|
70
74
|
}
|
|
71
75
|
});
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function ToBoolean(value) {
|
|
77
|
-
let res = false;
|
|
78
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
79
|
-
|
|
80
|
-
if (typeof value === 'boolean') {
|
|
81
|
-
res = value;
|
|
82
|
-
}
|
|
83
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
84
|
-
|
|
85
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
86
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
87
|
-
|
|
88
|
-
// Is it formated as a decimal number?
|
|
89
|
-
if (decimal.test(value)) {
|
|
90
|
-
res = parseFloat(value) != 0;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
res = value.toLowerCase() === "true";
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return res;
|
|
98
|
-
};
|
|
99
77
|
}
|
|
100
78
|
|
|
101
79
|
|
|
@@ -23,7 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
paletteLabel: function () {
|
|
25
25
|
return "MathUltimate";
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
|
+
oneditprepare: function () {
|
|
28
|
+
if ($("#node-input-property").val() === "") $("#node-input-property").val("payload");
|
|
29
|
+
$("#node-input-property").typedInput({ default: 'msg', types: ['msg'] });
|
|
30
|
+
}
|
|
27
31
|
});
|
|
28
32
|
</script>
|
|
29
33
|
|
|
@@ -39,7 +43,7 @@
|
|
|
39
43
|
<input type="text" id="node-input-name" placeholder="Topic">
|
|
40
44
|
</div>
|
|
41
45
|
<div class="form-row">
|
|
42
|
-
<label for="node-input-property"><i class="icon-tag"></i>
|
|
46
|
+
<label for="node-input-property"><i class="icon-tag"></i> Input</label>
|
|
43
47
|
<input type="text" id="node-input-property" placeholder="payload">
|
|
44
48
|
</div>
|
|
45
49
|
<div class="form-row">
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
name: {
|
|
7
7
|
value: "Toggle"
|
|
8
8
|
},
|
|
9
|
-
valueToToggle: { value: "true" }
|
|
9
|
+
valueToToggle: { value: "true" },
|
|
10
|
+
payloadPropName: { value: "payload", required: false }
|
|
10
11
|
},
|
|
11
12
|
inputs: 1,
|
|
12
13
|
outputs: 1,
|
|
@@ -17,6 +18,10 @@
|
|
|
17
18
|
},
|
|
18
19
|
paletteLabel: function () {
|
|
19
20
|
return "toggleUltimate";
|
|
21
|
+
},
|
|
22
|
+
oneditprepare: function () {
|
|
23
|
+
if ($("#node-input-payloadPropName").val() === "") $("#node-input-payloadPropName").val("payload");
|
|
24
|
+
$("#node-input-payloadPropName").typedInput({ default: 'msg', types: ['msg'] });
|
|
20
25
|
}
|
|
21
26
|
});
|
|
22
27
|
</script>
|
|
@@ -31,6 +36,10 @@
|
|
|
31
36
|
<div class="form-row">
|
|
32
37
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
|
33
38
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
39
|
+
</div>
|
|
40
|
+
<div class="form-row">
|
|
41
|
+
<label for="node-input-payloadPropName"><i class="fa fa-ellipsis-h"></i> Input</label>
|
|
42
|
+
<input type="text" id="node-input-payloadPropName">
|
|
34
43
|
</div>
|
|
35
44
|
<div class="form-row">
|
|
36
45
|
<label style="width:160px" for="node-input-valueToToggle"><i class="fa fa-toggle-on"></i> Initial value</label>
|
|
@@ -3,7 +3,8 @@ module.exports = function (RED) {
|
|
|
3
3
|
RED.nodes.createNode(this, config);
|
|
4
4
|
this.config = config;
|
|
5
5
|
var node = this;
|
|
6
|
-
|
|
6
|
+
const utils = require("./utils.js");
|
|
7
|
+
node.valueToToggle = config.valueToToggle === undefined ? true : utils.ToBoolean(config.valueToToggle);
|
|
7
8
|
|
|
8
9
|
function setNodeStatus({ fill, shape, text }) {
|
|
9
10
|
let dDate = new Date();
|
|
@@ -14,9 +15,11 @@ module.exports = function (RED) {
|
|
|
14
15
|
|
|
15
16
|
this.on('input', function (msg) {
|
|
16
17
|
|
|
18
|
+
const utils = require("./utils.js");
|
|
19
|
+
let sPayload = utils.fetchFromObject(msg, config.payloadPropName || "payload");
|
|
17
20
|
|
|
18
21
|
// 15/11/2021 inform user about undefined topic or payload
|
|
19
|
-
if (
|
|
22
|
+
if (sPayload === undefined ) {
|
|
20
23
|
setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
@@ -35,33 +38,6 @@ module.exports = function (RED) {
|
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
function ToBoolean(value) {
|
|
40
|
-
let res = false;
|
|
41
|
-
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
42
|
-
|
|
43
|
-
if (typeof value === 'boolean') {
|
|
44
|
-
res = value;
|
|
45
|
-
}
|
|
46
|
-
else if (typeof value === 'number' || typeof value === 'string') {
|
|
47
|
-
|
|
48
|
-
if (typeof value === "string" && value.toLowerCase() === "on") return true;
|
|
49
|
-
if (typeof value === "string" && value.toLowerCase() === "off") return false;
|
|
50
|
-
|
|
51
|
-
// Is it formated as a decimal number?
|
|
52
|
-
if (decimal.test(value)) {
|
|
53
|
-
res = parseFloat(value) != 0;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
res = value.toLowerCase() === "true";
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return res;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
41
|
}
|
|
66
42
|
|
|
67
43
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module.exports.ToBoolean = function ToBoolean(value) {
|
|
2
|
+
let res = false;
|
|
3
|
+
let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
|
|
4
|
+
|
|
5
|
+
if (typeof value === 'boolean') {
|
|
6
|
+
return value;
|
|
7
|
+
} else if (typeof value === 'string') {
|
|
8
|
+
|
|
9
|
+
if (value.toLowerCase() === "on") return true;
|
|
10
|
+
if (value.toLowerCase() === "off") return false;
|
|
11
|
+
|
|
12
|
+
if (value.toLowerCase() === "active") return true;
|
|
13
|
+
if (value.toLowerCase() === "inactive") return false;
|
|
14
|
+
|
|
15
|
+
if (value.toLowerCase() === "open") return true;
|
|
16
|
+
if (value.toLowerCase() === "closed") return false;
|
|
17
|
+
if (value.toLowerCase() === "close") return false;
|
|
18
|
+
|
|
19
|
+
if (value.toLowerCase() === "1") return true;
|
|
20
|
+
if (value.toLowerCase() === "0") return false;
|
|
21
|
+
|
|
22
|
+
if (value.toLowerCase() === "true") return true;
|
|
23
|
+
if (value.toLowerCase() === "false") return false;
|
|
24
|
+
|
|
25
|
+
} else if (typeof value === 'number') {
|
|
26
|
+
// Is it formated as a decimal number?
|
|
27
|
+
if (decimal.test(value)) {
|
|
28
|
+
res = parseFloat(value) != 0;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
res = value.toLowerCase() === "true";
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports.fetchFromObject = function fetchFromObject(_msg, _payloadPropName) {
|
|
38
|
+
// The output cannot be an oblect. In case, return undefined.
|
|
39
|
+
var _index = _payloadPropName.indexOf('.')
|
|
40
|
+
if (_index > -1) {
|
|
41
|
+
return fetchFromObject(_msg[_payloadPropName.substring(0, _index)], _payloadPropName.substr(_index + 1));
|
|
42
|
+
}
|
|
43
|
+
if (typeof _msg[_payloadPropName] === "object") return undefined;
|
|
44
|
+
return _msg[_payloadPropName];
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-boolean-logic-ultimate",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant
|
|
3
|
+
"version": "1.0.56",
|
|
4
|
+
"description": "A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant values.",
|
|
5
5
|
"author": "Supergiovane (https://github.com/Supergiovane)",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"fs": "0.0.1-security",
|