Virtual sensor for Homeassistant - Fuelio - Read from file .csv data

Hi.
I have a problem with reading data from a .csv file, in short I want to use Nodred to create virtual sensors for Homeassistant from data downloaded from the fuelio.csv file
Fuelio is a program - a log of vehicle refueling. (save file to *.csv)
Homeasistant - will display current data on sensors after synchronizing the file with fuelio.

Currently, I have prepared a fuelio file which is automatically transferred to the nodred server after synchronization.

Now nodered should read the data from the file and update the sensor status in Homeassistant.

in the ssh console the command works:
cat config/fuelio/fuelio.csv | grep '"*"' | cut -d "," -f 2 | awk 'NR==6' | sed 's/"//g'

returning data, e.g. about the current mileage: 117850 (km)

but I don't know if this command can be used in nodered?
I tried various functions but to no avail.


I found the command to read from a file but I don't know how to get past this error - there is no appropriate library...

Hello @ozmtox and welcome to the forum.

I am puzzled that you quote a bash shell command which works but your screen capture of [part of] a file pathname seems to be on Windows.

I presume your attempt to read the file using a function node gives an error.
Node-red has a read-file node (as you already know) which opens and reads a file, then you can parse the data within Node-red.

Or you could use an exec node to run the cat | grep | cut | awk | sed command. (Impressive use of every line editor known to man :grinning: ).

Hello @jbudd
Thank you for the guidance, it works great with the EXEC node, but it refers to a short executable *.sh file containing bash commands (it works, but it's not very elegant :wink: )

Can you tell me what I should enter in the FUNCTION node to output only one value as shown in the screenshot?

ok, a few minutes later... :slight_smile:
I found the solution!

Function need :

var v = {}
v.value = msg.payload[6].col2
msg.payload = v.value
return msg;

Screenshot_3

If you click that "Copy path" button (and paste it somewhere) you will see that the data you outlined is msg.payload[6].col2

Assuming that it's always array element 6 that you need, in a function you could have msg.payload = msg.payload[6].col2
Or, using standard nodes rather than resorting to a function a change node can easily move msg.payload[6].col2 to msg.payload

Note: Looking at your debug output and the original Bash command line, I'm not convinced that your awk 'NR==6' retrieves the same line from the CSV file as msg.payload[6]

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