# Why does the AND not work

**URL:** <https://discourse.nodered.org/t/why-does-the-and-not-work/52374>\
**Category:** Developing Nodes\
**Created:** [18 October 2021 18:16 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374 "2021-10-18T18:16:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [18 October 2021 18:16 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/1 "2021-10-18T18:16:32Z")

</div>

Good evening,  
I have two Boolean values. Both of these are true. The AND element always shows unknown and gives nothing out. Where is my mistake?

```auto
[
    {
        "id": "3d846a3cec7a7d97",
        "type": "change",
        "z": "da4995d901bb5abd",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "CLOSED",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OPEN",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 580,
        "y": 180,
        "wires": [
            [
                "418f6185c0335945"
            ]
        ]
    }
]

```

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/3126bf2686a97473f6ac88782399fb35a37f634c.png)

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [18 October 2021 18:25 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/2 "2021-10-18T18:25:30Z")

</div>

Hi Andy,

Can't import your posted code, it will import only a change node, the other nodes are missing.

---

<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:** [18 October 2021 18:26 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/3 "2021-10-18T18:26:42Z")

</div>

You have only posted one Change node so it's difficult to advise. But in that node you change OPEN to true and CLOSED to true.

So I suggest you check for similar typos elsewhere.

Edit: I can see the word "false" up there in your post but it doesn't show false when I import it.

---

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [18 October 2021 18:31 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/4 "2021-10-18T18:31:15Z")

</div>

```auto
[
    {
        "id": "da4995d901bb5abd",
        "type": "tab",
        "label": "Flow 11",
        "disabled": false,
        "info": ""
    },
    {
        "id": "cd2329869f578bf5",
        "type": "openhab2-in",
        "z": "da4995d901bb5abd",
        "name": "",
        "controller": "2341e6d1c1f117f5",
        "itemname": "FensterDurchgangszimmerlinks_OpenClose",
        "x": 290,
        "y": 120,
        "wires": [
            [
                "d1e942d83e070aef"
            ],
            []
        ]
    },
    {
        "id": "d1e942d83e070aef",
        "type": "change",
        "z": "da4995d901bb5abd",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "CLOSED",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OPEN",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 620,
        "y": 120,
        "wires": [
            [
                "418f6185c0335945"
            ]
        ]
    },
    {
        "id": "35d8f708c4eab8a5",
        "type": "openhab2-in",
        "z": "da4995d901bb5abd",
        "name": "",
        "controller": "2341e6d1c1f117f5",
        "itemname": "FensterDurchgangszimmerrechts_OpenClose",
        "x": 270,
        "y": 200,
        "wires": [
            [
                "3d846a3cec7a7d97"
            ],
            []
        ]
    },
    {
        "id": "3d846a3cec7a7d97",
        "type": "change",
        "z": "da4995d901bb5abd",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "CLOSED",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OPEN",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 580,
        "y": 180,
        "wires": [
            [
                "418f6185c0335945"
            ]
        ]
    },
    {
        "id": "418f6185c0335945",
        "type": "BooleanLogic",
        "z": "da4995d901bb5abd",
        "name": "",
        "operation": "AND",
        "inputCount": "2",
        "topic": "result",
        "x": 860,
        "y": 160,
        "wires": [
            [
                "01f457d68cf6d103"
            ]
        ]
    },
    {
        "id": "01f457d68cf6d103",
        "type": "debug",
        "z": "da4995d901bb5abd",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1070,
        "y": 200,
        "wires": []
    },
    {
        "id": "2341e6d1c1f117f5",
        "type": "openhab2-controller",
        "name": "Ziegler",
        "protocol": "http",
        "host": "192.168.178.YYY",
        "port": "8080",
        "path": "",
        "username": "oh.NODERED.xyzz",
        "password": ""
    }
]

```

---

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [18 October 2021 18:32 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/5 "2021-10-18T18:32:57Z")

</div>

```auto
[
    {
        "id": "da4995d901bb5abd",
        "type": "tab",
        "label": "Flow 11",
        "disabled": false,
        "info": ""
    },
    {
        "id": "cd2329869f578bf5",
        "type": "openhab2-in",
        "z": "da4995d901bb5abd",
        "name": "",
        "controller": "2341e6d1c1f117f5",
        "itemname": "FensterDurchgangszimmerlinks_OpenClose",
        "x": 290,
        "y": 120,
        "wires": [
            [
                "d1e942d83e070aef"
            ],
            []
        ]
    },
    {
        "id": "d1e942d83e070aef",
        "type": "change",
        "z": "da4995d901bb5abd",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "CLOSED",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OPEN",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 620,
        "y": 120,
        "wires": [
            [
                "418f6185c0335945"
            ]
        ]
    },
    {
        "id": "35d8f708c4eab8a5",
        "type": "openhab2-in",
        "z": "da4995d901bb5abd",
        "name": "",
        "controller": "2341e6d1c1f117f5",
        "itemname": "FensterDurchgangszimmerrechts_OpenClose",
        "x": 270,
        "y": 200,
        "wires": [
            [
                "3d846a3cec7a7d97"
            ],
            []
        ]
    },
    {
        "id": "3d846a3cec7a7d97",
        "type": "change",
        "z": "da4995d901bb5abd",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "CLOSED",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OPEN",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 580,
        "y": 180,
        "wires": [
            [
                "418f6185c0335945"
            ]
        ]
    },
    {
        "id": "418f6185c0335945",
        "type": "BooleanLogic",
        "z": "da4995d901bb5abd",
        "name": "",
        "operation": "AND",
        "inputCount": "2",
        "topic": "result",
        "x": 860,
        "y": 160,
        "wires": [
            [
                "01f457d68cf6d103"
            ]
        ]
    },
    {
        "id": "01f457d68cf6d103",
        "type": "debug",
        "z": "da4995d901bb5abd",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1070,
        "y": 200,
        "wires": []
    },
    {
        "id": "2341e6d1c1f117f5",
        "type": "openhab2-controller",
        "name": "Ziegler",
        "protocol": "http",
        "host": "192.168.178.XX",
        "port": "8080",
        "path": "",
        "username": "xxxxxxx",
        "password": ""
    }
]

```

