Dirk Alders 6b28a8b302 Initial nodered configuration | vor 1 Jahr | |
---|---|---|
.. | ||
boolean-logic | vor 1 Jahr | |
LICENSE | vor 1 Jahr | |
README.md | vor 1 Jahr | |
package.json | vor 1 Jahr |
Node-RED nodes to easily perform boolean logic.
Node-RED does not support multiple inputs on nodes, and it has been discussed at length in this thread. The TL;DR - as I understand it - is that the developers of NR argue that multiple inputs makes it too complex for users without a background in electrical engineering and that it is preferred users of NR instead use other means to create the desired logic (i.e. write Javascript in function-nodes).
I really needed a simple and reusable way to perform boolean logic on multiple topics without the need to write the same code over and over.
Could this be solved using a subflow? No, function-node within a subflow cannot be configured on an instance basis which is required as the logic must know how many inputs it is expecting when performing operations such as A || B
or A && (B || C)
. Yes, that could be hard coded, but then it would not be reusable. Also, a subflow cannot use the status indicator which is a great help to the user.
What I came up with are the following nodes.
msg.payload
on any number of topics.msg.payload
, e.g. true -> false.All nodes attempts to convert the incoming msg.payload
to a boolean value according to these rules:
This node must be configured with the expected number of topics. It will not output a value until it has received the configured number of topics. Also, if it receives more than the configured number of topics it will reset (but not output a value) and wait until it once again sees the configured number of topics.