I need a little help, I am trying to export some data from my power monitor to a text file by appending a date stamp and the item value to it. I have tried using the exec binding to accomplish this, but cannot seem to get it to work properly. Here is my rule so far:
rule "Total Daily Energy Usage"
Time cron " 0 59 23 1/1 * ? *"
var String Usage = ElectricMeterKWh.state.toString
var Message = (now.toString ("dd-MMM-yyyy") + Usage2)
executeCommandLine = ("echo "+ Message + ( ">> /etc/openhab2/html/totalusage.txt" ))
My issue using the exec binding is getting the quotes around the variable value for the command. I have tried:
So, when I checked the file totalusage.txt, there is nothing int the file except for the data I manually typed in (header). So I typed the above into the command line and it does append the file. So, I guess now my question is what would cause this not to work?
Did you added the 5000 as the second argument? You have to give it a timeout so the executeCommandLine will wait at least that long (5 seconds in this case) for the script to complete. Without the timeout executeCommandLine doesn’t return anything.
The permissions are wrong. The file is owned by openhabian:openhabian and only that user and group had permission to write to the file. OH runs as the openhab user. It doesn’t have permission to wit to the file. Either give everyone write permission or change the ownership of the file to openhab:openhab.
I’ve set this up to test, and it is working. Rich got to it first… your permissions won’t work for the openhab account, which OH runs under, even on openHABian. You could just give everyone rw (chmod o=rw /etc/openhab2/html/totalusage.txt).