# Node-red-contrib-boolean-logic

**URL:** <https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931>\
**Category:** General\
**Created:** [16 March 2022 14:50 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931 "2022-03-16T14:50:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_mirjka](https://avatars.discourse-cdn.com/v4/letter/_/f19dbf/32.png) [@\_mirjka](https://discourse.nodered.org/u/_mirjka)\
**Post date:** [16 March 2022 14:50 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/1 "2022-03-16T14:50:57Z")

</div>

Hi,

after a lot googleing and searching in this forum (without success), I decided to open a new topic.  
I have no experience in programming 😉

Acutally I can´t get the node-red-contrib-boolean-logic "AND" running.  
Here is my current flow:

```auto
[
    {
        "id": "a06e8018b1704b0f",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": ""
    },
    {
        "id": "963717d20a3edc72",
        "type": "inject",
        "z": "a06e8018b1704b0f",
        "name": "trigger",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 450,
        "y": 300,
        "wires": [
            [
                "2aba1c1629e748b5"
            ]
        ]
    },
    {
        "id": "d087b46150f1879c",
        "type": "inject",
        "z": "a06e8018b1704b0f",
        "name": "trigger",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 450,
        "y": 340,
        "wires": [
            [
                "f019ed65ead5e776"
            ]
        ]
    },
    {
        "id": "2aba1c1629e748b5",
        "type": "trigger",
        "z": "a06e8018b1704b0f",
        "name": "true5s",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5000",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "false",
        "bytopic": "all",
        "topic": "on_off:true",
        "outputs": 1,
        "x": 590,
        "y": 300,
        "wires": [
            [
                "a9a6089bf5593a78",
                "6f37650026621006"
            ]
        ]
    },
    {
        "id": "f019ed65ead5e776",
        "type": "trigger",
        "z": "a06e8018b1704b0f",
        "name": "true5s",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5000",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "false",
        "bytopic": "all",
        "topic": "on_off:true",
        "outputs": 1,
        "x": 590,
        "y": 340,
        "wires": [
            [
                "a9a6089bf5593a78",
                "6f37650026621006"
            ]
        ]
    },
    {
        "id": "a9a6089bf5593a78",
        "type": "debug",
        "z": "a06e8018b1704b0f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 260,
        "wires": []
    },
    {
        "id": "dfc1b2830593df69",
        "type": "debug",
        "z": "a06e8018b1704b0f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 320,
        "wires": []
    },
    {
        "id": "6f37650026621006",
        "type": "BooleanLogic",
        "z": "a06e8018b1704b0f",
        "name": "",
        "operation": "AND",
        "inputCount": 2,
        "topic": "result",
        "x": 750,
        "y": 320,
        "wires": [
            [
                "dfc1b2830593df69"
            ]
        ]
    }
]

```

Would be great if someone could give me a hint...

---

<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:** [16 March 2022 15:09 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/2 "2022-03-16T15:09:03Z")

</div>

The AND logic node uses msg.topic to distinguish between the two inputs.

If you add msg.topic to your two inject nodes, using two different topics, it should work.  
Alternatively, you could add msg.topic using change nodes.

---

<div class="post-metadata">

**Author:** ![\_mirjka](https://avatars.discourse-cdn.com/v4/letter/_/f19dbf/32.png) [@\_mirjka](https://discourse.nodered.org/u/_mirjka)\
**Post date:** [16 March 2022 16:23 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/3 "2022-03-16T16:23:16Z")

</div>

I finally got it, thanks!  
But I only can inject msg.topic via the inject nodes.

Is it easy to convert a bool value (which is sent via MQTT) into a msr.topic in order to use it as a trigger for AND?

---

<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:** [16 March 2022 16:38 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/4 "2022-03-16T16:38:57Z")

</div>

If the data arrives via mqtt it will already have msg.topic. As long as the two inputs don't have the same topic (eg sensors/door and sensors/window) you shouldn't need to do anything.  
But you can use a change mode to set msg.topic

---

<div class="post-metadata">

**Author:** ![\_mirjka](https://avatars.discourse-cdn.com/v4/letter/_/f19dbf/32.png) [@\_mirjka](https://discourse.nodered.org/u/_mirjka)\
**Post date:** [16 March 2022 17:50 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/5 "2022-03-16T17:50:03Z")

</div>

Ok, I try to seperate the massage in another way tomorrow.

---

<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:** [16 March 2022 18:02 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/6 "2022-03-16T18:02:12Z")

</div>

Are you trying to do an AND of two values that are in the same message?

---

<div class="post-metadata">

**Author:** ![\_mirjka](https://avatars.discourse-cdn.com/v4/letter/_/f19dbf/32.png) [@\_mirjka](https://discourse.nodered.org/u/_mirjka)\
**Post date:** [21 March 2022 09:28 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/7 "2022-03-21T09:28:50Z")

</div>

Sorry for not answering!  
I figured it out by using the change node: I changed payload to topic. not pretty but it works 🙂

```auto
[
    {
        "id": "aac0bf696ba6908d",
        "type": "change",
        "z": "d6aef09d.37155",
        "name": "topic + true",
        "rules": [
            {
                "t": "move",
                "p": "payload",
                "pt": "msg",
                "to": "topic",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1230,
        "y": 1540,
        "wires": [
            [
                "10f7766c5fdf8ea8"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 May 2022 09:29 UTC](https://discourse.nodered.org/t/node-red-contrib-boolean-logic/59931/8 "2022-05-20T09:29:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
