Switch node not capturing text

I am trying to utilize a switch node to eliminate messages that contain a certain text. In this case the text "cmnd".

The debug output displayed is coming from the 2nd output of the switch command.

What am I missing?

Did you check that the switch config does not have trailing spaces?

I don't understand why the "contains" option even exists since you can just as well use "matches regex" "cmnd"

Yeah, no trailing spaces. I even tried "/cmnd/"

Also, I DO have it stopping after first match.

The Regex did not work either.

Strange.

Can you post a flow with an inject node and switch to illustrate the problem?

Down at the bottom of the switch nodes options, do you have it set to:
checking all rules
or
stopping after first match?

Try with stopping after first match

It is set to stop after first match. Which is probably wrong not that I think about it because I want to ignore any messages that contain "cmnd" in the msg.topic, but that doesn't explain what I am seeing.

Can you put together a little example like an inject node with the data set in it, connected to the switch node and the to the debug nodes?

Also, what version of NR and are you running in Docker or using Home Assistant?

This works for me

[{"id":"fbf02cd4eca2427a","type":"tab","label":"Flow 6","disabled":false,"info":"","env":[]},{"id":"07b1a5c24776507c","type":"switch","z":"fbf02cd4eca2427a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"cont","v":"cmnd","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":180,"wires":[["1451b356b13e0dc2"],["e941fb9c777c4cb6"]]},{"id":"dfa527144af1a56c","type":"inject","z":"fbf02cd4eca2427a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"publish/cmnd/undefined/restart","payload":"","payloadType":"date","x":200,"y":180,"wires":[["07b1a5c24776507c"]]},{"id":"1451b356b13e0dc2","type":"debug","z":"fbf02cd4eca2427a","name":"debug 937","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":140,"wires":[]},{"id":"e941fb9c777c4cb6","type":"debug","z":"fbf02cd4eca2427a","name":"Otherwise","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":220,"wires":[]}]

I completely agree. It also worked for me in a new sample flow.

I will keep trying. If you look at my original post I show not only the switch command but the matching debug pic in the same output. I am not nutzzzz. :slight_smile:

What version of Node-RED are you using?

One other thing to try would be to replace the current switch node with a new one and see if the problem still occurs

I am current with node-red, and not in docker. I just deleted it and replaced it and now it is working.

I don't know what to say...

2 Likes

I’ve had something weird happen in the past where I replaced a node and things started working, that’s why I suggested you try it.

I’m glad that fixed your problem.

Have you got an export of the failing node? That would have been interesting to see.