# True / false nicht erkannt

**URL:** <https://discourse.nodered.org/t/true-false-nicht-erkannt/96272>\
**Category:** General\
**Created:** [26 March 2025 16:26 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272 "2025-03-26T16:26:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![binderj1](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@binderj1](https://discourse.nodered.org/u/binderj1)\
**Post date:** [26 March 2025 16:26 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/1 "2025-03-26T16:26:55Z")

</div>

Hallo  
Kann mir jemand sagen bzw. erklären warum in meinem Flow das (function-noe "Stop\_10") true und false nicht erkennt.

```auto
[{"id":"084fdb23992ec35f","type":"tab","label":"Flow 6","disabled":false,"info":"","env":[]},{"id":"17b51293306fc757","type":"mqtt in","z":"084fdb23992ec35f","name":"state","topic":"shellyplus2pm-a0dd6c4acab4/status/cover:0","qos":"2","datatype":"auto-detect","broker":"d457a115.b395e","nl":false,"rap":true,"rh":0,"inputs":0,"x":330,"y":480,"wires":[["58b0b8f9395f3844"]]},{"id":"58b0b8f9395f3844","type":"function","z":"084fdb23992ec35f","name":"opening closing","func":"if ((msg.payload.state === \"opening\") || (msg.payload.state === \"closing\")) {\n msg.payload.E2 = true;\n} else if ((msg.payload.state === \"open\") || (msg.payload.state === \"closed\")) {\n msg.payload.E2 = false;\n}\n\nreturn [{ payload: msg.payload.E2}] ;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":480,"wires":[["2a875159d19ee36a","a38933851346e3cf"]]},{"id":"c8fa46e8f18fee2c","type":"debug","z":"084fdb23992ec35f","name":"debug A2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":440,"wires":[]},{"id":"2a875159d19ee36a","type":"function","z":"084fdb23992ec35f","name":"Stop_10","func":" if (msg.payload.E2 === false) {\n return [null, { payload: msg.payload.E2}]; // E1 → Ausgang 2\n } else {\n return [{ payload: msg.payload.E2}, null]; // E1 → Ausgang 1\n }\n","outputs":2,"timeout":"0","noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":480,"wires":[["c8fa46e8f18fee2c"],["a7ad6ad5c469d921"]]},{"id":"a7ad6ad5c469d921","type":"debug","z":"084fdb23992ec35f","name":"debug A3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":540,"wires":[]},{"id":"a38933851346e3cf","type":"debug","z":"084fdb23992ec35f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":320,"wires":[]},{"id":"d457a115.b395e","type":"mqtt-broker","name":"ZuHause","broker":"192.168.178.52","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

 ![false](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e5c95243a6175356cbddadcaa9a4ef860d0c4ad.png)

DANKE

---

<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:** [26 March 2025 16:47 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/2 "2025-03-26T16:47:32Z")

</div>

What are you trying to achieve with this (in function "opening closing")?

```auto
return [{ payload: msg.payload.E2}] ;

```

In function "stop\_10" you have `if (msg.payload.E2 === false)` but at this point there is no msg.payload.E2. msg.payload contains `true`.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [26 March 2025 16:50 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/3 "2025-03-26T16:50:36Z")

</div>

Was about to reply, but @jbudd got there before me.

As above, you are setting `payload` to a boolean.  
so instead (in `opening closing`)

Just do

```auto
return msg;

```

NOT

```auto
/* set's payload to a boolean, nothing more */
return [{ payload: msg.payload.E2}] ;

```

---

<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:** [26 March 2025 16:58 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/4 "2025-03-26T16:58:00Z")

</div>

In addition, your function "Stop\_10" would be much more efficiently accomplished as a switch node. There is more to Node-red than a javascript IDE.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ff11e7d88fe7143f4ecc9a567877929bf695ca8d.png)

---

<div class="post-metadata">

**Author:** ![binderj1](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@binderj1](https://discourse.nodered.org/u/binderj1)\
**Post date:** [27 March 2025 18:35 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/5 "2025-03-27T18:35:07Z")

</div>

Hallo

 ![test](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b99ed225019496f2d954da8b345c870860c9952.jpeg)

Wenn der Ausgang von [State]="false" ist, und von [Push 0] ein "input:0" kommt muss zu [0 open] ein "start" kommen.  
Ist der Ausgang von [State]="true" , und von [Push 0] kommt ein "input:0" , muss zu [0 stop] ein "stop" kommen.

wie soll ich das machen ich check das nicht. 😭

```auto
[{"id":"43fa0f745315d099","type":"tab","label":"Büro","disabled":false,"info":"","env":[]},{"id":"824eb5a48c275c81","type":"function","z":"43fa0f745315d099","name":"0 open","func":"msg.payload = {\n method: \"Cover.Open\",\n parameters : {\n id : 0,\n // duration : 1, // optional time in seconds\n }\n};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":240,"wires":[["41edd01d4a3faa58"]]},{"id":"41edd01d4a3faa58","type":"shelly-gen2","z":"43fa0f745315d099","hostname":"192.168.178.64","description":"Rollladen Büro_ost","mode":"callback","verbose":false,"server":"04263f2d054cc2a1","uploadretryinterval":"5000","pollinginterval":5000,"pollstatus":true,"getstatusoncommand":false,"devicetype":"SNSW-102P16EU","devicetypemustmatchexactly":false,"captureblutooth":false,"outputs":1,"x":1130,"y":400,"wires":[[]]},{"id":"66851263862684f4","type":"function","z":"43fa0f745315d099","name":"0 close","func":"msg.payload = {\n method: \"Cover.Close\",\n parameters : {\n id : 0,\n // duration : 1, // optional time in seconds\n }\n};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":580,"wires":[["41edd01d4a3faa58"]]},{"id":"d86a41064c9daf66","type":"function","z":"43fa0f745315d099","name":"0 stop","func":"msg.payload = {\n method: \"Cover.Stop\",\n parameters : {\n id : 0,\n }\n};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":400,"wires":[["41edd01d4a3faa58"]]},{"id":"22e5d009183d672e","type":"shelly-gen2","z":"43fa0f745315d099","hostname":"192.168.178.54","description":"LoungeSwitch","mode":"callback","verbose":false,"server":"04263f2d054cc2a1","outputmode":"event","uploadretryinterval":"5000","pollinginterval":"2000","pollstatus":true,"getstatusoncommand":true,"devicetype":"Button","devicetypemustmatchexactly":false,"captureblutooth":false,"outputs":1,"x":100,"y":480,"wires":[["3f222e1af003b9e3","4ca15a6d734eb7a0"]]},{"id":"3f222e1af003b9e3","type":"function","z":"43fa0f745315d099","name":"Push 0","func":"let singlePush = null;\nlet doublePush = null;\nlet longePush = null;\n\nif(msg.payload.component === \"input:0\"){\n event = msg.payload.info.event;\n switch(event){\n case \"single_push\":\n singlePush = msg;\n break;\n case \"double_push\":\n doublePush = msg;\n break;\n case \"long_push\":\n longePush = msg;\n break;\n }\n}\n\nnode.send([singlePush, doublePush, longePush]);","outputs":3,"timeout":"0","noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":320,"wires":[["0874887255905690"],[],[]]},{"id":"4ca15a6d734eb7a0","type":"function","z":"43fa0f745315d099","name":"Push 1","func":"let singlePush = null;\nlet doublePush = null;\nlet longePush = null;\n\nif(msg.payload.component === \"input:1\"){\n event = msg.payload.info.event;\n switch(event){\n case \"single_push\":\n singlePush = msg;\n break;\n case \"double_push\":\n doublePush = msg;\n break;\n case \"long_push\":\n longePush = msg;\n break;\n }\n}\n\nnode.send([singlePush, doublePush, longePush]);","outputs":3,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":480,"wires":[["fe30edfdec99f78b"],[],[]]},{"id":"09ec8db5a21c98c9","type":"comment","z":"43fa0f745315d099","name":"Shelly plus 2PM","info":"IP:64","x":1140,"y":360,"wires":[]},{"id":"e56d68d38cd8bcf9","type":"comment","z":"43fa0f745315d099","name":"Shelly I4","info":"IP:64","x":100,"y":440,"wires":[]},{"id":"0bb73530a83ae462","type":"mqtt in","z":"43fa0f745315d099","name":"state","topic":"shellyplus2pm-a0dd6c4acab4/status/cover:0","qos":"2","datatype":"auto-detect","broker":"d457a115.b395e","nl":false,"rap":true,"rh":0,"inputs":0,"x":330,"y":400,"wires":[["943e3d90bbb81aea"]]},{"id":"0874887255905690","type":"function","z":"43fa0f745315d099","name":"Stop_1","func":"if (msg.payload.component === \"input:0\") {\n if (msg.payload.E2 === \"false\") {\n return [null, { payload: msg.payload[\"stop\"] }]; // E1 → Ausgang 1\n } else {\n return [{ payload: msg.payload[\"start\"] }, null]; // E1 → Ausgang 2\n }\n}\n","outputs":2,"timeout":"0","noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":240,"wires":[["824eb5a48c275c81"],["d86a41064c9daf66"]]},{"id":"943e3d90bbb81aea","type":"function","z":"43fa0f745315d099","name":"State","func":"if ((msg.payload.state === \"opening\") || (msg.payload.state === \"closing\")) {\n msg.payload.E2 = true;\n} else if ((msg.payload.state === \"open\") || (msg.payload.state === \"closed\")) {\n msg.payload.E2 = false;\n}\n\nreturn [{ payload: msg.payload.E2}] ;\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":400,"wires":[["fe30edfdec99f78b","0874887255905690"]]},{"id":"fe30edfdec99f78b","type":"function","z":"43fa0f745315d099","name":"Stop_2","func":"if (msg.payload.component === \"input:1\") {\n if (msg.payload.E2 === true) {\n return [{ payload: msg.payload.E1 }, null]; // E1 → Ausgang 1\n }\n else {\n return [null, { payload: msg.payload.E1 }];\n }\n}","outputs":2,"timeout":"0","noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":580,"wires":[["d86a41064c9daf66"],["66851263862684f4"]]},{"id":"04263f2d054cc2a1","type":"shelly-gen2-server","port":"10001","hostname":"unimatrix"},{"id":"d457a115.b395e","type":"mqtt-broker","name":"ZuHause","broker":"192.168.178.52","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":4,"keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<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:** [27 March 2025 19:55 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/6 "2025-03-27T19:55:42Z")

</div>

It is a common error to have two inputs to a function node and to combine or compare values from both inputs.  
Node-red can not do this. Each message is handled entirely without reference to the previous message.  
If you want to compare messages from two inputs you need to save one or both as context variables.

I am completely unable to understand what you are doing here

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f68c6b7cb704caf45c2c38f4ee452f55364975c.png)

Except that the red underline indicates that `event` has not been declared as a variable.

---

<div class="post-metadata">

**Author:** ![binderj1](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@binderj1](https://discourse.nodered.org/u/binderj1)\
**Post date:** [28 March 2025 17:02 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/7 "2025-03-28T17:02:25Z")

</div>

Hallo

```auto
let singlePush = null;
let doublePush = null;
let longePush = null;

if(msg.payload.component === "input:0"){
    event = msg.payload.info.event;
    switch(event){
        case "single_push":
            singlePush = msg;
            break;
        case "double_push":
            doublePush = msg;
            break;
        case "long_push":
            longePush = msg;
            break;
    }
}

node.send([singlePush, doublePush, longePush]);

```

mit diesem Code exrahiere ich aus einem JSON-Payload von einem Shelly-I4 einen Tastendruck.  
Ich bekomme eine Info welche Taste, und wie sie gedrückt wurde z.B. [input:3] für dritte Taste; [doublePush] für doppelt gedrückt. Aber das ist nicht mein Problem, das funktioniert. Mein Problem ist bei function-nod [Stop\_1]. Ich bekomme es nicht hin, dass beim oberen Ausgang "start" rauskommt wenn am Eingang "input:0" und "false" anliegen, bzw. am unteren Ausgang "stop" raus kommt wenn am Eingang "input:0" und "true" anliegen. Der Rest funktioniert.

---

<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 March 2025 17:17 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/8 "2025-03-28T17:17:23Z")

</div>

I do not speak German, only Google Translate.

```auto
My problem is with function-nod [Stop_1]. 
I can't get the upper output to output "start" 
   when the input contains "input:0" and "false," 
or the lower output to output "stop" 
   when the input contains "input:0" and "true."

```

```auto
if (msg.payload.component === "input:0") {
    if (msg.payload.E2 === "false") {
        return [null, { payload: msg.payload["stop"] }]; // E1 → Ausgang 1
    } else {
        return [{ payload: msg.payload["start"] }, null]; // E1 → Ausgang 2
    }
}

```

I _think_ that msg.payload.E2 comes from the node State.  
And that msg.payload.component comes from the node Push 0 when a single press occurs.

_If I am correct_, your function _cannot work_ because msg.payload.component and msg.payload.E2 do not both exist at the same time.

> [@jbudd](#):
>
> It is a common error to have two inputs to a function node and to combine or compare values from both inputs.  
> Node-red can not do this. Each message is handled entirely without reference to the previous message.

---

<div class="post-metadata">

**Author:** ![binderj1](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@binderj1](https://discourse.nodered.org/u/binderj1)\
**Post date:** [28 March 2025 17:36 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/9 "2025-03-28T17:36:18Z")

</div>

yes, here is der code of the [State-node]

```auto
if ((msg.payload.state === "opening") || (msg.payload.state === "closing")) {
  msg.payload.E2 = true;
} else if ((msg.payload.state === "open") || (msg.payload.state === "closed")) {
     msg.payload.E2 = false;
}

return [{ payload: msg.payload.E2}] ;

```

---

<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 March 2025 17:44 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/10 "2025-03-28T17:44:35Z")

</div>

I have seen your code but not your data.

Use debug nodes to show you and us the payload sent from State and Push 0 nodes.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/0523f85fdf7419e605d67ae75f8056f1b7c8650d.png)

---

<div class="post-metadata">

**Author:** ![binderj1](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@binderj1](https://discourse.nodered.org/u/binderj1)\
**Post date:** [29 March 2025 14:07 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/11 "2025-03-29T14:07:29Z")

</div>

The payloads of "Push 0" and "State"

 ![payload of state](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f130baf33708379cede23b8f3624ab8576bd0a76.png)

---

<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 March 2025 15:23 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/12 "2025-03-29T15:23:10Z")

</div>

I will try one more time to explain the issue as I see it.

#### The problem

I believe you are thinking of the `msg` object as a single pool of data.  
A message can add to or modify the properties and they remain there for you to reference at any time. **This is wrong.**

Instead, think of a msg object as a train travelling between stations.  
When it arrives at a station (a node) it has passengers on board. Some people get off, some others might get on (the msg object gets changed) Then it departs.  
Another train arrives. This has a completely different set of passengers.

A passenger on the first train cannot interact with a passenger on the second train.

#### Your flow:

Consider `Stop_1` node receives a message from `Push 0`:  
In this message` payload.component == "input: 0".`  
There is NO `msg.payload.E2` in this message.

First it tests `if (msg.payload.component === "input:0")`. **Yes, it is.**  
Next it tests `if (msg.payload.E2 === "false")` **msg.payload.E2 does not exist, so**  
`return [null, { payload: msg.payload["stop"] }]; // E1 → Ausgang 1` **can never happen**

Consider when it receives a message from `State`  
In this message `msg.payload == true` (or `false`)  
There is NO `msg.payload.component` in this message.

Stop\_1 tests `if (msg.payload.component === "input:0")`. **msg.payload.component does not exist so this function goes no further.**

#### How to fix it (perhaps)

Change `State` like this

```auto
let E2 = flow.get("E2") ?? false // set E2 from a context variable, default value is false
if ((msg.payload.state === "opening") || (msg.payload.state === "closing")) {
    E2 = true;
} 
else if ((msg.payload.state === "open") || (msg.payload.state === "closed")) {
    E2 = false;
}
flow.set("E2", E2) // save to the context variable

```

And `Stop_1` like this

```auto
const E2 = flow.get("E2") ?? false
if (msg.payload.component === "input:0") {
    if (E2 === "false") {
        msg.payload = "stop"
        return [null, msg]; 
    } else {
        msg.payload = "start"
        return [msg, null];  
    }
}

```

Remove the wire joining `State` and `Stop_1`

---

<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:** [27 June 2025 15:23 UTC](https://discourse.nodered.org/t/true-false-nicht-erkannt/96272/13 "2025-06-27T15:23:20Z")

</div>

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