# Logical And Function

**URL:** https://discourse.nodered.org/t/logical-and-function/70093
**Category:** General
**Created:** [4 November 2022 17:26 UTC](https://discourse.nodered.org/t/logical-and-function/70093 "2022-11-04T17:26:20Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 November 2022 21:52 UTC](https://discourse.nodered.org/t/logical-and-function/70093/41 "2022-11-28T21:52:18Z")

</div>

It is surprising that despite all of the different solutions people have offered you in this thread you chose to install and use a node that was last updated nearly 7 years ago.  
I have no idea if it is compatible with the current versions of Node-red or node.js.

Your best bet is to try the contrib node that @Colin, @E1cid and @craigcurtin recommended.  
There is nothing more that I can do to help.  
 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/857b3471ae4188a6b71aecf8ab734668d900a5be.jpeg)

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [29 November 2022 10:02 UTC](https://discourse.nodered.org/t/logical-and-function/70093/42 "2022-11-29T10:02:02Z")

</div>

![Skærmbillede 2022-11-29 kl. 10.55.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e10b7790098529f1745496068f97cf76efed4f4.png)

```auto
[{"id":"c52af6352be3bd5a","type":"rbe","z":"39a6bd7ef2286e65","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"amp","x":870,"y":120,"wires":[["94a0724cdf7b7618","751c9164ba677e74"]]},{"id":"e67b914464cf267c","type":"rbe","z":"39a6bd7ef2286e65","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"arc","x":870,"y":180,"wires":[["6a0766367991330c","751c9164ba677e74"]]},{"id":"5bde12cc53890d7b","type":"debug","z":"39a6bd7ef2286e65","name":"event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":140,"wires":[]},{"id":"94a0724cdf7b7618","type":"debug","z":"39a6bd7ef2286e65","name":"amp event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":100,"wires":[]},{"id":"6a0766367991330c","type":"debug","z":"39a6bd7ef2286e65","name":"arc event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":260,"wires":[]},{"id":"88c986d802a6409f","type":"comment","z":"39a6bd7ef2286e65","name":"This Flow does not work as expected","info":"","x":360,"y":80,"wires":[]},{"id":"e34dd8125e221d9b","type":"comment","z":"39a6bd7ef2286e65","name":"And (2) Node always show unknown ","info":"","x":1120,"y":200,"wires":[]},{"id":"e9e99f5e61cfac23","type":"inject","z":"39a6bd7ef2286e65","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"805","payloadType":"num","x":90,"y":120,"wires":[["12dc3d72de43c2d1"]]},{"id":"fa2e0ad1bb87646a","type":"inject","z":"39a6bd7ef2286e65","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"795","payloadType":"num","x":90,"y":180,"wires":[["12dc3d72de43c2d1"]]},{"id":"44cdd53e0470dace","type":"inject","z":"39a6bd7ef2286e65","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":90,"y":260,"wires":[["aaa0b54c99a79c9f"]]},{"id":"8670cfd1422be895","type":"inject","z":"39a6bd7ef2286e65","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":90,"y":320,"wires":[["aaa0b54c99a79c9f"]]},{"id":"751c9164ba677e74","type":"BooleanLogic","z":"39a6bd7ef2286e65","name":"","operation":"AND","inputCount":2,"topic":"result","x":1060,"y":140,"wires":[["5bde12cc53890d7b"]]},{"id":"2ff476ad83936390","type":"group","z":"39a6bd7ef2286e65","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["f24d695a4931d365","ad27bef6115b4c61","aaa0b54c99a79c9f","12dc3d72de43c2d1","9b8a7de322bdd0b6"],"x":334,"y":79,"w":392,"h":242},{"id":"f24d695a4931d365","type":"change","z":"39a6bd7ef2286e65","g":"2ff476ad83936390","name":"True above 800 Amps","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"amp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":120,"wires":[["c52af6352be3bd5a"]]},{"id":"ad27bef6115b4c61","type":"change","z":"39a6bd7ef2286e65","g":"2ff476ad83936390","name":"False below 800 Amps","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"topic","pt":"msg","to":"amp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":160,"wires":[["c52af6352be3bd5a"]]},{"id":"aaa0b54c99a79c9f","type":"change","z":"39a6bd7ef2286e65","g":"2ff476ad83936390","name":"Topic = arc","rules":[{"t":"set","p":"topic","pt":"msg","to":"arc","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":200,"wires":[["e67b914464cf267c"]]},{"id":"12dc3d72de43c2d1","type":"switch","z":"39a6bd7ef2286e65","g":"2ff476ad83936390","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"800","vt":"num"},{"t":"lt","v":"800","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":120,"wires":[["f24d695a4931d365"],["ad27bef6115b4c61"]]},{"id":"9b8a7de322bdd0b6","type":"comment","z":"39a6bd7ef2286e65","g":"2ff476ad83936390","name":"See the nodes in the boxed area","info":"","x":530,"y":280,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 November 2022 10:37 UTC](https://discourse.nodered.org/t/logical-and-function/70093/43 "2022-11-29T10:37:18Z")

</div>

Tell us which boolean node you are using (node-red-contrib-???).  
Show us what you see in the amp and arc events debug.

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [29 November 2022 11:44 UTC](https://discourse.nodered.org/t/logical-and-function/70093/44 "2022-11-29T11:44:08Z")

</div>

It was a reply to HansZnarf

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 13:21 UTC](https://discourse.nodered.org/t/logical-and-function/70093/45 "2022-11-29T13:21:55Z")

</div>

jbudd: Please excuse my ignorance about the age of the node I am trying to use. Being a nebie at Node-Red I have a lot to learn. My past programming experience involves logic blocks / nodes. Those I understand and the Node-Red nodes appear to work in some cases. I am not understanding the solutions being presented to me by others on the forum. If little more explanation will help. Would hope that others would gently assist people. Sorry to hear that I am frustrating others with my obvious lack of Node-Red experience.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 13:27 UTC](https://discourse.nodered.org/t/logical-and-function/70093/46 "2022-11-29T13:27:01Z")

</div>

Thanks: Will examine this code to see if I can understand how it works.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 13:31 UTC](https://discourse.nodered.org/t/logical-and-function/70093/47 "2022-11-29T13:31:11Z")

</div>

Colin: Have been told that the logic nodes I have been trying to use are very old. Is there a board or agency that can warn us when nodes may not be viable? The BOOL blocks work well in testing with inject node but for some reason they do not work when I applied them to live data.  
Thanks, Hans

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [29 November 2022 13:32 UTC](https://discourse.nodered.org/t/logical-and-function/70093/48 "2022-11-29T13:32:54Z")

</div>

There is no problem with lack of knowledge. We all start out as beginners.

Pick one of the suggestions. node-red-contrib-boolean-logic-ultimate is a good starting point.  
Try it.  
Show us what you did and where you encountered difficulties.  
People will help explain where you went wrong.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 13:45 UTC](https://discourse.nodered.org/t/logical-and-function/70093/49 "2022-11-29T13:45:23Z")

</div>

Frida: This flow works flawlessly with the "antique" BOOL block that I understand. Your changes fixed my program. Many thanks for the team sticking with me through the process. Node-Red programming is a side project. Appreciate all the help.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 17:03 UTC](https://discourse.nodered.org/t/logical-and-function/70093/50 "2022-11-29T17:03:08Z")

</div>

Frida: Thanks - it did appear to be a data format issue between the 16Bit Split and the filter. Would you have the time to explain how the difference between msg.payload and msg.topic in the change node fixed the flow? If not can you provide a link to help me understand this difference?  
Sincerely, Hans.

---

<div class="post-metadata">

### Author: ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)
#### Post date: [29 November 2022 18:40 UTC](https://discourse.nodered.org/t/logical-and-function/70093/51 "2022-11-29T18:40:14Z")

</div>

What is the name of your "16bit split", because I don't know it.  
I'll try to explain. What comes out of "16bit split" is probably only true or false in the payload. (no topic).  
What "node-red-contrib-boolean-logic" needs is a different topic for each input that comes to it.  
Since you had no (topic) on any of your inputs, the logic node perceived it as 1 input.  
Therefore, I added topic in the framed nodes so that the logic node could see 2 inputs. (amp and arc).  
You had it right in your test further down the page.  
Hope it can be used.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [29 November 2022 19:53 UTC](https://discourse.nodered.org/t/logical-and-function/70093/52 "2022-11-29T19:53:03Z")

</div>

Poul Borg: That makes sense since the 16Bit Split node does not have a place to put in a topic for each bit.  
I just do not understand the difference between msg.payload and msg.topic. Flow attached

[flows (3).json](https://discourse.nodered.org/uploads/short-url/jFelzlsbLbV8fVW9z21t1JyiGPR.json) (8.26 KB)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [29 November 2022 20:57 UTC](https://discourse.nodered.org/t/logical-and-function/70093/53 "2022-11-29T20:57:56Z")

</div>

> [@HansZnarf](#):
>
> I just do not understand the difference between msg.payload and msg.topic.

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [30 November 2022 18:18 UTC](https://discourse.nodered.org/t/logical-and-function/70093/54 "2022-11-30T18:18:16Z")

</div>

Colin:

Many thanks, will view and see what can be learned. Part of my issue is unlearning years of industrial / commercial programming systems and seeing how Node-Red does things.

Sincerely,

Hans

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [30 November 2022 19:50 UTC](https://discourse.nodered.org/t/logical-and-function/70093/55 "2022-11-30T19:50:33Z")

</div>

Learning new things is the spice of life! 🕶

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [2 December 2022 20:14 UTC](https://discourse.nodered.org/t/logical-and-function/70093/56 "2022-12-02T20:14:50Z")

</div>

Yes learning is fun

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [3 December 2022 03:26 UTC](https://discourse.nodered.org/t/logical-and-function/70093/57 "2022-12-03T03:26:05Z")

</div>

Let me see if I can put a spin on it. Node-RED is message flow programming, not ladder rung logic. While you can do the same things in either, the approach is different.

Messages can contain strings, boolean, multiple items, objects, arrays, structures, and you can add and subtract as well as modify any and all of the values as you pass the message from one node to another. "payload" , "topic", are only the comon elements of a message. A message can contain pretty much anything you want. These can be string, boolean, or any data type.

For boolean logic example, lets take this approach... lets construct a message with variables. Lets call them "IN 1" and "IN 2". on the first input "IN 1" = true, the next node input gets "IN 2" = false. Stop. The message has 2 values that it is carying. Logical inputs if you will. At this point you can evaluate the content of the message to AND,, OR, or whatever. If you cary 3, 4, 5 or many more at the point where you accumulate the values in your input variables, once you have the inputs all satisfied for your logical evaluation, you apply the programming to evaluate the variables. This can be with an expression in javascript in a function node, for example.

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [3 December 2022 15:27 UTC](https://discourse.nodered.org/t/logical-and-function/70093/58 "2022-12-03T15:27:05Z")

</div>

I'd like to add to the comment earlier.

Rung logic represents "current state" always. That's what a PLC does. It constantly evaluates inputs, rung logic and the outputs.

In order to program or convert PLC logic into flow logic you must consider the overhead a PLC does by it's nature.

Message logic is ONLY when messages are passed. You can have a program run for years and some message paths will never run. So, you must check conditions in flow logic to ensure that you have valid states. You may need to force messages with defaults to initialize logic. And then, of course, a state change.

PLC programming, you need to consider what all your logic does at all times. then you also need to apply conditions to properly block evaluation to control unintended results. Message Flow programming does not need to consider what is NOT going on in time. You do not need to consider paths which are irrelevant, only those which are presently working to produce results. The logical thought process is completely different.

Consider your assumptions on how the machine works. Unknowns, and assumptions will get you every time.

For example timing is assumed Left to Right in PLC logic. This can cause issues how rungs are evaluated. Left to Right. Top to bottom. Allen Bradley vs. Modicon. Placement of rung logic elements in rungs before or after evaluation are critical depending on how rung logic is evaluated.

---

<div class="post-metadata">

### Author: ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)
#### Post date: [5 December 2022 14:06 UTC](https://discourse.nodered.org/t/logical-and-function/70093/59 "2022-12-05T14:06:50Z")

</div>

hp-apcc: Many thanks for the detailed explanation. I have done some PLC programming during my career. My main background has been in 3 phase electrical power monitoring software with data HMI functions and Industrial / Large Commercial - Institutional lighting control systems.

What I am attempting in Node-Red is to mimic / mine data from Protective Relays / PLCs to make local Dashboards and move data around. All control will happen at the Hardware Level in the Relays / PLCs. Sometimes this requires simple logic to tie two events together to create an alarm.

In my example we need a high current and arc flash (light 50k lux) event to both occur before we alarm. The protective relay will do the work at the gear level. Node-Red will provide an HMI and/or push events to another application for humans to use.

The attached block (believe you wrote it) changes what goes into it into something the AND node can use. The concept is clear but how it works internally to do this is a bit foggy.

How subject / variable names are handled in Node-Red is something I am very weak in knowledge.

Thanks, Hans

[MakeTopic.json](https://discourse.nodered.org/uploads/short-url/7URCikdHqJy9SvSnitm8lhtw0Lm.json) (581 Bytes)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 December 2022 15:01 UTC](https://discourse.nodered.org/t/logical-and-function/70093/60 "2022-12-05T15:01:38Z")

</div>

> [@HansZnarf](#):
>
> How subject / variable names are handled in Node-Red is something I am very weak in knowledge.

Have you watched the essentials videos I posted earlier?

[Previous page](https://discourse.nodered.org/t/logical-and-function/70093.md?page=2)

[Next page](https://discourse.nodered.org/t/logical-and-function/70093.md?page=4)