---

<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:** [18 October 2021 18:33 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/6 "2021-10-18T18:33:46Z")

</div>

Sorry, that won't import either, click the "Preformatted text" button then paste over the highlighted line.  
Done...

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 18:34 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/7 "2021-10-18T18:34:38Z")

</div>

Hi, in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [18 October 2021 18:42 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/8 "2021-10-18T18:42:25Z")

</div>

Do your inputs have msg.topic set?  
Try setting two different topics in the change nodes.

The importing false as true is a problem at my end, it imports OK on another computer.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 18:45 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/9 "2021-10-18T18:45:14Z")

</div>

Andy

You have a couple issues in your change nodes. You have:  
 ![Screen Shot 2021-10-18 at 2.40.25 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c33be16cc63ca3a8e5d7619c683c587e6c6416c4.png)  
and you are `replacing` the values you search for. That means that if you sent in the string "CLOSED and OPEN" you would end up with "true and true" so unless both inputs were exactly same thing, the result will always be FALSE. If you sent "valve 2 is open" and "valve 4 is open" you would still get a FALSE becasue the replace would return the messages "valve 2 is true" and "xvalve 4 is true" and they don't match.

Put a `debug` node on the output of every node (and name them) and run your test so you can see what data is coming thru and how it will react.

---

<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:** [18 October 2021 18:48 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/10 "2021-10-18T18:48:58Z")

</div>

@zenofmud, could there be a problem in Node-Red's import function?  
If you look at the code @AndyWB first posted in this thread, it clearly shows Change string OPEN to boolean false.

---

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [18 October 2021 18:50 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/11 "2021-10-18T18:50:26Z")

</div>

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/54db25d7cd85e11e12ebf7dfc321bd4b00fd5c11.png)  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/74003c21333a2ffd55c2c41489a5e3a97bef1795.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 18:56 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/12 "2021-10-18T18:56:49Z")

</div>

What does the data coming into the two change nodes look like?

@jbudd Nope, the import imports it correctly but the search replaces only the value searched for not the entire msg.payload and the end result is a string containing the words 'true' or 'false' with what ever text was originally in the incoming msg.payload. This is why it is important to look at the data going into and out of a node when you don't get the results you expect.

---

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [18 October 2021 19:02 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/13 "2021-10-18T19:02:41Z")

</div>

That is the content of the object. I have no idea what I have to do so that I actually only get true or false.  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11b3d25433f47ac6231e03990e694eb7b8a27924.png)

```auto
{"_msgid":"d128fce2e164cd82","payload":true,"item":"FensterDurchgangszimmerlinks_OpenClose","event":"StateEvent"}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 19:19 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/14 "2021-10-18T19:19:19Z")

</div>

What node is that coming from?  
Is that the incoming data?  
What comes from the other node?  
What is in msg.topic?What comes out of the two change nodes?

---

<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:** [18 October 2021 19:20 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/15 "2021-10-18T19:20:15Z")

</div>

> [@zenofmud](#):
>
> import imports it correctly

I don't think it does. I've posted about it on the 2.1.0beta.2 thread

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 19:29 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/16 "2021-10-18T19:29:54Z")

</div>

Well then wwe need to know what version of Node-RED @AndyWB is running.  
(@jbudd good spot!)

---

<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:** [18 October 2021 19:31 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/17 "2021-10-18T19:31:54Z")

</div>

@AndyWB did you try setting msg.topic in your change nodes?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 October 2021 20:15 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/18 "2021-10-18T20:15:34Z")

</div>

@jbudd I just checked and it imports fine in v2.0.6 so that is another 2.1.0 beta bug. Like I said good spot!

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [18 October 2021 20:21 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/19 "2021-10-18T20:21:14Z")

</div>

For info;

> [@tada Node-RED 2.1.0-beta.2 released](https://discourse.nodered.org/t/node-red-2-1-0-beta-2-released/52212/19):
>
> Currently debugging this live on Twitch... [Twitch](https://twitch.tv/knolleary)

---

<div class="post-metadata">

**Author:** ![AndyWB](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@AndyWB](https://discourse.nodered.org/u/AndyWB)\
**Post date:** [19 October 2021 17:08 UTC](https://discourse.nodered.org/t/why-does-the-and-not-work/52374/20 "2021-10-19T17:08:09Z")

</div>

I work with 2.0.6: Maintenance Release  
I hope this will help you, to help me

[Next page](https://discourse.nodered.org/t/why-does-the-and-not-work/52374.md?page=2)
