My switch node does not what I expect

I have the following simple flow and I would expect that my signal passes output 1 of the switch node when my payload of "Plugged" is 1.

[{"id":"0b7e0b7d175bbb22","type":"debug","z":"7f3f8d551243a1af","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":180,"wires":[]},{"id":"70985d276f19ff97","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":0}","payloadType":"json","x":120,"y":220,"wires":[["aaafffd89118fb89"]]},{"id":"64112c84e991c110","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":1}","payloadType":"json","x":120,"y":260,"wires":[["aaafffd89118fb89"]]},{"id":"aaafffd89118fb89","type":"split","z":"7f3f8d551243a1af","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","property":"payload","x":330,"y":180,"wires":[["89cf236158ce97e3","0b22ed02a6139db1"]]},{"id":"89cf236158ce97e3","type":"switch","z":"7f3f8d551243a1af","name":"plugged","property":"payload.Plugged","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":180,"wires":[["0b7e0b7d175bbb22"],["6b3895cde63e7855"]]},{"id":"0b22ed02a6139db1","type":"debug","z":"7f3f8d551243a1af","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":260,"wires":[]},{"id":"6b3895cde63e7855","type":"debug","z":"7f3f8d551243a1af","name":"debug 20","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":220,"wires":[]}]

But it does not and comes out of output 2, regardless of the value. Can someone help me out here?

because you have a split node that is operating on an object, the value is set in payload (that is evident by debug node output after the split)

your switch should be checking payload not payload.Plugged - thats why it does NOT find a 1 in payload.Plugged because the split moved the Plugged value to payload and the key name to msg.key (set the debug attached to split node to "show FULL msg object")

Why do you have the split node anyhow? what are you actually trying to achieve?

It will be part of something more, but at first I wanted to solve this problem. What you wrote, this works.
I want to release a log flow into a text file when "Plugged" is 1 and stop it when it is 0, but still I have no idea how to realize this. The log flow is simple line by line text. How can I combine my Plugged-Signal with the log flow to control it.
I see, the split node is not necessary, this was legacy.
Iam searching for a function instead of the comment/debug node.

[{"id":"f3d2023a47cd6b86","type":"file","z":"7f3f8d551243a1af","name":"WB-log.csv","filename":"/mnt/nas/homeassistant/Zoe-Daten/WB-log.csv","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"utf8","x":630,"y":180,"wires":[[]]},{"id":"0b7e0b7d175bbb22","type":"debug","z":"7f3f8d551243a1af","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":180,"wires":[]},{"id":"128a2b5bda1761c2","type":"mqtt in","z":"7f3f8d551243a1af","name":"WiCAN Zoe","topic":"wican/7c2c67b3dbc1/auto/plugged","qos":"2","datatype":"json","broker":"5c944a233ddbd024","nl":false,"rap":true,"rh":0,"inputs":0,"x":130,"y":260,"wires":[["89cf236158ce97e3"]]},{"id":"70985d276f19ff97","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":0}","payloadType":"json","x":120,"y":300,"wires":[["89cf236158ce97e3"]]},{"id":"64112c84e991c110","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":1}","payloadType":"json","x":120,"y":340,"wires":[["89cf236158ce97e3"]]},{"id":"89cf236158ce97e3","type":"switch","z":"7f3f8d551243a1af","name":"plugged","property":"payload.Plugged","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":260,"wires":[["0b7e0b7d175bbb22"],[]]},{"id":"206552ff0bc3f298","type":"inject","z":"7f3f8d551243a1af","name":"Log","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/log","payload":"blablabla","payloadType":"str","x":110,"y":180,"wires":[["f3d2023a47cd6b86"]]},{"id":"ebb729a3b5ed2090","type":"comment","z":"7f3f8d551243a1af","name":"","info":"","x":440,"y":180,"wires":[]},{"id":"5c944a233ddbd024","type":"mqtt-broker","name":"Raspi3","broker":"192.168.178.2","port":1883,"clientid":"","autoConnect":true,"usetls":false,"protocolVersion":4,"keepalive":60,"cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

I assume since you named the file *.csv, you want the object in the mqtt payload to be converted into well formatted CSV row data. In which case, I would suggest adding a timestamp, push it through a CSV node, then pipe that into the file.

e.g:

[{"id":"f3d2023a47cd6b86","type":"file","z":"6e5ea1e6617b5df3","name":"WB-log.csv","filename":"/mnt/nas/homeassistant/Zoe-Daten/WB-log.csv","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"utf8","x":1010,"y":440,"wires":[[]]},{"id":"70985d276f19ff97","type":"inject","z":"6e5ea1e6617b5df3","name":"Plugged 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":0}","payloadType":"json","x":300,"y":480,"wires":[["89cf236158ce97e3"]]},{"id":"64112c84e991c110","type":"inject","z":"6e5ea1e6617b5df3","name":"Plugged 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":1}","payloadType":"json","x":300,"y":520,"wires":[["89cf236158ce97e3"]]},{"id":"89cf236158ce97e3","type":"switch","z":"6e5ea1e6617b5df3","name":"plugged","property":"payload.Plugged","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":520,"y":440,"wires":[["8d8b59b16522efa1"],[]]},{"id":"d98219ab6edb5d45","type":"csv","z":"6e5ea1e6617b5df3","name":"","spec":"rfc","sep":",","hdrin":"","hdrout":"once","multi":"one","ret":"\\r\\n","temp":"ts,Plugged","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":830,"y":440,"wires":[["f3d2023a47cd6b86","2478386691d1b30c"]]},{"id":"8d8b59b16522efa1","type":"change","z":"6e5ea1e6617b5df3","name":"add ts","rules":[{"t":"set","p":"payload.ts","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["d98219ab6edb5d45","6ee950baa9b75cee"]]},{"id":"6ee950baa9b75cee","type":"debug","z":"6e5ea1e6617b5df3","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":520,"wires":[]},{"id":"2478386691d1b30c","type":"debug","z":"6e5ea1e6617b5df3","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":520,"wires":[]}]

