True / false nicht erkannt

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

[{"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":""}]

DANKE

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

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.

1 Like

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

return msg;

NOT

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

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.

Hallo

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. :sob:

[{"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":""}]

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

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

Hallo

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.

I do not speak German, only Google Translate.

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."
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.

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

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}] ;

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.

The payloads of "Push 0" and "State"

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

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

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