node-red-contrib-boolean-logic-ultimate 1.1.22 → 1.1.24

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,14 @@
3
3
 
4
4
  # CHANGELOG
5
5
 
6
+ <p>
7
+ <b>Version 1.1.24</b> January 2025<br/>
8
+ - Translator node. added js evaluation of the values. For example "{{value>=50}}:true".</br>
9
+ </p>
10
+ <p>
11
+ <b>Version 1.1.23</b> December 2024<br/>
12
+ - Math node. fixed multiply by zero issue.</br>
13
+ </p>
6
14
  <p>
7
15
  <b>Version 1.1.22</b> November 2024<br/>
8
16
  - Kalman Filter node: added filter's reset by issuing meg.reset=true.</br>
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  ![Logo](img/logo.png)
2
-
3
2
  [![NPM version][npm-version-image]][npm-url]
4
3
  [![NPM downloads per month][npm-downloads-month-image]][npm-url]
5
4
  [![NPM downloads total][npm-downloads-total-image]][npm-url]
@@ -20,52 +19,25 @@ A set of Node-RED enhanced boolean logic and utility nodes, with persistent valu
20
19
  <br/>
21
20
  <br/>
22
21
 
23
- ### HOME ASSISTANT COMPATIBLES INPUT VALUES
22
+ # TRANSLATOR NODE
24
23
 
25
24
  Other than true/false, all nodes accepts [Homeassistant](https://www.home-assistant.io) output strings.
26
25
 
27
26
  You can **even add your own input translation word list**, thanks to the translator-config node.
28
27
 
29
- <br/>
30
- <br/>
31
-
32
- # BOOLEAN LOGIC
33
-
34
- <img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/bl1.png' width='60%'>
35
-
36
- <details><summary>CLICK HERE, copy and paste it into your flow</summary>
37
- <code>
38
- [{"id":"1a90a718.5c0409","type":"BooleanLogicUltimate","z":"adb2ee5c.0bf6e","name":"","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","x":380,"y":160,"wires":[["5f9fbfcc.d2c34"],[],[]]},{"id":"81ef6fec.5d413","type":"inject","z":"adb2ee5c.0bf6e","name":"Night","topic":"Dark","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["1a90a718.5c0409"]]},{"id":"e0d5d620.966478","type":"inject","z":"adb2ee5c.0bf6e","name":"Daylight","topic":"Dark","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["1a90a718.5c0409"]]},{"id":"1c2f8e73.2c22ba","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect true","topic":"Motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["1a90a718.5c0409"]]},{"id":"5f9fbfcc.d2c34","type":"debug","z":"adb2ee5c.0bf6e","name":"Garden Light","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":580,"y":160,"wires":[]},{"id":"201baa3d.7c63ae","type":"inject","z":"adb2ee5c.0bf6e","name":"Motion detect false","topic":"Motion","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["1a90a718.5c0409"]]},{"id":"b65f4ff4.bfe2c8","type":"comment","z":"adb2ee5c.0bf6e","name":"Motion sensor turns on lights, when it's dark. The light turns off itself at day","info":"","x":290,"y":100,"wires":[]}]
39
- </code>
40
- </details>
41
-
42
- <img src='https://raw.githubusercontent.com/Supergiovane/node-red-contrib-boolean-logic-ultimate/master/img/bl2.png' width='60%'>
43
-
44
- <details><summary>CLICK HERE, copy and paste it into your flow</summary>
45
- <code>
46
- [{"id":"53a10a7a.cf1894","type":"BooleanLogicUltimate","z":"a76c6a12.37379","name":"","filtertrue":"onlytrue","persist":true,"sInitializeWith":"true","triggertopic":"Pushbutton","outputtriggeredby":"onlyonetopic","inputCount":2,"topic":"result","x":340,"y":220,"wires":[["cd9244ea.471b78"],[],[]]},{"id":"9318320b.670af8","type":"inject","z":"a76c6a12.37379","name":"","topic":"Pushbutton","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":220,"wires":[["53a10a7a.cf1894"]]},{"id":"20a981b9.552b4e","type":"inject","z":"a76c6a12.37379","name":"","topic":"IsNight","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":320,"wires":[["53a10a7a.cf1894"]]},{"id":"da0dff55.d7888","type":"inject","z":"a76c6a12.37379","name":"","topic":"IsNight","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":360,"wires":[["53a10a7a.cf1894"]]},{"id":"7129d101.1fb7d8","type":"comment","z":"a76c6a12.37379","name":"Pushbutton to switch on light stairs, only if it's night.","info":"","x":210,"y":180,"wires":[]},{"id":"cd9244ea.471b78","type":"debug","z":"a76c6a12.37379","name":"Temporized Stairs Lightbulb","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":580,"y":220,"wires":[]},{"id":"ad5a62a1.7ad81","type":"comment","z":"a76c6a12.37379","name":"Brightness sensor","info":"","x":110,"y":280,"wires":[]}]
47
- </code>
48
- </details>
49
-
50
- The node performs Boolean logic on the incoming payloads.<br/>
51
-
52
- The node expects a fixed number of topics (configured in the settings) on which it will operate. It will only output a value
53
-
54
- when it has seen the expected number of topics. If it ever sees more than the configured number of topics it will log a message then reset its state and start over.<br/>
55
-
56
- The input message is preserved and passed to the output, changing only the topic and the payload.
28
+ The translator node can translate an input payload, to a true/false boolean values.<br />
57
29
 
58
- The node performs some checks on the incoming boolean payloads and outputs all results at the same time, as follow:<br/>
30
+ Each row in the text box, represents a translation command. <br/>
59
31
 
