Read file and split line into separate values

I want to read a Sensirion log file and split the two measured values into two separate values to work with. The two last values in the line is temperature and humidity.


So far i have manage by the forum to read the last line in the log file, but I'm not able to find any examples to get the split function working on the separator used in the log file.

I have tried but I think I'm far from any solution

[{"id":"fa6e2728cb6426c9","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"73e4e16.4d9742","type":"inject","z":"fa6e2728cb6426c9","name":"Inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":100,"wires":[["9991d13193c67668"]]},{"id":"9991d13193c67668","type":"file in","z":"fa6e2728cb6426c9","name":"","filename":"C:\\Users\\perha\\data_logging\\2024-09-28_23-22-06-SHT4x_261087770.edf","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":810,"y":100,"wires":[["892ca195.f46cb"]]},{"id":"892ca195.f46cb","type":"csv","z":"fa6e2728cb6426c9","name":"","spec":"rfc","sep":" ","hdrin":false,"hdrout":"none","multi":"mult","ret":"\\r\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":true,"x":590,"y":240,"wires":[["dab29fbd.3cc03"]]},{"id":"dab29fbd.3cc03","type":"change","z":"fa6e2728cb6426c9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[[-1..-1]]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":240,"wires":[["9d223cc0.c2a008"]]},{"id":"9d223cc0.c2a008","type":"csv","z":"fa6e2728cb6426c9","name":"","spec":"rfc","sep":",","hdrin":false,"hdrout":"none","multi":"one","ret":"\\r\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":true,"x":930,"y":240,"wires":[["df6d6c66.b6c4e","14ddc802.a51cb8"]]},{"id":"14ddc802.a51cb8","type":"debug","z":"fa6e2728cb6426c9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":240,"wires":[]},{"id":"df6d6c66.b6c4e","type":"split","z":"fa6e2728cb6426c9","name":"","splt":"\\r","spltType":"str","arraySplt":"1","arraySpltType":"len","stream":false,"addname":"","property":"payload","x":1150,"y":340,"wires":[["3ba2aff1.e8af5"]]},{"id":"3ba2aff1.e8af5","type":"debug","z":"fa6e2728cb6426c9","name":"spltted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1310,"y":340,"wires":[]}]

Please use triple backticks

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

here is an example of how to get the last line values into a payload object

