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

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
@@ -1,6 +1,21 @@
1
1
  # node-red-contrib-boolean-logic-ultimate
2
2
  [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square)](https://www.paypal.me/techtoday)
3
3
 
4
+ # CHANGELOG
5
+
6
+ <p>
7
+ <b>Version 1.0.51</b> February 2022<br/>
8
+ - Blinker Ultimate: fixed minor problem with an orphan timer.</br>
9
+ - Better scoping of some vars, to leave the memory garbace collector to get rid of unused references.</br>
10
+ </p>
11
+ <p>
12
+ <b>Version 1.0.50</b> February 2022<br/>
13
+ - NEW: Added Youtube example for each node. You can find the link in the config window of each one and hede the playlist https://youtube.com/playlist?list=PL9Yh1bjbLAYoRH4IyQB7EL5srHAihiKpy.</br>
14
+ </p>
15
+ <p>
16
+ <b>Version 1.0.48</b> February 2022<br/>
17
+ - NEW: TOGGLE node: Simple toggle node.</br>
18
+ </p>
4
19
  <p>
5
20
  <b>Version 1.0.48</b> February 2022<br/>
6
21
  - NEW: SUM node: this new node makes sum, average and measurement count.</br>
package/README.md CHANGED
@@ -8,12 +8,9 @@
8
8
  [![MIT License][license-image]][license-url]
9
9
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
10
10
  [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square)](https://www.paypal.me/techtoday)
11
- [![Facebook][facebook-image]][facebook-url]
11
+ [![youtube][youtube-image]][youtube-url]
12
12
 
13
- A set of Node-RED enhanced boolean logic, with persisten values after reboot and more.
14
-
15
- > Wellcome! First of all thank you for your interest in my nodes. This is a set of logic nodes, to overcome the simplicity of the default node-red boolean logic nodes.
16
- Hope you enjoy that and if you're in trouble, please ask!
13
+ A set of Node-RED enhanced boolean logic and utility nodes, with persistent values after reboot. Compatible also with Homeassistant ON and OFF values.
17
14
 
18
15
  <br/>
19
16
  <br/>
@@ -358,11 +355,28 @@ resets the values to zero.
358
355
  }
359
356
  </pre>
360
357
 
