Write data periodically to a CSV file

Hi,

using openhab 1.9 and I would like to get some datapoints periodically written to a CSV file which I can then analyze in Excel.

Have not found an example yet and the logging documentation is not very intuitive and guiding to the point. Has anyone done this before and might share how?

TY
Claus

File access from OH is very awkard.
Node-red has a csv node

https://nodered.org/
and

In OH 1.x there was a a Logging Persistence add-on. See https://github.com/openhab/openhab1-addons/wiki/Logging-Persistence

You can configure it to log values out in a CSV format, though it will be just Item.name and Item.state.

If you need lots of values on the same line, and you are running on a Linux, I’d use executeCommandLine to append each row to a file from a Rule.

    // build up the row CSV string
    executeCommandLine("echo " + row + " >> /path/to/csv/file")

If you were on OH 2, I could probably help you figure out how to configure log4j2’s logger to output CSV. I know it has a supported CSV appender.

NOTE: the Logger Persistence add-on is not available in OH 2.

1 Like

On OH2 under windows you need a little workaround.

Create a bat-file (maybe name echotofile.bat) somewhere with this content:

echo %1 >> %2

you can call it via

executeCommandLine("C:\\OpenHab2\\executeable\\echotofile.bat " + "xx,yy,zz" + " C:\\OpenHAB2\\userdata\\logs\\logfile.csv", 1000)

xx,yy,zz is a line which will be written to the file given by parameter 2 (C:\OpenHAB2\userdata\logs\logfile.csv)

2 Likes