[{"id":"73e4e16.4d9742","type":"inject","z":"fa6e2728cb6426c9","name":"Inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":100,"wires":[["0edd8736d88f90c4"]]},{"id":"0edd8736d88f90c4","type":"template","z":"fa6e2728cb6426c9","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"larry curly mo 20 40\nlarry curly mo 20 40\nlarry curly mo 20 40","output":"str","x":440,"y":100,"wires":[["892ca195.f46cb"]]},{"id":"892ca195.f46cb","type":"csv","z":"fa6e2728cb6426c9","name":"","spec":"rfc","sep":" ","hdrin":false,"hdrout":"none","multi":"mult","ret":"\\r\\n","temp":"value1,value2,value3,temp,humidity","skip":"0","strings":true,"include_empty_strings":"","include_null_values":true,"x":590,"y":100,"wires":[["a5cc343d4581e9bf"]]},{"id":"a5cc343d4581e9bf","type":"change","z":"fa6e2728cb6426c9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[-1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":100,"wires":[["14ddc802.a51cb8"]]},{"id":"14ddc802.a51cb8","type":"debug","z":"fa6e2728cb6426c9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":140,"wires":[]}]

The objects names can be set by adding them in the column field of the csv node, or a msg.columns with a list of names in a string format separated by commas.

Thank you.

This helped me a lot. I managed to put together a flow that can display the values. But I'm not sure if I do in an correct/efficient way, but it works.

[{"id":"73025f76c5176754","type":"tab","label":"Flow 7","disabled":false,"info":"","env":[]},{"id":"de776e03da5326b7","type":"inject","z":"73025f76c5176754","name":"Inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":210,"y":80,"wires":[["474c07f0ddadf6d5"]]},{"id":"09f41fc33cea38e7","type":"csv","z":"73025f76c5176754","name":"","spec":"rfc","sep":"\\t","hdrin":false,"hdrout":"none","multi":"mult","ret":"\\r\\n","temp":"value1,DateAndTime,Temp,Humidity","skip":"0","strings":true,"include_empty_strings":"","include_null_values":true,"x":350,"y":160,"wires":[["1a97f631df74ad6c"]]},{"id":"1a97f631df74ad6c","type":"change","z":"73025f76c5176754","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[-1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":160,"wires":[["72e6bd7e1acb3fa7","56b59f026932419e"]]},{"id":"72e6bd7e1acb3fa7","type":"debug","z":"73025f76c5176754","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":80,"wires":[]},{"id":"56b59f026932419e","type":"split","z":"73025f76c5176754","name":"","splt":"","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":710,"y":160,"wires":[["ccc451ecdd83c41c"]]},{"id":"aa2a8fd977695788","type":"change","z":"73025f76c5176754","name":"to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":120,"wires":[["dbea4151a8816bb6"]]},{"id":"ccc451ecdd83c41c","type":"switch","z":"73025f76c5176754","name":"route","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":830,"y":160,"wires":[["aa2a8fd977695788"],["215ff6de4a3a00b1"],["9853565d842f00b5"],["db7318c7aec6a8c2"]]},{"id":"dbea4151a8816bb6","type":"debug","z":"73025f76c5176754","name":"FirstValue","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":100,"wires":[]},{"id":"215ff6de4a3a00b1","type":"debug","z":"73025f76c5176754","name":"DateAndTime","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1280,"y":140,"wires":[]},{"id":"f965559660cae979","type":"debug","z":"73025f76c5176754","name":"Temperature","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":180,"wires":[]},{"id":"5062750292861f35","type":"debug","z":"73025f76c5176754","name":"Humidity","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":220,"wires":[]},{"id":"9853565d842f00b5","type":"change","z":"73025f76c5176754","name":"to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":200,"wires":[["f965559660cae979","949ad32ec26fec07"]]},{"id":"db7318c7aec6a8c2","type":"change","z":"73025f76c5176754","name":"to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":320,"wires":[["5062750292861f35","2906f8421b00c60e"]]},{"id":"949ad32ec26fec07","type":"ui_gauge","z":"73025f76c5176754","name":"","group":"4cb77f9e1cabda6f","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":1230,"y":320,"wires":[]},{"id":"2906f8421b00c60e","type":"ui_gauge","z":"73025f76c5176754","name":"","group":"4cb77f9e1cabda6f","order":1,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":1240,"y":440,"wires":[]},{"id":"474c07f0ddadf6d5","type":"template","z":"73025f76c5176754","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"1727629863.134701\t2024-09-29T19:11:03.134701+02:00\t23.380737\t35.794461\n1727629863.633744\t2024-09-29T19:11:03.633744+02:00\t23.410110\t36.204547\n1727629864.135420\t2024-09-29T19:11:04.135420+02:00\t23.428802\t36.471580\n1727629864.631990\t2024-09-29T19:11:04.631990+02:00\t23.407440\t36.528801\n","output":"str","x":340,"y":80,"wires":[["09f41fc33cea38e7"]]},{"id":"4cb77f9e1cabda6f","type":"ui_group","name":"TempOgFukt","tab":"f0939ec229419f89","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f0939ec229419f89","type":"ui_tab","name":"Sensirion","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

Looks OK to me, just no need for change nodes to convert to number as the csv node does this.

In your switch node you use string and numbers in comparisons , parts.index would be a number,. May be netter using parts.key and use the object property names.

You could also grab the last line of the text file using tail command in a exec node, Tail command in Linux with examples - GeeksforGeeks , this may be more effivient if you text file is very long.