File Storage to a text file

I have a BME280 sending out Temp, humidity, pressure, heatindex, dewpoint, temp F, pressure Hg.
i'm only using 3 outputs
I have three gauges temperature 70.0 Humidity 29.6 and Pressure 30.1 i have added filters to eliminate trailing digits.
I send the data to the file node and the text file reads
70.12345678946
29.12318641684
30.16512565668
The data from the BME280 node goes to a change node then to the file node.
Can i place a function node between the change node and the file node to filter trailing digits.

Yes you can.

can you help with a formula for the function

[{"id":"72043f3d.827cc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"272eb534.be29ca","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":3,"width":"6","height":"3","gtype":"gage","title":"Temperature","label":"DEG F","format":"{{value | number :1}}","min":"32","max":"100","colors":["#00ff00","#e6e600","#ca3838"],"seg1":"90","seg2":"100","x":870,"y":100,"wires":[]},{"id":"90116c44.f3074","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":60,"wires":[["74df22fe.74f7fc"]]},{"id":"74df22fe.74f7fc","type":"Bme280","z":"72043f3d.827cc","name":"Pressure","bus":"1","address":"0x76","topic":"bme280","extra":true,"x":240,"y":60,"wires":[["fea6e758.ad9fb8","394f61c4.52fb5e","417ed70d.ece5f8","ed34257d.0fc748"]]},{"id":"262fcf86.9db6b","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":5,"width":"6","height":"3","gtype":"gage","title":"Barometric Pressure","label":"Hg","format":"{{value | number :1}}","min":0,"max":"100","colors":["#02f702","#e6e600","#ca3838"],"seg1":"","seg2":"","x":900,"y":180,"wires":[]},{"id":"fea6e758.ad9fb8","type":"change","z":"72043f3d.827cc","name":"Temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature_F","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":60,"wires":[["272eb534.be29ca","b4bf63bb.4fada","9a93c487.465258"]]},{"id":"394f61c4.52fb5e","type":"change","z":"72043f3d.827cc","name":"Humidity","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.humidity","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":180,"wires":[["2843b6a1.bc350a","6114affc.6f54b","9a93c487.465258"]]},{"id":"417ed70d.ece5f8","type":"change","z":"72043f3d.827cc","name":"Barometric Pressure","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.pressure_Hg","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":120,"wires":[["262fcf86.9db6b","9a93c487.465258","dc699213.a7ffa"]]},{"id":"2843b6a1.bc350a","type":"ui_gauge","z":"72043f3d.827cc","name":"","group":"5d511d53.994404","order":4,"width":"6","height":"3","gtype":"gage","title":"Humdity","label":"%","format":"{{value | number :1}}","min":0,"max":"100","colors":["#00ff00","#e6e600","#ca3838"],"seg1":"40","seg2":"80","x":860,"y":260,"wires":[]},{"id":"b4bf63bb.4fada","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":60,"wires":[]},{"id":"6114affc.6f54b","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":220,"wires":[]},{"id":"dc699213.a7ffa","type":"debug","z":"72043f3d.827cc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":140,"wires":[]},{"id":"9a93c487.465258","type":"file","z":"72043f3d.827cc","name":"","filename":"/home/pi/dynotests/dynorun.log","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":770,"y":400,"wires":[[]]},{"id":"d2aef49b.9bbe88","type":"file","z":"72043f3d.827cc","name":"","filename":"/home/pi/dynotests/dynorun.log","appendNewline":true,"createDir":false,"overwriteFile":"delete","encoding":"none","x":750,"y":460,"wires":[[]]},{"id":"aaf4dc78.c238a","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":400,"wires":[["9a93c487.465258"]]},{"id":"f9bead26.2ce08","type":"inject","z":"72043f3d.827cc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":460,"wires":[["d2aef49b.9bbe88"]]},{"id":"ed34257d.0fc748","type":"debug","z":"72043f3d.827cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1100,"y":40,"wires":[]},{"id":"5d511d53.994404","type":"ui_group","name":"Weather","tab":"70eb2da0.452ad4","order":2,"disp":true,"width":"6","collapse":false},{"id":"70eb2da0.452ad4","type":"ui_tab","name":"LANGE RACING","icon":"dashboard","disabled":false,"hidden":false}]

Can you share your flow and screen shot the data please?

(Need more info to assist)

Edit...
You beat me to it :joy:

Hi @dirtydredrt

In JavaScript, numbers have a function on them called toFixed that will convert them to a String with the required number of decimal places.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

In your case, you'd need a Function that calls toFixed(1) (to match what you've done with the gauges) on each of the properties.

Without more details on what you message looks like, it is hard to be any more specific.

@dirtydredrt

the issue I see is you only send the payload to the file. How can you differentiate each value?

Also, this data will be a simple list of number and not really great for other uses (I imagine you are going to load the values into excel or something else later?)


A better solution would be to join all three values and create a CSV of data.

Is that of interest?

This is part of a engine dyno that Colin help me create.
At the end of the run i press a button on the dashboard and get th results of the run
start RPM
Finish RPM
Date time
weather info temp humidity and pressure
the output file is OK, I would like to organize the output like
Date time
weather info
Start run RPM
Finish RPM
Run time

If needed i can copy my complete flow if that helps

No thanks :laughing:

Here is a small demo you can build upon.

[{"id":"51c8307b.a00d5","type":"function","z":"ddf1cb1b.a8f668","name":"fomrat values","func":"var p = {\n    temperature: msg.payload.temperature_F.toFixed(2),\n    humidity: msg.payload.humidity.toFixed(2),\n    pressure: msg.payload.pressure_Hg.toFixed(2)\n}\nmsg.payload = p;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":340,"wires":[["d7c152a1.a6876"]]},{"id":"d7c152a1.a6876","type":"csv","z":"ddf1cb1b.a8f668","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"temperature,humidity,pressure","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":470,"y":340,"wires":[["e741916.0221a7"]]}]

Info

Since the Bme280 has all properties in the msg, instead splitting the values out and writing them individually to the file, it is probably a better bet to write all values at once.

Look at the function code & what it does (add a debug node to the function output)
Look at the column names entered in the CSV node.
Look at the output of the CSV node

You should see how it fits together.

this is my run file```
test run

40
400
4 / 7 / 2021 10:42:25
73.328
3822

Thanks Steve-Mcl
i will give it a go

you have fixed the readout .00
Can I add Headings in the function
This id my file now
New file data
4
40
72.91, 28.43, 30.09
can we add a header
temp 72.91
Humidity 28.43
Pressure 30.09