I"d like to write “ON” and “OFF” to a simple text-file whenever a switch is changing.
The switch is changing perfectly each 30 seconds, but the “ON” and “OFF” is not going to be written to the text-file, althoug I have given the necessary privileges (chmod 777 for test.txt) and put openhab into the openhabian-group to be able to write there.
This is the code I use in default.rules:
rule "timeclock test ON"
when
Time cron "30 * * ? * MON-SUN *"
then
sendCommand(PifaceSwitch1, ON)
executeCommandLine("echo \"ON\" > /home/openhabian/status/test.txt")
end
rule "timeclock test OFF"
when
Time cron "0 * * ? * MON-SUN *"
then
sendCommand(PifaceSwitch1, OFF)
executeCommandLine("echo \"OFF\" > /home/openhabian/status/test.txt")
end
In the log-file, I get the message that the command has been executed successfully:
I may be wrong, wouldn’t be the first time, but I think you need something like a python script that will execute and write the text your wanting. I’ve never seen a post on the forum where OH will simply write into a .txt file like your describing but I’m sure it can be done with a script.
Note: The commandLine variable often has to use a special format where @@ needs to be used in place of spaces. For example the bash command touch somefile will have to be written as touch@@somefile
Hi H102:
I tried to do it the way you recommended: Created two python-files, one for writing “ON” and another for “OFF”. I made them executable and tried them, everything well - I got the “ons” and “offs” whenever I was running the python scripts.
Then I put the whole thing into rules - but nothing happens, although logging is telling the contrary.
May be another mistake happening, but seems not to be the solution, at least the way I did it:
When reading again the observations about the common errors of the executeCommandLine, I found out, that I had forgotten to put the “python” command in my CommandLine: