How to change the order of CSV values written to a file

I am using NodeRed with HomeSeer. In NodeRed I read two devices of a rainmeter, the daily and cumulative precipitation. In NodeRed I generate a timestamp and once a day I write the three values to a file.
Now I would like to have the three values in a specific order and the timestamp first.
This is what I have:

The CSV output is:

30-12-2020 14:00:33node: f5ed2ce5.4fe4adaily : msg.payload : string[30]

"0.793,0.0,30-12-2020 13:57:42↵"

Here is my flow for this:

 [{"id":"c7e544f6.db5568","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"f5ed2ce5.4fe4a","type":"debug","z":"c7e544f6.db5568","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":950,"y":320,"wires":[]},{"id":"aa2f533d.fce7d","type":"hs-device","z":"c7e544f6.db5568","name":"Regenmeter cumulatief","device":"436","server":"ab4d84fb.9a1c88","feature":"438","reportonstartup":true,"x":170,"y":200,"wires":[["e769b1d6.eb9c8"]]},{"id":"56ba4997.ce12a8","type":"change","z":"c7e544f6.db5568","name":"Now","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now('[D01]-[M01]-[Y0001] [H01]:[m01]:[s01]', '+0100')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["8751ac75.7d2ac"]]},{"id":"5aba7d4d.0378f4","type":"inject","z":"c7e544f6.db5568","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"05 00 * * *","once":false,"onceDelay":0.1,"topic":"current","payload":"","payloadType":"date","x":170,"y":120,"wires":[["56ba4997.ce12a8"]]},{"id":"e769b1d6.eb9c8","type":"function","z":"c7e544f6.db5568","name":"topic cum","func":"//read payload\n\nvar stringValue = msg.payload.value;\n\n//convert string to float to 3 decimal places\nvar floatValue = parseFloat(stringValue).toFixed(3);\n\n//set and return payload\nmsg.topic = \"cum\"\nmsg.payload = floatValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":200,"wires":[["389b42b2.0e430e"]]},{"id":"8751ac75.7d2ac","type":"function","z":"c7e544f6.db5568","name":"topic tijd","func":"//read payload\n\nvar stringValue = msg.payload;\n\n//set and return payload\nmsg.topic = \"tijd\";\nmsg.payload = stringValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":120,"wires":[["389b42b2.0e430e"]]},{"id":"389b42b2.0e430e","type":"join","z":"c7e544f6.db5568","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":200,"wires":[["27a9715.7c4038e"]]},{"id":"6cb883a7.77ac8c","type":"file","z":"c7e544f6.db5568","name":"to file","filename":"/home/pi/Metingen/rain.txt","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":1010,"y":200,"wires":[[]]},{"id":"9c966191.ce7eb","type":"hs-device","z":"c7e544f6.db5568","name":"Regenmeter dagelijks","device":"300","server":"ab4d84fb.9a1c88","feature":0,"reportonstartup":true,"x":160,"y":280,"wires":[["14d3efca.e617a"]]},{"id":"14d3efca.e617a","type":"function","z":"c7e544f6.db5568","name":"topic daily","func":"//read payload\n\nvar stringValue = msg.payload.value;\n\n//convert string to float to 1 decimal places\nvar floatValue = parseFloat(stringValue).toFixed(1);\n\n//set and return payload\nmsg.topic = \"daily\"\nmsg.payload = floatValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":280,"wires":[["389b42b2.0e430e"]]},{"id":"27a9715.7c4038e","type":"csv","z":"c7e544f6.db5568","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":850,"y":200,"wires":[["f5ed2ce5.4fe4a","6cb883a7.77ac8c"]]},{"id":"ab4d84fb.9a1c88","type":"hs-server","name":"RPi4-HS4","host":"192.168.1.20","port":"8080"}]

Is there a way to change the order?
Thanks for any hint.
-- Cor --

Add a change node after the join to reorder the items

or use a function node instead and set order.

[{"id":"9af07b82.dfe52","type":"join","z":"a67a8284.324fe","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":200,"wires":[["b92f7ed8.fd5d9","6b25aced.283cbc"]]},{"id":"3e38352e.d3c6aa","type":"function","z":"a67a8284.324fe","name":"topic cum","func":"//read payload\n\nvar stringValue = msg.payload.value;\n\n//convert string to float to 3 decimal places\nvar floatValue = parseFloat(stringValue).toFixed(3);\n\n//set and return payload\nmsg.topic = \"cum\"\nmsg.payload = floatValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":200,"wires":[["9af07b82.dfe52"]]},{"id":"2f649a7d.cc9ef6","type":"function","z":"a67a8284.324fe","name":"topic tijd","func":"//read payload\n\nvar stringValue = msg.payload;\n\n//set and return payload\nmsg.topic = \"tijd\";\nmsg.payload = stringValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":120,"wires":[["9af07b82.dfe52"]]},{"id":"7568f758.3545a","type":"function","z":"a67a8284.324fe","name":"topic daily","func":"//read payload\n\nvar stringValue = msg.payload.value;\n\n//convert string to float to 1 decimal places\nvar floatValue = parseFloat(stringValue).toFixed(1);\n\n//set and return payload\nmsg.topic = \"daily\"\nmsg.payload = floatValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":280,"wires":[["9af07b82.dfe52"]]},{"id":"b92f7ed8.fd5d9","type":"debug","z":"a67a8284.324fe","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":950,"y":320,"wires":[]},{"id":"6b25aced.283cbc","type":"function","z":"a67a8284.324fe","name":"","func":"msg.payload = msg.payload.tijd+\",\"+msg.payload.cum+\",\"+msg.payload.daily+\"\\n\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":840,"y":200,"wires":[["b92f7ed8.fd5d9"]]},{"id":"eede7c19.974728","type":"inject","z":"a67a8284.324fe","name":"","props":[{"p":"payload.value","v":"7.345","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":330,"y":200,"wires":[["3e38352e.d3c6aa"]]},{"id":"d599ced1.16f598","type":"change","z":"a67a8284.324fe","name":"Now","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now('[D01]-[M01]-[Y0001] [H01]:[m01]:[s01]', '+0100')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["2f649a7d.cc9ef6"]]},{"id":"bed662f4.bdf738","type":"inject","z":"a67a8284.324fe","name":"","props":[{"p":"payload.value","v":"0","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":330,"y":260,"wires":[["7568f758.3545a"]]},{"id":"8dda4d07.fd9d1","type":"inject","z":"a67a8284.324fe","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"current","payload":"","payloadType":"date","x":160,"y":120,"wires":[["d599ced1.16f598"]]}]

Thank you both for your quick reaction!
It works fine now.

I think its as simple as defining the order of your comma seperated values
in the Columns setting of the CSV node.

Example:
image

2 Likes