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:
Now
var result = executeCommandLine(“curl -s http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi”, 5000)
logInfo(“BLABLA abus”, result)
provides the result:
InputCH1=OFF
InputCH2=OFF

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

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”
when
Time cron “0 0/2 * * * ?” // every 2 minutes -> works as expected !!!
then
var result = executeCommandLine("/etc/openhab/configurations/scripts/readAbusStates.sh", 5000)
logInfo(“BLABLA abus”, result)
end

The shell script looks like this:
#!/bin/bash
RESULT=curl -s http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | 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?
Abus_ARRAY[1]
Abus_ARRAY[2]
doesn’t seem to work…

You need to call something like this:

MyItem1.sendCommand(Abus_ARRAY.get(0))
MyItem2.sendCommand(Abus_ARRAY.get(1))

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.

Yeah!
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”
when
Time cron “0 0/2 * * * ?” // every 2 minutes -> works as expected !!!
then
var result_Abus = executeCommandLine("/etc/openhab/configurations/scripts/readAbusStates.sh", 5000)
var Abus_ARRAY = result_Abus.split(" ")
Abus_Eingang.postUpdate(Abus_ARRAY.get(0))
Abus_Balkon.postUpdate(Abus_ARRAY.get(1))
Abus_Oberlicht.postUpdate(Abus_ARRAY.get(2))
Abus_Kamera.postUpdate(Abus_ARRAY.get(3))
Abus_Steckdose.postUpdate(Abus_ARRAY.get(4))
Abus_Batteriealarm.postUpdate(Abus_ARRAY.get(5))
Abus_Einbruch.postUpdate(Abus_ARRAY.get(6))
end

I’m glad it works!