I am a complete beginner with OpenHab and I using the OpenHABian 1.4.1 on my RaspberryPi and using the SmartMeter binding to read SML singal from smart meters. I am reading the data successfully and want to log them to a text file. I read about persistence but I only want to log the values of channels into 1 csv file.
I’m sorry, but the way persistence is build into openHAB the data is always saved into a database. Additionally the values can be queried for display in charts or display some standard calculations like average-since etc… All that is done in a way that the user needs only very limited knowledge of this feature!
Why are you relying on text-files?
This is why I miss the Logger Persistence add-on. I never did figure out why it got removed. I think it used log4j and no one wanted to update it to use log4j2.
That would have been perfect for this.
Anyway, the problem is even if that was still supported, it probably doesn’t work like you think it will. Each Item would get its own file and there would be two columns, a date/time and the value (i.e. time series data). I suspect you want one row with the states of a whole bunch of different Items which really isn’t how OH generates data so that isn’t really how persistence works.
What you could do is create a Rule that runs periodically and (assuming you are running on Linux) use something like:
// build up your row as a String
executeCommandLine("cat >> " + rowString + " myfile.csv")
You will probably have to mess with escaping commas and stuff like that.
But like Jürgen stated, you will have far more flexibility and capability if you use a real database and OH’s built in persistence.
I am currently using SmartMeter binding to read SML signal from an EasyMeter. The readings can be seen in the log alongside a lot of other unwanted logged data.
I wanted to log the channel values to my own csv file to have them easily accessible.
I was successful with persistence and created my own database and charts but readings saved with time and values for every item would actually be just perfect for this.