Read Alarm System status with JSON

All,

Because I would like to integrate my Alarm System (Abus Secvest IP) into OpenHAB, I would like to read the status from its web GUI (and if possible change status).

Unfortunately I do not have a clue how to request the JSON information from the web GUI.
Actually I do not know how to check if the GUI supports JSON.

So it would be very helpful, if someone could get me hint how the syntax to request JSON from the Secvest Web GUI should look like.

My first item try looks like this:
String Abus_Status “Status: [%s]” { http="<[http://user:password@192.168.178.24:8060/home.cgi?10000:JS(readABUS.js)]" }
and "readABUS.js is located in openhab/configurations/transform and looks like this
JSON.parse(input).CurrentMode;
(I saw somewhere in the html code the “CurrentMode” but I don’t know if this is included in the JSON response.

Sorry, if this is a stupid question.

Best regards,
NCO

It isn’t a stupid question at all. However, it will require someone who knows the Abus Secvest IP alarm system to help. It isn’t a generic openHAB question.

But since it has a web GUI, you could write an XSLT transform to extract the information you want from the HTML if JSON is not available. There are several examples, mostly weather based parsing weather data from Yahoo in the wiki that might get you started.

Hi Rich,

thanks for your response (again) :wink:
I hope I will succeed as quick as last time when you provided some hints.

That said, I played around a little successfully :smile:

The source code of the Abus Web GUI contains:
var g_audio_path = “/sd/audio/english/”;
var g_audio_current_mode;
var g_sound_path = “/sd/audio/sounds/”

an I extracted the sound path with:
String Abus_String “OutputCH1: [%s]” { http="<[http://user:password@192.168.178.24:8060/home.cgi:10000:REGEX(.?g_sound_path = "(.?)".*)]" }

Result: /sd/audio/sounds/

So far so good…
Unfortunately the variable I would like to extract is in a separate frame within “home.cgi” and I don’t know how to search within the other frame for a phrase.

Thanks in advance.
Best regards,
NCO

We are rapidly approaching the end of my knowledge about this, but I believe that each frame has its own URL (a frame is basically a web page embedded within another web page) so perhaps you can pull down the frame individually using that URL.

Hi Rich,

I really appreciate your help.
Actually I found out that your point is true (separate “overview.cgi” containing information I would like to read out (Status of Window sensors).
However, there is one part in the website where the activation switch for the security system is located.
I did not find the source code / separate URL of this switch, but I will keep digging :wink:

Best regards,
NCO

Another problem I did not find a solution for is:
How to convert a string to another type of variable.
e.g:
String Abus_Status “Abus Status: [%s]” { http="<[http:// … /home.cgi:10000:REGEX(.?var CurrentMode="(.?)".*)]" }
will store “Set” or “Unset” into the variable “Abus_Status”.
How do I convert it to a contact item?

Best regards,
Enzio

There are two things you have to do. First is just declare it as a Contact instead of a String:

Contact Abus_Status ...

The second is you have to create a map to convert “Set” to “OPEN” and “Unset” to “CLOSED” as a Contact only supports those two states. But my regular expression skills are not up to figuring out how to do that in the transform. Another way you can get around this is to leave Abus_Status as a String and create another Item Abus_Contact as a Contact and a rule to update the contact when Abus_Status updates.

Items:

String Abus_Status        "Abus Status:    [%s]"    { http="<[http:// ... /home.cgi:10000:REGEX(.?var CurrentMode=\"(.?)\".*)]" }
Contact Abus_Contact "Abus Status: [%s]"

Rules:

rule "Update Abus Contact"
when
    Item Abus_Status received update
then
    if(Abus_Status.state == "Set") Abus_Contact.sendCommand(OPEN) 
    else Abus_Contact.sendCommand(CLOSED)
end

Hi Rich,

thanks for your help.
You contact suggestion was a good choice and I the functionalityis getting better.

Now I can even switch the Abus Secvest IP on and off:
Switch Abus_Mode “Alarmanlage” (G_Abus) { exec=">[ON:curl http://root:xxx@192.168.178.24:8060/setMode.cgi?Mode=Set] >[OFF: curl http://root:xxx@192.168.178.24:8060/setMode.cgi?Mode=Unset]"}

However I have problems reading the status of the window contacts etc.
There is a cgi returning the
values:
http://192.168.178.24:8060/getOverviewStatus.cgi
This responds with a bunch of states:
InputCH1=OFF
InputCH2=OFF
InputCH3=OFF
InputVCH1=OFF
InputVCH2=DEACTIVATED
InputVCH3=DEACTIVATED
OutputCH1=OFF
OutputCH2=OFF
OutputWired=OFF
AlarmPowerFail=OFF
AlarmLowBattery=OFF
AlarmFault=OFF
AlarmFire=OFF
AlarmTechnical=OFF
AlarmBurglary=OFF
AlarmEntry=OFF
AlarmPanic=OFF

How do I extract the right one only?

Thanks.
best regards,
Enzio

You will need to get the field using a regular expression transformation. There is an example on the http binding wiki page. I’m afraid regex is not my thing and I’ll be of limited use figuring it out. I already have to start from scratch and relearn it every time.

Hi,

I worked out the right queue of commands to filter the required information out of the list of variables mentioned in my previous post.
It took quite a while, but it’s working well - even if it’s not a beauty :wink:

In this command example mentioned below I just cut out the first variable to find the right syntax to integrate it into a proper rule (all other lines are deleted and will be used later:
executeCommandLine(Abus_ARRAY=“curl -s http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=2 && NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed ‘s#^.*=##’ > /var/log/openhab/abus.log”);

The information (here: OFF) is extracted correctly, but I don’t know how to store it into a variable.
Even better would be to store multiple Variables of the list above into an Array.
Any hint is greatly appreciated.

Best regards,
NCO

I guess, I need to change my root password right away :wink:

To create a variable in rules you use “var” if it is something that will be reassigned later or “val” if not.

var myVar = executeCommandLine(...

This will result in aa String returned by the command.

Once in the string, you can get an array using the .split(“delimiter”) method. For example, if the fields are separated by a space you would use

myVar.split(" ")

Hi Rich,

thanks for your quick reply.
So you mean, that you first generate the list of Strings and than separate THE SAME variable with .split?
Doesn’t this lead to a conflict of different types of one single variable (string list / single string)?


import java.lang.String
rule “request Abus Secvest IP status”
when
Time cron “/3 * * * * ?"
then
var Abus_String = executeCommandLine("curl -s http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed 's#^.
=##’”);
Abus_ARRAY.split(" ")
end


But I get an ERROR message in the openhab log:

Error during the execution of rule request Abus Secvest IP status
java.lang.RuntimeException: The name ‘.split()’ cannot be resolved to an item or type.
Any idea?
Thanks.
NCO

Try:

// import java.lang.String You don't need to import stuff from java.lang
rule "request Abus Secvest IP status"
when
    Time cron "*/3 * * * * ?"
then
    var Abus_String = executeCommandLine("curl -s http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk 'NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17' | sed 's#^.*=##'");
    var Abus_ARRAY = Abus_String.split(" ")
end

Unless it’s changed recently, if you use executeCommandLine synchronously you need to give it a timeout as the second argument.

1 Like

That’s right. I forgot about that. @danielwalters86 is correct. you have to give it a timeout or else you won’t get the result string back.

I tried:
rule “request Abus Secvest IP status”
when
Time cron “/3 * * * * ?"
then
var Abus_String = executeCommandLine("curl -s --max-time 2 --connect-timeout 2 http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed 's#^.
=##’”);
var Abus_ARRAY = Abus_String.split(" ")
end

But the execute curl pops up in the log every 3 seconds:
2015-10-14 19:28:57.012 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘curl -s --max-time 2 --connect-timeout 2 http://root:=xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed ‘s#^.=##’’
2015-10-14 19:29:00.036 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine 'curl -s --max-time 2 --connect-timeout 2 http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed 's#^.
=##’’
2015-10-14 19:29:03.017 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘curl -s --max-time 2 --connect-timeout 2 http://root:xxx@192.168.178.24:8060/getOverviewStatus.cgi | awk ‘NR!=3 && NR!=4 && NR!=5 && NR!=6 && NR!=7 && NR!=8 && NR!=9 && NR!=10 && NR!=11 && NR!=12 && NR!=13 && NR!=14 && NR!=15 && NR!=16 && NR!=17’ | sed ‘s#^.*=##’’

That’s weird…

Not weird. The cron trigger is set to go off every 3 seconds.

If you want every three minutes you want “* */3 * * * ?”.

Also, don’t miss the comments above. You will want to add a timeout number as the second argument to the executeCommandLine or else you won’t get your string result back.

Damn it - you are right.
That kind of thing happens if I copy and paste… :wink:

I got your (and @danielwalters86) hint wrong and though I just need to add the timeout to the curl call.
Now I added 2000 ms to the exec command and will check…

Still having Problems I did not understand yet.

So I simplified the command above.

The 2 executeCommandLine (in two different rules) below are executed according to the openhab.log but nothing happens:

Commands:
executeCommandLine( “/usr/share/openhab/configurations/scripts/sonyTVcheck.sh” )

executeCommandLine(“curl@@-s@@http://root:=p3n&Hab@192.168.178.24:8060/getOverviewStatus.cgi > /tmp/openhab.txt”)

openhab.log result:
2015-10-18 19:57:00.024 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘/usr/share/openhab/configurations/scripts/sonyTVcheck.sh’
2015-10-18 19:58:00.020 [INFO ] [g.openhab.io.net.exec.ExecUtil] - executed commandLine ‘[curl, -s, http://root:=p3n&Hab@192.168.178.24:8060/getOverviewStatus.cgi > /tmp/openhab.txt]’

So the second result shows brackets the first one doesn’t.

No error message at all.
Any ideas?
Thank you.

Best regards,
NCO