OpenHab2 Parse HTTP and Read Array of Adresses - Internorm - Mediola Gateway

Hello,
I am somewhat new to OpenHAB - while I already use OpenHAB with my KNX Installation on my iPhone basically only as a remote - I now would like to go one step further into the “automation” of things.

Unfortunately when building my house I used the “Internorm Smart Window” Solution to capture the state of my windows (Open, Closed, Tilted). This solution is basically a modified Mediola Gateway V4.

Now I would like to make these window states also available in OpenHAB in order to automate my shutters. (e.g. When a window is open and it starts to rain then the shutter shall close, … )

I already was able to read out the statuses via a http call that looks like follows:

http://192.168.178.18/command?XC_FNC=GetStates

This will result in the following html feedback:

{XC_SUC}[{“type”:“IW”,“adr”:“FF”,“state”:“0018:00”},{“type”:“IW”,“adr”:“01366B01”,“state”:“0110:01”},{“type”:“IW”,“adr”:“01366B02”,“state”:“0012:05”},{“type”:“IW”,“adr”:“01366B03”,“state”:“0012:07”},{“type”:“IW”,“adr”:“01366B04”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B05”,“state”:“0012:07”},{“type”:“IW”,“adr”:“01366B06”,“state”:“0012:04”},{“type”:“IW”,“adr”:“01366B07”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B08”,“state”:“0112:02”},{“type”:“IW”,“adr”:“01366B09”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B10”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B11”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B12”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B13”,“state”:“0012:04”},{“type”:“IW”,“adr”:“01366B14”,“state”:“0112:01”},{“type”:“IW”,“adr”:“01366B15”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B16”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B17”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B18”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B19”,“state”:“0112:01”},{“type”:“IW”,“adr”:“01366B20”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B21”,“state”:“0112:01”}]

The syntax is that:

  • the “adr” is the Adress of a window (e.g. 01366B02 = Bathroom Window)
  • the 3rd and 4th digit of the state is the state of the window (12=closed, 10=open, 11=tilted)

Now - my Problem is that I do not know how to extract the status of each window and make it usable in OpenHab for further processing / logic.
I tried to use RegEx, but not very successful - I was able to find the state of a adress with the following RegEx - but I do not really know how to make use of it:

/adr":“01366B02”.?state":"(.?):/si

Since I do know which window I am adressing I would only need the status back.

Guess this is a very basic question - guess I am only missing that little hint…

thanks in advance

That looks like valid JSON so perhaps the JSONPATH transform would be a better choice. However, that will keep the " around the value returned. If that will be a problem you may want to use the JS transform.

See the Comprehensive Wunderground using HTTP Binding Example for a detailed example using Wunderground weather data.

