Help with SWITCH node - is there a way to OR options?

This is a cut down example, but for the sake of showing the problem (question)

If msg.payload contains partly it goes to output 1
if msg.payload contains scattered it goes to output 2.
otherwise it goes to 3.

Ok. But for the sake of asking:
If I have a few things which are OR, can I save outputs and tests and put them all one one line?

Then it would be more like:
if msg.payload contains partly || scattered it goes to output 1

[{"id":"8469cd6d.ced9c","type":"switch","z":"703c61ac.837e1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"partly","vt":"str"},{"t":"cont","v":"scattered","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":430,"y":390,"wires":[["ee25707a.a4a21"],["ee25707a.a4a21"],["9760d9dd.5b4b2"]]}]

Three methods
1 use regex
2 use jsonata
3 use wires

Eg.

[{"id":"4fd0f248.01985c","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"hhh scattered hh","payloadType":"str","x":160,"y":2480,"wires":[["257a6f7a.a8c0d"]]},{"id":"3591244.8c0325c","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"hhh showers hh","payloadType":"str","x":150,"y":2520,"wires":[["257a6f7a.a8c0d"]]},{"id":"65c3ac83.00447c","type":"debug","z":"8d22ae29.7df6d","name":"Na Template","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":2520,"wires":[]},{"id":"257a6f7a.a8c0d","type":"switch","z":"8d22ae29.7df6d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$contains(payload, \"(rainy|showers)\")","vt":"jsonata"},{"t":"regex","v":"(scattered|partly)","vt":"str","case":false},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":380,"y":2520,"wires":[["65c3ac83.00447c"],["65c3ac83.00447c"],[]]}]

I have only used 1 debug add more to see routing.

1 Like

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