358
+ br/>
359
+ <br/>
360
+ <br/>
361
+ <br/>
362
+ <br/>
363
+
364
+ # TOGGLE ULTIMATE
365
+
366
+ The pourpose of this node is to toggle between true/false the payload of every incoming message.<br />
367
+
368
+
369
+ **INPUT**<br />
370
+
371
+ Any message that arrives on input, will be passwd through to the output with the payload toggled between true and false.
372
+
373
+
374
+
361
375
  [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
362
376
  [license-url]: https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/LICENSE
363
377
  [npm-url]: https://npmjs.org/package/node-red-contrib-boolean-logic-ultimate
364
378
  [npm-version-image]: https://img.shields.io/npm/v/node-red-contrib-boolean-logic-ultimate.svg
365
379
  [npm-downloads-month-image]: https://img.shields.io/npm/dm/node-red-contrib-boolean-logic-ultimate.svg
366
380
  [npm-downloads-total-image]: https://img.shields.io/npm/dt/node-red-contrib-boolean-logic-ultimate.svg
367
- [facebook-image]: https://img.shields.io/badge/Visit%20me-Facebook-blue
368
- [facebook-url]: https://www.facebook.com/supergiovaneDev
381
+ [youtube-image]: https://img.shields.io/badge/Visit%20me-youtube-red
382
+ [youtube-url]: https://youtube.com/playlist?list=PL9Yh1bjbLAYoRH4IyQB7EL5srHAihiKpy
@@ -37,7 +37,8 @@
37
37
  <script type="text/x-red" data-template-name="BlinkerUltimate">
38
38
  <div class="form-row">
39
39
  <b>Blinker 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
- <br/>
40
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/HtMoutMFB6A"><u>Youtube Sample</u></a></span>
41
+ <br/>
41
42
  <br/>
42
43
  </div>
43
44
  <div class="form-row">
@@ -12,12 +12,13 @@ module.exports = function (RED) {
12
12
  node.stopbehaviorPIN2 = node.stopbehaviorPIN2 == "0" ? false : true;
13
13
 
14
14
  function setNodeStatus({ fill, shape, text }) {
15
- var dDate = new Date();
15
+ let dDate = new Date();
16
16
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
17
17
  }
18
18
 
19
19
  // 12/04/2021 Autostart blinker?
20
20
  if (config.initializewith !== undefined && config.initializewith === "1") {
21
+ if (node.tBlinker !== null) clearInterval(node.tBlinker);
21
22
  node.tBlinker = setInterval(handleTimer, node.blinkfrequency); // Start the timer that handles the queue of telegrams
22
23
  node.isBlinking = true;
23
24
  setNodeStatus({ fill: "green", shape: "dot", text: "-> Autostarted" });
@@ -68,9 +69,9 @@ module.exports = function (RED) {
68
69
 
69
70
 
70
71
  function ToBoolean(value) {
71
- var res = false;
72
- var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
73
-
72
+ let res = false;
73
+ let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
74
+
74
75
  if (typeof value === 'boolean') {
75
76
  res = value;
76
77
  }
@@ -82,8 +83,7 @@ module.exports = function (RED) {
82
83
 
83
84
  // Is it formated as a decimal number?
84
85
  if (decimal.test(value)) {
85
- var v = parseFloat(value);
86
- res = v != 0;
86
+ res = parseFloat(value) != 0;
87
87
  }
88
88
  else {
89
89
  res = value.toLowerCase() === "true";
@@ -39,7 +39,6 @@
39
39
  inputs: 1,
40
40
  outputs: 3,
41
41
  outputLabels: function (i) {
42
- var ret = "";
43
42
  switch (i) {
44
43
  case 0:
45
44
  return "AND";
@@ -118,6 +117,7 @@
118
117
  <script type="text/x-red" data-template-name="BooleanLogicUltimate">
119
118
  <div class="form-row">
120
119
  <b>Boolean Logic 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>
120
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/6En2WiWKsXM"><u>Youtube Sample</u></a></span>
121
121
  <br/>
122
122
  <br/>
123
123
  </div>
@@ -17,7 +17,7 @@ module.exports = function (RED) {
17
17
  node.inputMessage = {}; // 26/01/2022 input message is stored here.
18
18
 
19
19
  function setNodeStatus({ fill, shape, text }) {
20
- var dDate = new Date();
20
+ let dDate = new Date();
21
21
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
22
22
  }
23
23
 
@@ -221,7 +221,7 @@ module.exports = function (RED) {
221
221
  for (let index = 0; index < nTotalDummyToCreate; index++) {
222
222
  node.jSonStates["dummy" + index] = node.sInitializeWith === "false" ? false : true;
223
223
  }
224
- setTimeout(() => { setNodeStatus({ fill: "green", shape: "ring", text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith }); }, 4000)
224
+ let t = setTimeout(() => { setNodeStatus({ fill: "green", shape: "ring", text: "Initialized " + nTotalDummyToCreate + " undefined inputs with " + node.sInitializeWith }); }, 4000)
225
225
  }
226
226
  }
227
227
  }
@@ -278,8 +278,8 @@ module.exports = function (RED) {
278
278
  }
279
279
 
280
280
  function ToBoolean(value) {
281
- var res = false;
282
- var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
281
+ let res = false;
282
+ let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
283
283
 
284
284
  if (typeof value === 'boolean') {
285
285
  res = value;
@@ -291,8 +291,7 @@ module.exports = function (RED) {
291
291
 
292
292
  // Is it formated as a decimal number?
293
293
  if (decimal.test(value)) {
294
- var v = parseFloat(value);
295
- res = v != 0;
294
+ res = parseFloat(value) != 0;
296
295
  }
297
296
  else {
298
297
  res = value.toLowerCase() === "true";
@@ -36,6 +36,7 @@
36
36
  <script type="text/x-red" data-template-name="FilterUltimate">
37
37
  <div class="form-row">
38
38
  <b>Filter 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>
39
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/DXfpXRM-LJA"><u>Youtube Sample</u></a></span>
39
40
  <br/>
40
41
  <br/>
41
42
  </div>
@@ -5,7 +5,7 @@ module.exports = function (RED) {
5
5
  var node = this;
6
6
 
7
7
  function setNodeStatus({ fill, shape, text }) {
8
- var dDate = new Date();
8
+ let dDate = new Date();
9
9
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
10
10
  }
11
11
 
@@ -47,8 +47,8 @@ module.exports = function (RED) {
47
47
 
48
48
 
49
49
  function ToBoolean(value) {
50
- var res = false;
51
- var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
50
+ let res = false;
51
+ let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
52
52
 
53
53
  if (typeof value === 'boolean') {
54
54
  res = value;
@@ -60,8 +60,7 @@ module.exports = function (RED) {
60
60
 
61
61
  // Is it formated as a decimal number?
62
62
  if (decimal.test(value)) {
63
- var v = parseFloat(value);
64
- res = v != 0;
63
+ res = parseFloat(value) != 0;
65
64
  }
66
65
  else {
67
66
  res = value.toLowerCase() === "true";
@@ -50,7 +50,8 @@
50
50
  <script type="text/x-red" data-template-name="ImpulseUltimate">
51
51
  <div class="form-row">
52
52
  <b>Impulse 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>
53
- <br/>
53
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/PdLEWtKsNv8"><u>Youtube Sample</u></a></span>
54
+ <br/>
54
55
  <br/>
55
56
  </div>
56
57
  <div class="form-row">
@@ -12,7 +12,7 @@ module.exports = function (RED) {
12
12
  node.isPlaying = false;
13
13
 
14
14
  node.setNodeStatus = ({ fill, shape, text }) => {
15
- var dDate = new Date();
15
+ let dDate = new Date();
16
16
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
17
17
  }
18
18
  async function delay(ms) {
@@ -62,8 +62,9 @@
62
62
  <script type="text/x-red" data-template-name="InjectUltimate">
63
63
  <div class="form-row">
64
64
  <b>Inject 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>
65
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/sYc6L5QQrTw"><u>Youtube Sample</u></a></span>
65
66
  <br/>
66
- <br/>
67
+ <br/>
67
68
  </div>
68
69
  <div class="form-row">
69
70
  <label for="node-input-name"><i class="icon-tag"></i> Name</label>
@@ -26,15 +26,15 @@ module.exports = function (RED) {
26
26
  // 29/08/2020 triggered by button press
27
27
  node.buttonpressed = () => {
28
28
  setNodeStatus({ fill: "green", shape: "dot", text: "Pin1:true, Pin2:false, Pin3:" + node.curVal.toString() + " (next " + (!node.curVal).toString() + ")" });
29
- var msgTrue = { payload: true, topic: node.topic };
30
- var msgFalse = { payload: false, topic: node.topic };
31
- var msgToggled = { payload: node.curVal, topic: node.topic };
29
+ let msgTrue = { payload: true, topic: node.topic };
30
+ let msgFalse = { payload: false, topic: node.topic };
31
+ let msgToggled = { payload: node.curVal, topic: node.topic };
32
32
  node.curVal = !node.curVal;
33
33
  node.send([msgTrue, msgFalse, msgToggled]);
34
34
  }
35
35
 
36
36
  function setNodeStatus({ fill, shape, text }) {
37
- var dDate = new Date();
37
+ let dDate = new Date();
38
38
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
39
39
  }
40
40
 
@@ -37,6 +37,7 @@
37
37
  <script type="text/x-red" data-template-name="InterruptFlowUltimate">
38
38
  <div class="form-row">
39
39
  <b>Interrupt Flow 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/1T1g0HCeYA8"><u>Youtube Sample</u></a></span>
40
41
  <br/>
41
42
  <br/>
42
43
  </div>
@@ -10,7 +10,7 @@ module.exports = function (RED) {
10
10
  node.timerAutoToggle = null;
11
11
 
12
12
  function setNodeStatus({ fill, shape, text }) {
13
- var dDate = new Date();
13
+ let dDate = new Date();
14
14
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
15
15
  }
16
16
  setNodeStatus({ fill: "green", shape: "ring", text: "-> pass" });
@@ -59,7 +59,7 @@ module.exports = function (RED) {
59
59
  node.currentMsg.isReplay = true;
60
60
  setNodeStatus({ fill: "yellow", shape: "dot", text: "-> replay" });
61
61
  // Restore previous status
62
- setTimeout(() => {
62
+ let t = setTimeout(() => {
63
63
  if (node.bInviaMessaggio) {
64
64
  setNodeStatus({ fill: "green", shape: "dot", text: "-> pass" });
65
65
  } else {
@@ -96,8 +96,8 @@ module.exports = function (RED) {
96
96
 
97
97
 
98
98
  function ToBoolean(value) {
99
- var res = false;
100
- var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
99
+ let res = false;
100
+ let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
101
101
 
102
102
  if (typeof value === 'boolean') {
103
103
  res = value;
@@ -109,8 +109,7 @@ module.exports = function (RED) {
109
109
 
110
110
  // Is it formated as a decimal number?
111
111
  if (decimal.test(value)) {
112
- var v = parseFloat(value);
113
- res = v != 0;
112
+ res = parseFloat(value) != 0;
114
113
  }
115
114
  else {
116
115
  res = value.toLowerCase() === "true";
@@ -23,6 +23,7 @@
23
23
  <script type="text/x-red" data-template-name="InvertUltimate">
24
24
  <div class="form-row">
25
25
  <b>Invert 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>
26
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/A41x8VevZD8"><u>Youtube Sample</u></a></span>
26
27
  <br/>
27
28
  <br/>
28
29
  </div>
@@ -6,7 +6,7 @@ module.exports = function (RED) {
6
6
 
7
7
 
8
8
  function setNodeStatus({ fill, shape, text }) {
9
- var dDate = new Date();
9
+ let dDate = new Date();
10
10
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
11
11
  }
12
12
 
@@ -47,8 +47,8 @@ module.exports = function (RED) {
47
47
 
48
48
 
49
49
  function ToBoolean(value) {
50
- var res = false;
51
- var decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
50
+ let res = false;
51
+ let decimal = /^\s*[+-]{0,1}\s*([\d]+(\.[\d]*)*)\s*$/
52
52
 
53
53
  if (typeof value === 'boolean') {
54
54
  res = value;
@@ -60,8 +60,7 @@ module.exports = function (RED) {
60
60
 
61
61
  // Is it formated as a decimal number?
62
62
  if (decimal.test(value)) {
63
- var v = parseFloat(value);
64
- res = v != 0;
63
+ res = parseFloat(value) != 0;
65
64
  }
66
65
  else {
67
66
  res = value.toLowerCase() === "true";
@@ -36,7 +36,8 @@
36
36
  <script type="text/x-red" data-template-name="SimpleOutputUltimate">
37
37
  <div class="form-row">
38
38
  <b>Simple Output 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>
39
- <br/>
39
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/tCKolVculuw"><u>Youtube Sample</u></a></span>
40
+ <br/>
40
41
  <br/>
41
42
  </div>
42
43
  <div class="form-row">
@@ -18,7 +18,7 @@ module.exports = function(RED) {
18
18
 
19
19
  function setNodeStatus({fill, shape, text})
20
20
  {
21
- var dDate = new Date();
21
+ let dDate = new Date();
22
22
  node.status({fill: fill,shape: shape,text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")"})
23
23
  }
24
24
 
@@ -27,7 +27,8 @@
27
27
  <script type="text/x-red" data-template-name="StatusUltimate">
28
28
  <div class="form-row">
29
29
  <b>Status 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>
30
- <br/>
30
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/m3p06PN3rTI"><u>Youtube Sample</u></a></span>
31
+ <br/>
31
32
  <br/>
32
33
  </div>
33
34
  <div class="form-row">
@@ -5,7 +5,7 @@ module.exports = function (RED) {
5
5
  var node = this;
6
6
 
7
7
  function setNodeStatus({ fill, shape, text }) {
8
- var dDate = new Date();
8
+ let dDate = new Date();
9
9
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
10
10
  }
11
11
 
@@ -27,7 +27,8 @@
27
27
  <script type="text/x-red" data-template-name="SumUltimate">
28
28
  <div class="form-row">
29
29
  <b>Status 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>
30
- <br/>
30
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/jLIbQgmRzuc"><u>Youtube Sample</u></a></span>
31
+ <br/>
31
32
  <br/>
32
33
  </div>
33
34
  <div class="form-row">
@@ -6,7 +6,7 @@ module.exports = function (RED) {
6
6
  this.topics = {};
7
7
 
8
8
  function setNodeStatus({ fill, shape, text }) {
9
- var dDate = new Date();
9
+ let dDate = new Date();
10
10
  node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
11
11
  }
12
12
 
@@ -0,0 +1,64 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('toggleUltimate', {
3
+ category: 'boolean logic ultimate',
4
+ color: '#ff8080',
5
+ defaults: {
6
+ name: {
7
+ value: "Toggle"
8
+ },
9
+ valueToToggle: { value: "true" }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: "serial.png",
14
+ label:
15
+ function () {
16
+ return this.name || "Toggle";
17
+ },
18
+ paletteLabel: function () {
19
+ return "toggleUltimate";
20
+ }
21
+ });
22
+ </script>
23
+
24
+ <script type="text/x-red" data-template-name="toggleUltimate">
25
+ <div class="form-row">
26
+ <b>Toggle 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>
27
+ &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/VijkMBpt_CM"><u>Youtube Sample</u></a></span>
28
+ <br/>
29
+ <br/>
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-input-name"><i class="icon-tag"></i> Name</label>
33
+ <input type="text" id="node-input-name" placeholder="Name">
34
+ </div>
35
+ <div class="form-row">
36
+ <label style="width:160px" for="node-input-valueToToggle"><i class="fa fa-toggle-on"></i> Initial value</label>
37
+ <select type="text" id="node-input-valueToToggle" placeholder="">
38
+ <option value="true">Initialize wiht True</option>
39
+ <option value="false">Initialize with False</option>
40
+ </select>
41
+ </div>
42
+ <!-- <div class="form-row">
43
+ <input type="checkbox" id="node-input-homeAssitantBoolean" style="display:inline-block; width:auto; vertical-align:top;">
44
+ &nbsp;
45
+ <label style="width:85%" for="node-input-homeAssitantBoolean">
46
+ <i class="fa fa-home"></i>&nbsp;Output Home Assistant "on"/"off" instead of true/false
47
+ </label>
48
+ </div> -->
49
+
50
+
51
+ </script>
52
+
53
+ <script type="text/x-red" data-help-name="toggleUltimate">
54
+ <p>
55
+ SEE THE README FOR HELP CONFIGURING THE NODE
56
+ </p>
57
+
58
+ <p>
59
+ <a href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate" target="_blank">Click here to learn how to configure the node.</a>
60
+ </p>
61
+
62
+ <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>
63
+
64
+ </script>
@@ -0,0 +1,70 @@
1
+ module.exports = function (RED) {
2
+ function toggleUltimate(config) {
3
+ RED.nodes.createNode(this, config);
4
+ this.config = config;
5
+ var node = this;
6
+ node.valueToToggle = config.valueToToggle === undefined ? true : ToBoolean(config.valueToToggle);
7
+
8
+ function setNodeStatus({ fill, shape, text }) {
9
+ let dDate = new Date();
10
+ node.status({ fill: fill, shape: shape, text: text + " (" + dDate.getDate() + ", " + dDate.toLocaleTimeString() + ")" })
11
+ }
12
+
13
+ setNodeStatus({ fill: "grey", shape: "dot", text: "Waiting" });
14
+
15
+ this.on('input', function (msg) {
16
+
17
+
18
+ // 15/11/2021 inform user about undefined topic or payload
19
+ if (!msg.hasOwnProperty("payload") || msg.payload === undefined || msg.payload === null) {
20
+ setNodeStatus({ fill: "red", shape: "dot", text: "Received invalid payload from " + msg.topic || "" });
21
+ return;
22
+ }
23
+
24
+ node.valueToToggle = !node.valueToToggle;
25
+
26
+ let msgOUT = RED.util.cloneMessage(msg);
27
+ try {
28
+ msgOUT.payload = node.valueToToggle;
29
+ setNodeStatus({ fill: "green", shape: "dot", text: "(Send) " + msgOUT.payload });
30
+ node.send(msgOUT);
31
+ } catch (error) {
32
+ setNodeStatus({ fill: "red", shape: "dot", text: "Unable to invert the input payload " + bRes });
33
+ }
34
+
35
+ });
36
+
37
+
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
+ }
66
+
67
+
68
+
69
+ RED.nodes.registerType("toggleUltimate", toggleUltimate);
70
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.0.48",
4
- "description": "A set of Node-RED enhanced boolean logic node, flow interruption node, blinker node, invert node, filter node, with persisten values after reboot and more.",
3
+ "version": "1.0.51",
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": {
7
7
  "fs": "0.0.1-security",
@@ -30,7 +30,8 @@
30
30
  "InjectUltimate": "boolean-logic-ultimate/InjectUltimate.js",
31
31
  "StatusUltimate": "boolean-logic-ultimate/StatusUltimate.js",
32
32
  "ImpulseUltimate": "boolean-logic-ultimate/ImpulseUltimate.js",
33
- "SumUltimate": "boolean-logic-ultimate/SumUltimate.js"
33
+ "SumUltimate": "boolean-logic-ultimate/SumUltimate.js",
34
+ "toggleUltimate": "boolean-logic-ultimate/toggleUltimate.js"
34
35
  }
35
36
  }
36
37
  }