Http and JSON

Hi

I have an Myelas alarm system and i would lige to see the status on the system in openhab

when I call this adress:
172.0.0.1:8111/api/alarm/status

i get this status:
{“version”: 0.1, “devices”: {“panel1”: 100, “zone4”: 200}}

so this exempel is, panel1 100 ( partition ready) zone4 200 ( zone inactive)

i have this response types

ResponseTypes
100 : partition ready
110 : partition notready
120 : partition armed
130 : partition partarmed,
140 : partition alarm
200 : zone inactive
210 : zone active
220 :zone bypassed
230 : zone alarm
300 : zone closed
310 : zone open
320 : zone bypassed
330 : zone alarm
400 : zone clear
410 : zone smoke
420 : zone bypassed
500 : zone clear
510 : zone water
520 : zone bypassed
600 : zone clear
610 : zone carbonMonoxide,
620 : zone bypassed

Can somone help me get this in openhab?

Do the keys in the devices object always come back as panel1 and zone4, or can the keys change dynamically like zone6 or panel2? How to proceed depends on the answer. Also, are you on openHAB 1 or 2?

Hi John

Thanks for the answer

PANEL1 and ZONE4 is static.
but there may come more later on. eg. zone3, but I think it just copy of some coding ?

I am running openhab2. Can you make a code that works om both pladforms?

Yes, it’s nearly identical except for .cfg files. Here is one approach (not tested of course):

Install JSONPATH and MAP transformation services, and HTTP binding.

services/http.cfg:

myelas.url=172.0.0.1:8111/api/alarm/status
myelas.updateInterval=60000

items/your.items:

String PanelStatus "Panel Status [MAP(myelas.map):%s]" { http="<[myelas:60000:JSONPATH($.devices.panel1)]" }
String Zone4Status "Zone4 Status [MAP(myelas.map):%s]" { http="<[myelas:60000:JSONPATH($.devices.zone4)]" }

transform/myelas.map:

100 partition ready
110 partition notready
120 partition armed
130 partition partarmed
140 partition alarm
200 zone inactive
210 zone active
220 zone bypassed
230 zone alarm
300 zone closed
310 zone open
320 zone bypassed
330 zone alarm
400 zone clear
410 zone smoke
420 zone bypassed
500 zone clear
510 zone water
520 zone bypassed
600 zone clear
610 zone carbonMonoxide
620 zone bypassed

Hi John

It workes. Thanks

But the http.cfg does not seem to work, the string only work if I type the ip in like this:

String PanelStatus “Panel Status [MAP(myelas.map):%s]” { http="<[172.0.0.1:8111/api/alarm/status:60000:JSONPATH($.devices.panel1)]" }
String Zone4Status “Zone4 Status [MAP(myelas.map):%s]” { http="<[127.0.0.1:8111/api/alarm/status:60000:JSONPATH($.devices.zone4)]" }

What did I do wrong since myelas don’t work?

Thx Mads

Did you put your http.cfg in the services directory?

Hi John

I missed the http:// in front of the IP address:
Not like this
myelas.url=172.0.0.1:8111/api/alarm/status

But like this
myelas.url=http://172.0.0.1:8111/api/alarm/status

This workes :slight_smile:

Thx Mads

Ps. Do you know if It is difficult to change the Myelas-Alarm-Server in to a binding?


As a can see it is written in Java, but a don’t know what language bindings are written in.

Glad you got it working.

The repo you linked seems to contain code written in Python, with SmartThings integration in Groovy. Bindings in openHAB are written in Java. A quick glance at AlarmServer.py seems to indicate that it is communicating with https://www.myelas.com/ELAS/WebUI/Security/GetCPState and isn’t very complicated. This might make it a candidate to use the HTTP Binding directly, instead of having to write a new binding. Otherwise, having a binding replicate the function of AlarmServer.py looks pretty simple!

Hi John

First of all, are you interested in helping me a bit further?

If I use this address in a http binding.

Wil the string look like this?

String PanelStatus “Panel Status [MAP(myelas.map):%s]” { http="<[https://www.myelas.com/ELAS/WebUI/Security/GetCPState:60000:JSONPATH($.devices.panel1)]" }

How do a insert my username and password and pin code to the alarm?

It would be nice not to run the py shript in the background.

The approach would be to achieve the same HTTP request/responses you find in AlarmServer.py with the equivalent functions of the HTTP binding, assuming it’s all possible, which it might very well be. It might also need an assist from a rule and the sendHttpPostRequest action.

This line shows that JSON data is POSTed with username, password and alarm code, but I don’t know if that sets a cookie in Python which is used by subsequent calls. If so, it will probably need a binding instead of using the HTTP binding.

Someone with good Python knowledge and knowledge of the HTTP binding could try to match up requests and responses to see if the HTTP binding+rules+sendHttpPostRequest is viable, or if a new binding would be needed. In the more capable environment of Java and the Jetty HTTP client libraries, a fast and capable binding could be built with no doubt.

Thanks.

I will try figuring out this python coding.

1 Like

Hi

a am running in to an other problem, if I want du arm/disarm the alarm, I need du send following commands

Arm:
http://localhost:8111/api/alarm/arm

Disarm
http://localhost:8111/api/alarm/disarm

How do I use them on a switch

I tryed with

Switch Arm “Arm” (Alarm) {http=">[http://localhost:8111/api/alarm/arm]"}

And

Switch Arm “Arm” (Alarm) {http=">[ON:http://localhost:8111/api/alarm/arm]" >[OFF:http://localhost:8111/api/alarm/disarm]"}

With no luck, can ypu help me again?

Please see the examples in the documentation here:

http://docs.openhab.org/addons/bindings/http1/readme.html#item-configuration

Let us know if the documentation is lacking somehow.

Thanks John

It worked :slight_smile:

1 Like

This would not work with JSON in the http adress and a transform to a switch item, right?
Like transforming a string of “unplugged” to Switch state OFF

You could use a javascript transform that both processes JSON and decides what to return