# AND - how it works?

**URL:** <https://discourse.nodered.org/t/and-how-it-works/85663>\
**Category:** General\
**Created:** [19 February 2024 07:05 UTC](https://discourse.nodered.org/t/and-how-it-works/85663 "2024-02-19T07:05:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 07:05 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/1 "2024-02-19T07:05:15Z")

</div>

Hello, starting, would need some infos pls!

 ![Bildschirmfoto 2024-02-19 um 07.48.59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/769d19c0b5b826422bae81ca75cfbee37ec1de77.png)

```auto
[
    {
        "id": "092520097a3dcc4c",
        "type": "victron-input-system",
        "z": "7978e0ce1be8e6fb",
        "service": "com.victronenergy.system/0",
        "path": "/Dc/Battery/Voltage",
        "serviceObj": {
            "service": "com.victronenergy.system/0",
            "name": "Venus system"
        },
        "pathObj": {
            "path": "/Dc/Battery/Voltage",
            "type": "float",
            "name": "Battery voltage (V)"
        },
        "name": "",
        "onlyChanges": false,
        "x": 160,
        "y": 60,
        "wires": [
            [
                "8d3e188d3bb213c2",
                "8f7751900ce13e11"
            ]
        ]
    },
    {
        "id": "8f7751900ce13e11",
        "type": "limit-monitor",
        "z": "7978e0ce1be8e6fb",
        "name": "lower limit",
        "topic": "",
        "limit": "65",
        "kind": "1",
        "delay": "0",
        "hysteresis": "0",
        "x": 430,
        "y": 80,
        "wires": [
            [
                "826d727d6717c7fa",
                "be8c435f27d8a2db"
            ]
        ]
    },
    {
        "id": "8d3e188d3bb213c2",
        "type": "limit-monitor",
        "z": "7978e0ce1be8e6fb",
        "name": "upper limit",
        "topic": "",
        "limit": "60",
        "kind": "2",
        "delay": "0",
        "hysteresis": "0",
        "x": 430,
        "y": 40,
        "wires": [
            [
                "826d727d6717c7fa"
            ]
        ]
    },
    {
        "id": "826d727d6717c7fa",
        "type": "and",
        "z": "7978e0ce1be8e6fb",
        "name": "",
        "topic": "",
        "property": "payload",
        "minData": "1",
        "filter": false,
        "x": 590,
        "y": 60,
        "wires": [
            [
                "0137ea2a0adbd59d",
                "37b45ff69e780207"
            ]
        ]
    },
    {
        "id": "37b45ff69e780207",
        "type": "debug",
        "z": "7978e0ce1be8e6fb",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 40,
        "wires": []
    },
    {
        "id": "be8c435f27d8a2db",
        "type": "debug",
        "z": "7978e0ce1be8e6fb",
        "name": "debug 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 120,
        "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:** [19 February 2024 07:43 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/2 "2024-02-19T07:43:33Z")

</div>

What node have you installed that gives you the And gate? Possibly node-red-contrib-something,

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 08:27 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/3 "2024-02-19T08:27:09Z")

</div>

Hello and welcome to the Node-RED forum.

Just checking... are your nodes 'Home Assistant' nodes (as I don't recognise the colour/shape of them) ?  
If they are - then I doubt if anyone will be able to help as most people on this forum don't use HA.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 08:55 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/4 "2024-02-19T08:55:26Z")

</div>

this node-red is installed on a Victron Cerbo GX device  
which pallet should I install to have node-red logics?

maybe I installed the wrong one?  
 ![Bildschirmfoto 2024-02-19 um 09.55.00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc0f340a67e5d7baef1876d119b7ab7b0b2e563d.png)

---

<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:** [19 February 2024 09:11 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/5 "2024-02-19T09:11:16Z")

</div>

I have not used that node, but it looks ok. Have you remembered to make sure that the two inputs have different topics as described in the help text? If you have then add another debug showing what is coming out of the upper limit node and show us what you see in the debug pane showing the inputs and outputs.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 09:18 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/6 "2024-02-19T09:18:35Z")

</div>

> [@4711Austria](#):
>
> Victron Cerbo GX

I'd not heard of that platform until today.  
Looks like that version of Node-RED has a mixture of styles of nodes.  
It will be interesting to hear what you discover using @Colin suggestion.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 09:24 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/7 "2024-02-19T09:24:32Z")

</div>

still I am not familiar with the coding on nodes, maybe the topic is set wrong? tried different thins on A, or "A" or (A)... nothing does the job  
the value changes, I do not get a debug out of the upper node (where the value is ok)  
is that the problem, that they do not feed simultainously true or false?

 ![Bildschirmfoto 2024-02-19 um 10.22.52](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/9408d1ac6e596ca243475b1b4f3a02b917fdf27c.png)  
 ![Bildschirmfoto 2024-02-19 um 10.22.42](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfa2090e5a9325cb9d78447bf29ec48d6250fd17.png)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 09:26 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/8 "2024-02-19T09:26:53Z")

</div>

I've just imported your flow on one of my Raspberry Pi platforms.  
This is what I get... lots of unknown nodes (so maybe going to be difficult to help you).

 ![unknown](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9cc4484afc8bfa57dcf9bf2e5a2c13780ce145f7.png)

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 09:28 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/9 "2024-02-19T09:28:29Z")

</div>

I am asking for standard behavior, use other nodes that work for you.  
I just want to check a value to be in a range, the end should be a relais is activated/deactivated

---

<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:** [19 February 2024 09:33 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/10 "2024-02-19T09:33:46Z")

</div>

For that you can use a Switch node (not ui\_switch) that directs the message to different outputs dependent on the value.  
Send it to output 1 if less then your lower limit, output 2 if greater than your upper limit and Otherwise to output 3. Then the in range messages will appear on output 3.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 09:39 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/11 "2024-02-19T09:39:36Z")

</div>

Can you explain a bit about the desired "logic"?  
I can see you have battery voltage as an input and a test for an upper and lower value.

So in words can you say something like...  
"When the battery voltage is 60V or above do this..."  
"When the battery voltage is 40V or below do this..."

The flow you posted has a sort of hysteresis effect - is that what you intended?

Not sure what you are trying to do with the AND gate.

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 09:47 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/12 "2024-02-19T09:47:01Z")

</div>

is used in between, or does it need to go through 3 outputs?  
getting the value out, would need true/false?

 ![Bildschirmfoto 2024-02-19 um 10.44.53](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01d475cdc5274befcfc96130e87665d831663af3.png)

simple comparism, if the value is inside a range -\> out true to acrivate a relais, if not deactivate

---

<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:** [19 February 2024 09:48 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/13 "2024-02-19T09:48:59Z")

</div>

> [@4711Austria](#):
>
> does it need to go through 3 outputs?

I would not have said to send it to three outputs if that was not necessary. Then in the outputs you can use Change nodes to set the relay values.

As a beginner 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:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 09:49 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/14 "2024-02-19T09:49:27Z")

</div>

I think this is what @Colin is suggesting...  
 ![filter](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/182a0452f27d6a225febdc75c1bca9c05c3e7861.png)

Here's my flow - you can 'copy' it and 'import' it into Node-RED.

```auto
[{"id":"a6d89fd07304fbc4","type":"inject","z":"1774ba78f53ce4da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"60","payloadType":"num","x":290,"y":820,"wires":[["af09aaf230403cbf"]]},{"id":"af09aaf230403cbf","type":"switch","z":"1774ba78f53ce4da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"60","vt":"num"},{"t":"lte","v":"40","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":450,"y":880,"wires":[["e4611d2839ba3057"],["cc71a1ca97d548fc"],["637f3df30e0bb242"]]},{"id":"6bd8322efbe8a4ef","type":"comment","z":"1774ba78f53ce4da","name":"Upper = 60, Lower = 40","info":"","x":500,"y":800,"wires":[]},{"id":"e4611d2839ba3057","type":"debug","z":"1774ba78f53ce4da","name":"High","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":840,"wires":[]},{"id":"7b6fb2795e5c12f9","type":"inject","z":"1774ba78f53ce4da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":290,"y":940,"wires":[["af09aaf230403cbf"]]},{"id":"8271b696f0de1cfe","type":"inject","z":"1774ba78f53ce4da","name":"50","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":290,"y":880,"wires":[["af09aaf230403cbf"]]},{"id":"cc71a1ca97d548fc","type":"debug","z":"1774ba78f53ce4da","name":"Low","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":880,"wires":[]},{"id":"637f3df30e0bb242","type":"debug","z":"1774ba78f53ce4da","name":"In range","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":920,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 09:54 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/15 "2024-02-19T09:54:03Z")

</div>

thx!! I understand, the "in range" shows the correct value, how do I get a true/false?

 ![Bildschirmfoto 2024-02-19 um 10.55.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93ba3932d6a6af19d7af278ff7a0d12da461c654.png)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 10:04 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/16 "2024-02-19T10:04:48Z")

</div>

Try this using a 'function' node.  
 ![filter_3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f00441b810c2db065bc25ba0a3cba86374da303.png)

```auto
[{"id":"a6d89fd07304fbc4","type":"inject","z":"1774ba78f53ce4da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"60","payloadType":"num","x":290,"y":820,"wires":[["af09aaf230403cbf","40cf7ea0d27d6bc0"]]},{"id":"af09aaf230403cbf","type":"switch","z":"1774ba78f53ce4da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"60","vt":"num"},{"t":"lte","v":"40","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":450,"y":880,"wires":[["e4611d2839ba3057"],["cc71a1ca97d548fc"],["637f3df30e0bb242"]]},{"id":"6bd8322efbe8a4ef","type":"comment","z":"1774ba78f53ce4da","name":"Upper = 60, Lower = 40","info":"","x":500,"y":800,"wires":[]},{"id":"e4611d2839ba3057","type":"debug","z":"1774ba78f53ce4da","name":"High","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":840,"wires":[]},{"id":"7b6fb2795e5c12f9","type":"inject","z":"1774ba78f53ce4da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":290,"y":940,"wires":[["af09aaf230403cbf","40cf7ea0d27d6bc0"]]},{"id":"8271b696f0de1cfe","type":"inject","z":"1774ba78f53ce4da","name":"50","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","x":290,"y":880,"wires":[["af09aaf230403cbf","40cf7ea0d27d6bc0"]]},{"id":"cc71a1ca97d548fc","type":"debug","z":"1774ba78f53ce4da","name":"Low","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":880,"wires":[]},{"id":"637f3df30e0bb242","type":"debug","z":"1774ba78f53ce4da","name":"In range","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":920,"wires":[]},{"id":"40cf7ea0d27d6bc0","type":"function","z":"1774ba78f53ce4da","name":"function 8","func":"if (msg.payload >= 60 || msg.payload <= 40) {\n node.status({fill:\"red\",shape:\"dot\",text:\"Out of range\"});\n msg.payload = false;\n}\nelse {\n node.status({fill:\"green\",shape:\"dot\",text:\"In range\"});\n msg.payload = true;\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1040,"wires":[["89102cc53f5dc444"]]},{"id":"89102cc53f5dc444","type":"debug","z":"1774ba78f53ce4da","name":"debug 416","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":1040,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 10:11 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/17 "2024-02-19T10:11:39Z")

</div>

yes that works, but I am not familiar with Java, still need to learn it of course...  
so I would need a std. node to change the "in range" to a true/false signal

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 February 2024 10:13 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/18 "2024-02-19T10:13:08Z")

</div>

Use change nodes, set payload to true or false. (high/low = false, in range = true for example)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [19 February 2024 10:13 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/19 "2024-02-19T10:13:57Z")

</div>

Please note:  
It is Java-Script NOT Java - two completely different languages. Make sure you learn the right one (ha, ha).

Please node:  
The flow I posted above will output 'true' or 'false' - check the output on the 'To my relay' debug node.  
 ![debug_node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/1162ecd8d777a4df72172f5b2c940745fd3b58b5.png)

---

<div class="post-metadata">

**Author:** ![4711Austria](https://avatars.discourse-cdn.com/v4/letter/4/c6cbf5/32.png) [@4711Austria](https://discourse.nodered.org/u/4711Austria)\
**Post date:** [19 February 2024 10:19 UTC](https://discourse.nodered.org/t/and-how-it-works/85663/20 "2024-02-19T10:19:31Z")

</div>

sry, do not get the point in editing the change node, there is comming a value or not from the switch node

the function generates true/false, but would like to do the job without java-script

[Next page](https://discourse.nodered.org/t/and-how-it-works/85663.md?page=2)
