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"
when
Time cron " 0 59 23 1/1 * ? *"
then
var String Usage = ElectricMeterKWh.state.toString
var Message = (now.toString ("dd-MMM-yyyy") + Usage2)
executeCommandLine = ("echo "+ Message + ( ">> /etc/openhab2/html/totalusage.txt" ))
end
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?
@5iver,
I tried your command (and also modifying my command with the â@@â but that did not seem to work, this is how the permissions are set for the file:
-rw-rw-r-- 1 openhabian openhabian 89 Aug 13 12:38 totalusage.txt
Is it possible, or a better idea to write a script to accomplish this?
Thanks for the help so far⊠still plugging away at trying to find a solution.
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).
@rlkoshak & @5iver: My mistake, thought on Openhabian, openhabian that was the user for OpenHAB⊠permissions changed (chmod 766 /etc/openhab2/html/totalusage.txt, I am use to using the numbers)âŠ
@rlkoshak, I did put the 5000 in, but the log keeps giving me:
The formatting of that line is incorrect. If youâd like to log the return code, use something like this (works for me without the full path to echo)âŠ
Agreed, but in this case the human OP needed to learn why his script wasnât running, not figure out how to detect and programmatically deal with the script failing.
Seeing -1 would have told OP nothing useful. âPermission deniedâ tells him exactly where to look for the problem.