I want to add a record to a csv file each time when my item is updated.
I have a rule with action:
...
then
val String ms_val = String_MS_raw.state.toString
executeCommandLine(String::format("echo \"%2$s;%1$s\" >> /media/data/big_storage/Temp/meteostation.csv", ms_val, now))
In log it says
17:47:26.759 [DEBUG] [AbstractDatagramChannelBinding:1389 ] - Received meteostation;1116;273;23;36 on the listener port from /0.0.0.0:4321
17:47:26.759 [DEBUG] [i.s.RegExTransformationService:42 ] - about to transform āmeteostation;1116;273;23;36ā by the function āmeteostation;(.*)ā
17:47:26.760 [DEBUG] [t.protocol.internal.UDPBinding:276 ] - transformed response is ā1116;273;23;36ā
17:47:26.760 [DEBUG] [m.r.internal.engine.RuleEngine:305 ] - Executing rule āParse raw meteostationā
17:47:26.760 [INFO ] [runtime.busevents :26 ] - String_MS_raw state updated to 1116;273;23;36 > 17:47:26.762 [INFO ] [g.openhab.io.net.exec.ExecUtil:64 ] - executed commandLine āecho ā2016-02-29T17:47:26.761+02:00;1116;273;23;36ā >> /media/data/big_storage/Temp/meteostation.csvā
17:47:26.764 [INFO ] [runtime.busevents :26 ] - MS_Temperature state updated to 23
17:47:26.765 [INFO ] [runtime.busevents :26 ] - MS_Humidity state updated to 36
17:47:26.766 [INFO ] [runtime.busevents :26 ] - MS_CO2_Raw state updated to 273
However actually the line is not added to file as expected. If I run the command separatelly in command line - line is adding.
My system is ubuntu 14.04
The user under which the openHAB server is running does not have permission to write to the file /media/data/big_storage/Temp/meteostation.csv, whereas the user under which you are logged in at a command prompt does have permission.
You donāt have access to shell syntax like >>, in which case you could write and invoke a two-line Bash script instead:
Does it allow to store files in csv format?
If not I think it would be nice to have additionally textual persistence (which would allow to save csv as well)
CSV is a separated formatted text. So only the suffix is another one.
I think if you define your csv file in the logback.xml and use the logging-action (logInfo, ā¦) within your rule, you should be fine!
Yes, the logging persistence can be configured to save your items as CSV. See the Logging Persistence wiki page for details.
I highly recommend using the version of executeCommandLine that returns the results and logging those results. I find the Exec binding and executeCommandLine to be pretty brittle and it saves tons of time to actually have the results from executing a command already in your logs.