Switch Node and Jsonata and/or range?

Guys,

Just looking to simplify some flows and wondering if i could use the switch node

Essentially i want to feed in a Month number (between 1 and 12) and then based on the value(s) switch to one of the outputs. So for instance i could have

Month number = 1,2,3,11,12
Month Number = 6,7,8
Month number = 4,5,9,10

If the switch matched any of out the blocks i would want them to go out a specific output - so if it saw 1 or 2 or 3 - it would send it out Output 1

4 or 5 or 10 would go out output 3 etc.

I looked at contains as an option - but that seems to be string only ?

Obviously i could do it in a function node fairly easily - just looking at ease of ongoing maintenance by using a provided node

Craig

As usual find it 5 minutes after finish looking - i think its because i am scared of JSONATA !!

Anyway - anyone else looking

You can select the switch node as a Jsonata expression and then just put in

msg.month = 1 or msg.month = 2 etc etc

Example flow below

[{"id":"4b27b7b.36083c8","type":"inject","z":"2a720386.f4226c","name":"Force","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":190,"y":280,"wires":[["f7b2e05e.f958f8"]]},{"id":"2f5ae7e2.12b908","type":"debug","z":"2a720386.f4226c","name":"output","active":true,"console":"false","complete":"true","x":782,"y":208,"wires":[]},{"id":"47a4278c.65ce68","type":"function","z":"2a720386.f4226c","name":"timeConvert","func":"if ( !msg.timestamp ) msg.timestamp = Math.round(+new Date());\n\nvar dt = new Date(msg.timestamp);\nvar msg = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":586,"y":208,"wires":[["2f5ae7e2.12b908","74912318.2556bc"]]},{"id":"f7b2e05e.f958f8","type":"function","z":"2a720386.f4226c","name":"set timestamp","func":"msg.timestamp=1376763133 * 1000;\nreturn msg;","outputs":1,"x":374,"y":280,"wires":[["47a4278c.65ce68"]]},{"id":"3bde431b.451a3c","type":"inject","z":"2a720386.f4226c","name":"Force","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":190,"y":208,"wires":[["47a4278c.65ce68"]]},{"id":"74912318.2556bc","type":"switch","z":"2a720386.f4226c","name":"Month Test","property":"month","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"msg.month = 1 or msg.month = 2 or msg.month = 3 or msg.month = 11 or msg.month = 12","vt":"jsonata"},{"t":"jsonata_exp","v":"msg.month = 4 or msg.month = 5 or msg.month = 9 or msg.month = 10","vt":"jsonata"},{"t":"jsonata_exp","v":"msg.month = 6 or msg.month = 7 or msg.month = 8","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":3,"x":820,"y":280,"wires":[["131a9c29.c61804"],["7ce0632d.52dcfc"],["2fd3aeac.909352"]]},{"id":"131a9c29.c61804","type":"debug","z":"2a720386.f4226c","name":"Summer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1020,"y":240,"wires":[]},{"id":"7ce0632d.52dcfc","type":"debug","z":"2a720386.f4226c","name":"Autumn/Spring","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":280,"wires":[]},{"id":"2fd3aeac.909352","type":"debug","z":"2a720386.f4226c","name":"Winter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":320,"wires":[]}]

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