node-red-contrib-boolean-logic-ultimate 1.0.51 → 1.0.52

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 CHANGED
@@ -3,6 +3,11 @@
3
3
 
4
4
  # CHANGELOG
5
5
 
6
+ <p>
7
+ <b>Version 1.0.52</b> Mai 2022<br/>
8
+ - NEW: Railway Switcher Ultimate: new node to switch the input message to an output pin (https://youtu.be/1SjYE7d04u4).</br>
9
+ - Updated README with samples of Railway Switch node.
10
+ </p>
6
11
  <p>
7
12
  <b>Version 1.0.51</b> February 2022<br/>
8
13
  - Blinker Ultimate: fixed minor problem with an orphan timer.</br>
package/README.md CHANGED
@@ -113,6 +113,8 @@ Resets all inputs to undefined.
113
113
 
114
114
  # INTERRUPT FLOWS ULTIMATE
115
115
 
116
+ The interrupt flows is able to stop the input messages to exiting the node.
117
+
116
118
  **Trigger by topic**
117
119
 
118
120
  Whenever the node receives a payload = false from this topic,it stops output messages to the flow.<br/>
@@ -125,7 +127,7 @@ The node tries to convert any arbitrary input value to a valid boolean value. It
125
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>
126
128
  </br>
127
129
 
128
- **INPUT MSG HWITH "TRIGGER" TOPIC**
130
+ **INPUT MSG WITH "TRIGGER" TOPIC**
129
131
 
130
132
  Pass <code>msg.payload = true</code> to allow messages to pass through</br>
131
133
  Pass <code>msg.payload = false</code> to prevent messages from passing through</br>
@@ -370,6 +372,43 @@ The pourpose of this node is to toggle between true/false the payload of every i
370
372
 
371
373
  Any message that arrives on input, will be passwd through to the output with the payload toggled between true and false.
372
374
 
375
+ <br/>
376
+ <br/>
377
+ <br/>
378
+ <br/>
379
+ <br/>
380
+
381
+ # RAILWAY SWITCH ULTIMATE
382
+
383
+ The railway switcher, switches the input msg flow to one ot the two output pins (upper or lower).
384
+
385
+ <img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/railroadSwitchScambio.png' width='80%'>
386
+
387
+ **Switcher topic**
388
+
389
+ Whenever the node receives a payload from this **topic**, it switches the input messages to an output PIN.<br/>
390
+
391
+ **Then**
392
+ This property, allow you to auto toggle the selected start state after some time.</br>
393
+ </br>
394
+
395
+ **INPUT MSG WITH "TRIGGER" TOPIC**
396
+
397
+ Pass <code>msg.payload = false</code> switches the msg input to the UPPER PIN</br>
398
+ Pass <code>msg.payload = true</code> switches the msg input to the LOWER PIN</br>
399
+
400
+ </br>
401
+
402
+ See the example below.<br/>
403
+
404
+ <img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/railwaySwitch.png' width='60%'>
405
+
406
+ Copy and paste it into your flow
407
+ ```javascript
408
+ [{"id":"a6993d5187f05c0a","type":"RailwaySwitchUltimate","z":"e5b506b72b42922e","name":"Railway Switch","triggertopic":"trigger","initializewith":"0","autoToggle":"0","x":490,"y":180,"wires":[["51e7df8da0bd8d67"],["7f33b14e12c91744"]]},{"id":"2e3014226290f678","type":"InjectUltimate","z":"e5b506b72b42922e","name":"Sample message","topic":"Train","curVal":true,"x":180,"y":140,"wires":[["a6993d5187f05c0a"],[],[]]},{"id":"f6f80cd77a65073e","type":"InjectUltimate","z":"e5b506b72b42922e","name":"Railway switcher","topic":"trigger","curVal":true,"x":180,"y":220,"wires":[[],[],["a6993d5187f05c0a"]]},{"id":"51e7df8da0bd8d67","type":"debug","z":"e5b506b72b42922e","name":"Upper railway","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"topic","statusType":"msg","x":720,"y":140,"wires":[]},{"id":"7f33b14e12c91744","type":"debug","z":"e5b506b72b42922e","name":"Lower railway","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"topic","statusType":"msg","x":720,"y":220,"wires":[]},{"id":"8716120e94a7b6ee","type":"comment","z":"e5b506b72b42922e","name":"Switch between railways","info":"","x":190,"y":80,"wires":[]}]
409
+ ```
410
+
411
+
373
412
 
374
413
 
375
414
  [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
@@ -0,0 +1,92 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('RailwaySwitchUltimate', {
3
+ category: 'boolean logic ultimate',
4
+ color: '#ff8080',
5
+ defaults: {
6
+ name: { value: "Railway Switch" },
7
+ triggertopic: { value: "trigger" },
8
+ initializewith: { value: "0" },
9
+ autoToggle: { value: "0" }
10
+ },
11
+ inputs: 1,
12
+ outputs: 2,
13
+ outputLabels: function (i) {
14
+ var ret = "";
15
+ switch (i) {
16
+ case 0:
17
+ return "Upper PIN";
18
+ break;
19
+ case 1:
20
+ return "Lower PIN";
21
+ break;
22
+ default:
23
+ break;
24
+ }
25
+ },
26
+ icon: "font-awesome/fa-train",
27
+ label:
28
+ function () {
29
+ return (this.name || "Switch") + " (" + this.triggertopic + ")";
30
+ },
31
+ paletteLabel: function () {
32
+ return "RailwaySwitchUltimate";
33
+ }
34
+ });
35
+ </script>
36
+
37
+ <script type="text/x-red" data-template-name="RailwaySwitchUltimate">
38
+ <div class="form-row">
39
+ <b>Railway Switch Ultimate</b>&nbsp&nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate"><u>Help online</u></a></span>
40
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/1SjYE7d04u4"><u>Youtube Sample</u></a></span>
41
+ <br/>
42
+ <br/>
43
+ </div>
44
+ <div class="form-row">
45
+ <label for="node-input-name"><i class="icon-tag"></i> Name</label>
46
+ <input type="text" id="node-input-name" placeholder="Name">
47
+ </div>
48
+
49
+ <div class="form-row">
50
+ <label for="node-input-triggertopic"><i class="icon-tag"></i> Switcher topic</label>
51
+ <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
+ </div>
57
+
58
+ <div class="form-row">
59
+ <label style="width:160px" for="node-input-initializewith"><i class="fa fa-home"></i> At node-red start</label>
60
+ <select type="text" id="node-input-initializewith" placeholder="" style="width:250px">
61
+ <option value="0">Flow messages to the upper PIN</option>
62
+ <option value="1">Flow messages to the lower PIN</option>
63
+ </select>
64
+ </div>
65
+ <div class="form-row">
66
+ <label style="width:160px" for="node-input-autoToggle"><i class="fa fa-hourglass-o"></i> Then</label>
67
+ <select type="text" id="node-input-autoToggle" placeholder="" style="width:250px">
68
+ <option value="0">Nothing</option>
69
+ <option value="10">Toggle above option after 10 seconds</option>
70
+ <option value="20">Toggle above option after 20 seconds</option>
71
+ <option value="30">Toggle above option after 30 seconds</option>
72
+ <option value="40">Toggle above option after 40 seconds</option>
73
+ <option value="50">Toggle above option after 50 seconds</option>
74
+ <option value="60">Toggle above option after 60 seconds</option>
75
+ <option value="90">Toggle above option after 90 seconds</option>
76
+ <option value="120">Toggle above option after 120 seconds</option>
77
+ </select>
78
+ </div>
79
+ </script>
80
+
81
+ <script type="text/x-red" data-help-name="RailwaySwitchUltimate">
82
+ <p>
83
+ SEE THE README FOR HELP CONFIGURING THE NODE
84
+ </p>
85
+
86
+ <p>
87
+ <a href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate" target="_blank">Click here to learn how to configure the node.</a>
88
+ </p>
89
+
90
+ <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a>
91
+
92
+ </script>
@@ -0,0 +1,103 @@
1
+ module.exports = function (RED) {
2
+ function RailwaySwitchUltimate(config) {
3
+ RED.nodes.createNode(this, config);
4
+ this.config = config;
5
+ var node = this;
6
+ node.currentMsg = {}; // Stores current payload
7
+ node.sTriggerTopic = node.config.triggertopic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '') || "trigger"; // Topic controlling the iRailway
8
+ node.iRailway = Number(node.config.initializewith); // Railway selector
9
+ node.autoToggle = config.autoToggle === undefined ? 0 : parseInt(config.autoToggle); // Auto toggle the selected "initializewith" after a while (useful for homekit bridged, that sends junk after start)
10
+ node.timerAutoToggle = null;
11
+
12
+ function setNodeStatus({ fill, shape, text }) {
13
+ let dDate = new Date();
14
+ node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
15
+ }
16
+
17
+ node.alignStatus = () => {
18
+ let sAutoToggle = node.autoToggle > 0 ? " (Autotoggle in " + node.autoToggle + "s)" : "";
19
+ if (node.iRailway === 0) {
20
+ setNodeStatus({ fill: "green", shape: "dot", text: "-> UPPER PIN" + sAutoToggle });
21
+ } else {
22
+ setNodeStatus({ fill: "blue", shape: "dot", text: "-> LOWER PIN" + sAutoToggle });
23
+ }
24
+ }
25
+
26
+ if (node.autoToggle > 0) {
27
+ node.timerAutoToggle = setTimeout(() => {
28
+ node.autoToggle = 0;
29
+ node.iRailway === 0 ? node.iRailway = 1 : node.iRailway = 0;
30
+ node.alignStatus();
31
+ }, node.autoToggle * 1000);
32
+ }
33
+
34
+ node.alignStatus();
35
+
36
+ this.on('input', function (msg) {
37
+ var sIncomingTopic = "";
38
+ if (msg.hasOwnProperty("topic")) {
39
+ // 06/11/2019
40
+ if (!msg.hasOwnProperty("topic") || msg.topic === undefined) msg.topic = "NoTopicReceived";
41
+ sIncomingTopic = msg.topic.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, ''); // Cut unwanted Characters
42
+ if (sIncomingTopic === node.sTriggerTopic) {
43
+
44
+ // 15/11/2021 inform user about undefined topic or payload
45
+ if (!msg.hasOwnProperty("payload") || msg.payload === undefined || msg.payload === null) {
46
+ setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
47
+ return;
48
+ }
49
+
50
+ msg.payload = ToBoolean(msg.payload); // 15/11/2021 Convert input to boolean.
51
+
52
+ // 28/01/2022 Stop autotoggle
53
+ if (node.timerAutoToggle !== null) clearInterval(node.timerAutoToggle);
54
+
55
+ if (msg.payload === false) node.iRailway = 0;
56
+ if (msg.payload === true) node.iRailway = 1;
57
+ if (node.iRailway === 0) {
58
+ setNodeStatus({ fill: "green", shape: "dot", text: "-> UPPER PIN" });
59
+ } else {
60
+ setNodeStatus({ fill: "blue", shape: "dot", text: "-> LOWER PIN" });
61
+ }
62
+ return; // DONT'S SEND THIS MESSAGE
63
+ }
64
+ }
65
+ node.currentMsg = RED.util.cloneMessage(msg);
66
+ if (node.iRailway === 0) {
67
+ node.send([msg, null]);
68
+ } else {
69
+ node.send([null, msg]);
70
+ }
71
+ });
72
+
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
+ }
100
+
101
+
102
+ RED.nodes.registerType("RailwaySwitchUltimate", RailwaySwitchUltimate);
103
+ }
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.0.51",
3
+ "version": "1.0.52",
4
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 ON and OFF values.",
5
5
  "author": "Supergiovane (https://github.com/Supergiovane)",
6
6
  "dependencies": {
@@ -31,7 +31,8 @@
31
31
  "StatusUltimate": "boolean-logic-ultimate/StatusUltimate.js",
32
32
  "ImpulseUltimate": "boolean-logic-ultimate/ImpulseUltimate.js",
33
33
  "SumUltimate": "boolean-logic-ultimate/SumUltimate.js",
34
- "toggleUltimate": "boolean-logic-ultimate/toggleUltimate.js"
34
+ "toggleUltimate": "boolean-logic-ultimate/toggleUltimate.js",
35
+ "RailwaySwitchUltimate": "boolean-logic-ultimate/RailwaySwitchUltimate.js"
35
36
  }
36
37
  }
37
- }
38
+ }