Hmm… I am not (yet) too familiar with JSON/REGEX… but when I try to check if my response is a valid JSON (using https://jsonlint.com/) then it appears it is not quit a valid JSON.

Reading through your WU example it appears you are doing most with JSONPATH. Yet I found one with RegEx - but somehow I am not able to only retrieve the window state (e.g. 12 = open) using my RegEx statement - and don’t know how to make use of the response?!

Something that I found out was that only a few changes to the HTTP response would make this a valid JSON:

  1. Put the XC_SUC in Quotes ("")

  2. Add a : right before the [

  3. Move the } after XC_SUC to the very end

So the resulting JSON would be:

{“XC_SUC”:[{“type”:“IW”,“adr”:“FF”,“state”:“0018:00”},{“type”:“IW”,“adr”:“01366B01”,“state”:“0110:01”},{“type”:“IW”,“adr”:“01366B02”,“state”:“0012:05”},{“type”:“IW”,“adr”:“01366B03”,“state”:“0012:07”},{“type”:“IW”,“adr”:“01366B04”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B05”,“state”:“0012:07”},{“type”:“IW”,“adr”:“01366B06”,“state”:“0012:04”},{“type”:“IW”,“adr”:“01366B07”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B08”,“state”:“0112:02”},{“type”:“IW”,“adr”:“01366B09”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B10”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B11”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B12”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B13”,“state”:“0012:04”},{“type”:“IW”,“adr”:“01366B14”,“state”:“0112:01”},{“type”:“IW”,“adr”:“01366B15”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B16”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B17”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B18”,“state”:“0012:02”},{“type”:“IW”,“adr”:“01366B19”,“state”:“0112:01”},{“type”:“IW”,“adr”:“01366B20”,“state”:“081A:FF”},{“type”:“IW”,“adr”:“01366B21”,“state”:“0112:01”}]}

So while I now know how to manually transfer my response into a valid JSON - I do not know how to do this programatically and how to only extract the window state I actually need!?

Guess this is a very very basic question - too basic?
anyway… thanks for your help - and I will definetely copy your WU solution once I am able to read my window states…

OK, if it isn’t valid JSON you are stuck with REGEX or you have to use JS to make the changes you identified and then you can parse the JSON using JavaScript, but that would probably be overkill.

There are online REGEX testers, this one was the top of Google’s results.

To use your REGEX, follow the instructions in the HTTP binding’s readme:

  1. Create a cache configuration

  2. Create an Item for each address

  3. Following the example:

    Number temperature { http="<[weatherCache:10000:XSLT(demo_yahoo_weather_temperature.xsl)]" }

You would replace the information listed in the example with your information. Your REGEX replaces the XSLT part.

Hello - thanks for your support. I will try to work with RegEx and see how far it gets me.
I am already in the process of setting up a parallel OpenHab Installation in order to “test” things…

wish me Luck…

On more night - and it appears I am still struggeling. I now tried both, the cached mode and the direct one - but I only get a “null” back in my Visu.

In my Items file I use the following entry (uncached) to obtain the response from my windows:

String  Inter_Norm "internorm [%s ..]" <window>	(EG_Flur) {http="<[http://192.168.178.18/command?XC_FNC=GetStates:30000:REGEX(B02.*?:(.*?):)]"}

If I test the RegEx using https://regex101.com/ it appears to be valid.

Also I did install the http binding with the following http.cfg:

# timeout in milliseconds for the http requests (optional, defaults to 5000)
#timeout=

# the interval in milliseconds when to find new refresh candidates
# (optional, defaults to 1000)
#granularity=

# whether to substitute the current time or state value into the URL
# (optional, defaults to true)
#format=

# configuration of the first cache item
internorm.url=http://192.168.178.18/command?XC_FNC=GetStates.json
internorm.updateInterval=36000

# configuration of the second cache item  
#<id2>.url=
#<id2>.updateInterval=

With the above I also tried to get something back using the following line in the items file - without success.:

String  internorm "internorm [%s ...]" <window>	(EG_Flur) {http="<[internorm:36000:REGEX(B02.*?:(.*?):)]"}

In both cases I get the same result:
OH-Internorm

May I ask again for your help…

First, change to a default REGEX (i.e. REGEX((.*))) to make sure there isn’t something big wrong (i.e. the data is not arraiving, you don’t have REGEX installed, etc. You can see in events.log what the Item is being updated to.

I notice that in http.cfg your URL ends with GetStates.json but in your direct Item it is missing the .json.

Assuming you have REGEX and it is able to process, then I expect it has to do with some quirk of the particular REGEX implementation in Java. It has many noted quirks. The first thing I would try is add a .* before and after your current one to match to all the stuff that could occur before and after the part you care about.

 REGEX(.*B02.*?:(.*?):.*)

You really should not be relying solely on the UI when trying to do something like there. There is so much that occurs between your webserver and the sitemap that the fact that it shows up null there means only that something went wrong with no hint as to where.

NOTE: the fact that it is showing null rather than - or NULL probably means that your REGEX is not matching. I would expected to see something in the logs.

You are so great!! Thanks a lot - your Regex statement fixed my Problem… or at least the first one.
I altered the regex a bit and it now responds perfectly with a 12 - just as desired… now I try get it to work in cached mode and try to transfer the response into something useful - to build a logic ontop of it…

REGEX(.B02.?:…(.?):.)

again - thanks so much for your continued help!

Hello Andreas,

i am interested in the same solution!
i want to integrate my internorm windows with mediola gateway in openhab.
has someone a good documentation / a working evironment an dcan help?

kind regards,

oliver

Hello Oliver,

here’s some documentation on what I did - first of all you need to know that I only have the window contacts! I do not have any blinds or vents from Internorm integrated!

Getting the window states:
http://Your Mediola Gateway IP/command?XC_FNC=GetStates

This should give you an Output like:

{XC_SUC}
[{“type”:“IW”,“adr”:“FF”,“state”:“0016:00”},{“type”:“IW”,“adr”:“01366B01”,“state”:“0012:01”},{“type”:“IW”,“adr”:“01366B21”,“state”:“0112:02”}]

Binding Config --> Services/http.cfg

internormCache.url=http://Your Mediola Gateway IP/command?XC_FNC=GetStates
internormCache.updateInterval=60000

Item Configuration:

String http_binding_test “This is a test [MAP(internorm.map):%s]” {http="<[internormCache:10000:REGEX(.B01.?:…(.?):.)]"}

Mapping File --> Internorm.map

0=Open
1=Tilted
2=Closed
4=Open-Bat
5=Tilted-Bat
6=Closed-Bat
8=Timeout
9=Timeout
A=Timeout
C=TimeO-Bat
D=TimeO-Bat
E=TimeO-Bat

Hope this helps?!