Read Alarm System status with JSON

Even the most simple example does not work:

executeCommandLine(“ls -la /tmp > horst.txt”)

It’s executed, but the file horst.txt is not created.

Look to see if the script is returning any sort of error on the command line that might be enlightening.

var result = executeCommandLine("ls -la /tmp > hosrt.txt", 5000)
logInfo("Rules", result)

Also, where are you looking for hosrt.txt. It isn’t clear to me what folder is the “working folder” when openHAB is running so I’m not entirely sure where I would look. Probably ~openhab would be my first stop.

You are right - the folder was not specified.
But I checked for the file globally and it was nowhere to be found.

thanks for the tip about the loginfo:
var result = executeCommandLine(“curl -s http://root:xxx@”, 5000)
logInfo(“BLABLA abus”, result)
provides the result:

If I extend the executeCommandLine by e.g. sed
var result = executeCommandLine(“curl -s http://root:xxx@ | sed ‘s#^.*=##’”, 5000)
logInfo(“BLABLA abus”, result)
The result is the same.
In the shell it provides the right result:

Interesting. That seems to indicate the script is executing and your sed is extracting just the states.

So now you just need to parse the results from the executeCommandLine to extract the data you need. Since it looks like all your items are on a new line, you will probably need to use result.split("\n") to split on newline instead of space like my example from above.

Because I was getting more and more frustrated about the implementation into a rule I moved the main command into a shell script.

So my rule looks like this now:
rule “request Abus Secvest IP status”
Time cron “0 0/2 * * * ?” // every 2 minutes -> works as expected !!!
var result = executeCommandLine("/etc/openhab/configurations/scripts/", 5000)
logInfo(“BLABLA abus”, result)

The shell script looks like this:
RESULT=curl -s http://root:xxx@ | awk 'NR!=5 && NR!=6 && NR!=8 && NR!=9 && NR!=10 && NR!=12 && NR!=13 && NR!=14 && NR!=16 && NR!=17' | sed 's#^.*=##'
echo $RESULT

Which ends up in the openhab.log as:
2015-10-19 19:54:00.285 [INFO ] [enhab.model.script.BLABLA abus] - OFF OFF OFF OFF OFF OFF OFF

This leads to your (@rlkoshak) suggestion splitting the result.
In this case with (" “)
var Abus_ARRAY = result.split(” ")
But how to use the ARRAY back in the items?
doesn’t seem to work…

You need to call something like this:


Note that it starts with 0, not 1 for the index in the array.

Thanks - I will give it a try and will get back to you.

I did it - thanks for your patience and support!
Now I have a working script and rule to check the state of the Abus Secvest IP on a regular (cron) basis.
I even can activate / deactivate it through OpenHAB.
The last thing to be adressed is switching the connected power plug.
Again: Thank you very much!

rule “request Abus Secvest IP status”
Time cron “0 0/2 * * * ?” // every 2 minutes -> works as expected !!!
var result_Abus = executeCommandLine("/etc/openhab/configurations/scripts/", 5000)
var Abus_ARRAY = result_Abus.split(" ")

I’m glad it works!