You got my legacy parts again, no, ist is a simple text file and contains a time stamp. I renamed it to WB.log. Here are some typical lines

2025-02-25T23:59:53.842Z LM MVAR current_SF_mA 10.000000
2025-02-25T23:59:53.846Z LM MVAR current_bat -317.548737
2025-02-25T23:59:53.851Z LM MVAR I_AC_CurrentB 38.000000
2025-02-25T23:59:53.854Z LM MVAR current_SF_mA 10.000000
2025-02-25T23:59:53.858Z LM MVAR current_bat -317.548737
2025-02-25T23:59:53.863Z LM MVAR I_AC_CurrentC 37.000000
2025-02-25T23:59:53.866Z LM MVAR current_SF_mA 10.000000

I simply want to suppress writing to the file when "Plugged" is 0. Otherwise I get too big files.

which is what the switch node does. Kinda. It only permits a msg to pass when payload.Plugged == 1


to avoid further confusion, rathr than little examples of code or pseudo examples, try explaining exactly what you want to achieve. for example, the values in that "typical log" were never stated before now and it is unclear from previous messages anything other than a msg with payload.Plugged == 1 should be logged,

I simply want to suppress writing the data from Log to the file wb.log when "Plugged" is 0 and enable it when "Plugged" is 1.

[{"id":"f3d2023a47cd6b86","type":"file","z":"7f3f8d551243a1af","name":"WB.log","filename":"/mnt/nas/homeassistant/Zoe-Daten/WB.log","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"utf8","x":620,"y":180,"wires":[[]]},{"id":"0b7e0b7d175bbb22","type":"debug","z":"7f3f8d551243a1af","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":260,"wires":[]},{"id":"70985d276f19ff97","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":0}","payloadType":"json","x":120,"y":300,"wires":[["89cf236158ce97e3"]]},{"id":"64112c84e991c110","type":"inject","z":"7f3f8d551243a1af","name":"Plugged 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":1}","payloadType":"json","x":120,"y":340,"wires":[["89cf236158ce97e3"]]},{"id":"89cf236158ce97e3","type":"switch","z":"7f3f8d551243a1af","name":"plugged","property":"payload.Plugged","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":260,"wires":[["0b7e0b7d175bbb22"],[]]},{"id":"206552ff0bc3f298","type":"inject","z":"7f3f8d551243a1af","name":"Log","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/log","payload":"blablabla","payloadType":"str","x":110,"y":180,"wires":[["f3d2023a47cd6b86"]]}]

Maybe the solution is a function node but I am absolutely not familiar with JavaScript.

Since that is exactly what the switch does in my example and it doesnt "work" for you, I think there is more to this than what you say.

Reading between the lines, you potentially need something like "whenever Plugged == 1, allow logging (regardless of where it comes from) to the CSV file"?

If yes, then you would simply store the value of Plugged in a context variable then use a switch to see if the value of the context variable is 1 and permit the logging to occur.

e.g.
chrome_xGuFESkkGv

[{"id":"70985d276f19ff97","type":"inject","z":"2f29e2966e4a81bb","name":"Plugged 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":0}","payloadType":"json","x":340,"y":2060,"wires":[["a6fefd1bea0a191c"]]},{"id":"64112c84e991c110","type":"inject","z":"2f29e2966e4a81bb","name":"Plugged 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"wican/7c2c67b3dbc1/auto/plugged","payload":"{\"Plugged\":1}","payloadType":"json","x":340,"y":2100,"wires":[["a6fefd1bea0a191c"]]},{"id":"206552ff0bc3f298","type":"inject","z":"2f29e2966e4a81bb","name":"Log","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"cfos_mqtt/log","payload":"","payloadType":"date","x":330,"y":2000,"wires":[["853293658630990d"]]},{"id":"a6fefd1bea0a191c","type":"change","z":"2f29e2966e4a81bb","name":"","rules":[{"t":"set","p":"AllowLogs","pt":"global","to":"payload.Plugged","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2080,"wires":[[]]},{"id":"853293658630990d","type":"switch","z":"2f29e2966e4a81bb","name":"AllowLogs == 1?","property":"AllowLogs","propertyType":"global","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":2000,"wires":[["fd4b95c4b3c2b3c4"]]},{"id":"fd4b95c4b3c2b3c4","type":"debug","z":"2f29e2966e4a81bb","name":"to log ->","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":750,"y":2000,"wires":[]}]

Global vars... That's a good solution. I didn't know about them nor used them before.
Thank you for your patience.

Possibly more 'the node red way' would be to use a node-red-contrib-simple-gate to block or allow the messages through, using the plugged value to control it. Then there are no global vars with all the problems that they can introduce.