60
- - Output "AND": true or false<br/>
61
- - Output "OR": true or false<br/>
62
- - Output "XOR": true or false<br/>
32
+ There are some default translation's rows, to make the *boolean-logic-ultimate* nodes compatible with Homeassistant as default. <br/>
63
33
 
64
- If you need ***"NAND"*** or ***"NOR"*** gate, just put an **InvertUltimate** node respectively after the "AND" or "OR" output.
34
+ You can add your own translation row.<br/>
65
35
 
66
- 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/>
36
+ | | Description |
37
+ | --------- | ---------------------------------------------------------------------------------------------------- |
38
+ | Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code>. You can also use an expressions to be evaluated, like this <code>{{value>=50}}:true</code> and <code>{{value<50}}:false</code>. In this case, the tranlsator will evaluate (javascript eval) the expression and, if true, returns the choosen value. |
67
39
 
68
- You can also set the default values of the topic inputs.<br/>
40
+ ![alt text](image.png)
69
41
 
70
42
  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/>
71
43
 
@@ -114,11 +86,8 @@ The interrupt flows is able to stop the input messages to exiting the node.
114
86
  **INPUT MSG WITH "TRIGGER" TOPIC**
115
87
 
116
88
  Pass <code>msg.payload = true</code> to allow messages to pass through</br>
117
-
118
89
  Pass <code>msg.payload = false</code> to prevent messages from passing through</br>
119
-
120
90
  Pass <code>msg.play = true</code> from a message having the "trigger" topic, to replay the last stored message</br>
121
-
122
91
  Pass <code>msg.reset = true</code> from a message having the "trigger" topic, to clear the last stored message</br>
123
92
 
124
93
  <code>
@@ -516,8 +485,6 @@ Copy and paste it into your flow
516
485
 
517
486
  Please refer to [this](https://github.com/wouterbulten/kalmanjs) link, on how it works.
518
487
 
519
-
520
-
521
488
  ![image.png](/img/image.png)
522
489
 
523
490
  | Property | Description |
@@ -531,6 +498,7 @@ Please refer to [this](https://github.com/wouterbulten/kalmanjs) link, on how it
531
498
  ### Inputs
532
499
 
533
500
  : reset (any) : by passing msg.reset, the Kalman filter will be reset.
501
+
534
502
  : payload (number) : the payload containing the number. If you've changed the incoming evaluation property in the ***Input*** field, the number to be evaluated must be put in such message's property, instead of the *payload* property.
535
503
 
536
504
  <br/>
@@ -72,10 +72,8 @@ module.exports = function (RED) {
72
72
 
73
73
  let moltiplicazione = 1;
74
74
  node.topics.forEach((item) => {
75
- if (item.val !== 0) {
76
- moltiplicazione *= item.val;
77
- ++quantita;
78
- }
75
+ moltiplicazione *= item.val;
76
+ ++quantita;
79
77
  });
80
78
  msg.payload = moltiplicazione; // Sum
81
79
  msg.average = moltiplicazione / quantita; // Average
@@ -54,7 +54,7 @@ You can add your own translation row.<br/>
54
54
 
55
55
  |Property|Description|
56
56
  |--|--|
57
- | Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code> |
57
+ | Translate | Add, delete or edit your own translation command. The row's translation command must be **input string:true(or false)**. For example: <code>open:true</code> <code>closed:false</code>. You can also use an expressions to be evaluated, like this <code>{{value>=50}}:true</code> and <code>{{value<50}}:false</code>. In this case, the tranlsator will evaluate (javascript eval) the expression and, if true, returns the choosen value. |
58
58
 
59
59
  <br/>
60
60
 
@@ -7,17 +7,26 @@ module.exports.ToBoolean = function ToBoolean(value, _configTranslationNode) {
7
7
  } else if (typeof value === "string") {
8
8
  try {
9
9
  let translationTable = [];
10
+ value = value.toLowerCase();
10
11
  if (_configTranslationNode === null) {
11
12
  translationTable = DEFAULTTRANSLATIONINPUT.split("\n");
12
13
  } else {
13
14
  translationTable = _configTranslationNode.commandText.split("\n");
14
15
  }
15
16
  for (let index = 0; index < translationTable.length; index++) {
16
- let inputPayloadToBeTranslated = translationTable[index].split(":")[0];
17
- //let outputBoolean = Boolean(translationTable[index].split(":")[1]);
18
- if (
19
- value.toLowerCase() === inputPayloadToBeTranslated.toLowerCase() &&
20
- inputPayloadToBeTranslated.toLowerCase() !== ""
17
+ // HA Style evaluation in the format "{{value>=0}}"
18
+ let inputPayloadToBeTranslated = translationTable[index].toLowerCase().split(":")[0];
19
+ if (inputPayloadToBeTranslated.indexOf("{{") > -1 && inputPayloadToBeTranslated.indexOf("}}") > -1) {
20
+ // Eval content of the brackets {{value<=0}}, HA style
21
+ inputPayloadToBeTranslated = inputPayloadToBeTranslated.replace("{{", "").replace("}}", "").replace("value", value); // Set the word value to real value
22
+ if (eval(inputPayloadToBeTranslated)) {
23
+ return translationTable[index].split(":")[1] === "true"
24
+ ? true
25
+ : false;
26
+ } // Eval the operation
27
+ } else if (
28
+ // Normal string value
29
+ value === inputPayloadToBeTranslated
21
30
  ) {
22
31
  return translationTable[index].split(":")[1] === "true"
23
32
  ? true
package/image.png ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-boolean-logic-ultimate",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
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 values.",
5
5
  "author": "Supergiovane (https://github.com/Supergiovane)",
6
6
  "dependencies": {