I couldn't seem to find any logic gate nodes (AND/OR) that have multiple input pins.
I feel like I have missed something, because I know that NR is extremely powerful and flexible, so I'm guessing there's a way to do something equivalent.
Any tips about this for a noob?
All the best,
Dax.
Node-red doesn't work that way I'm afraid. It is flow-based rather than linear.
As such, you can never guarantee that 2 inputs will arrive at the same time. In fact, each input to a node-red node creates a new invocation of that node.
The thing to do is either use a node that waits for all of the inputs to arrive before it calculates something. Or you can temporarily save intermediate values until you can do a calculation.
If you look at node-red-contrib-bool-gate, for example, it achieves multiple inputs (as many as you like) by using different topics for each input. So if you want an AND gate with three inputs you feed all three inputs into the node and make sure that each one has a topic identifying which input it is.
I have the same problem when I write the ladder logic nodes.
How can a node examine the count of nodes connected to the node input ?
I solve this with the msg.id and count the messages with same msg.id at start. This tells my how many nodes are connected to node input. Later when the system runs, each input message is logical calculated until count is reached.
If msg.id changes, a new calculation are made.
So I can perform AND, OR and XOR operation with multiply connected nodes.
Thanks for your replies, everyone.
I've come across problems a few times that I thought could be solved by using AND/OR gates.
One of them today; I want a way to temporarily disable email alerts via a switch on the dashboard. (A Dashboard latching switch, not the Switch Function.) An AND or OR gate could be used to easily solve this problem.
Perhaps there are other, better ways to do this in NR?
There are gate nodes and even finite state machine nodes.
Or you can do it with either a function node or a change node with JSONata. To do so, you need a context variable that holds the gate state. You only pass the msg if the gate is true (or false whatever makes sense to your process). A separate input or a separate flow opens/closes the gate.
I find that the easiest way to block a flow based on something like the operation of a UI switch is node-red-contrib-simple-gate. Then you can feed the switch straight into the gate, alongside the normal messages, and the input from the switch can open or close the gate to allow the messages through.
1 Like
Ahh, gate nodes! Very cool!
Did you ever play with LEGO? Remember being excited when you discovered a new part that you didn't know existed? ![:smiley: :smiley:](https://emoji.discourse-cdn.com/twitter/smiley.png?v=9)
Thank you TotallyInformation and Colin!
3 Likes
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.