HTTP binding - openHAB 3 version

I have a device that I currently manage with the exec binding and curl commands. I’d like to convert my script to use this http binding instead, but I’m having two issues:

  1. My device only answers POST requests. I’ve made several tests with the HTTP binding and it seems that it always uses GET to obtain status from the device. Is it possible to use POST to obtain status ? How ?
  2. Authentication for my device is made in the form of https://<userid>:<password>@<ip>:<port>. Is this supported by the HTTP binding ?

see this post in this thread.

Thanks but I do not understand how post 169 can help.

According to the docs there is a commandMethod parameter on the Thing where you can tell it to use one of GET, PUT, and POST. There are also a username and password parameters. The port would be a part of the baseURL.

True, but this seems to apply to commands only, not to status. How can I obtain the status using POST instead of GET ? Is this supported by this binding ?

No.

Edit: the question is: how should the request look like? Maybe we can implement something.

1 Like

This may be poor form and I’m happy to delete it if is. I am having some problems with configuring the HTTP binding and originally posted here:

The always helpful Rich was able to get me halfway there so I can now view the status of the device, but I am still unable to send commands using the binding and was hoping someone on this thread who may be using the binding can help me.

Essentially I am trying to replicate the following in the HTTP binding:

sendHttpPutRequest("http://actron.ninja.is/rest/v0/device/xxx?user_access_token=yyy", "application/json", '{"DA":{"amOn":"true"}}',3000)

or

curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"amOn":true}}' http://actron.ninja.is/rest/v0/device/xxx?user_access_token=yyy

I’ve spent several hours now but can’t make any headway. Most of the information is in the other thread but I’m happy to add anything which can help.

I’m trying to put a JSON into the system, in my case openHAB3, and I get this warning:

2020-12-15 13:34:33.920 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'https://warnung.bund.de/bbk.mowas/gefahrendurchsagen.json' (method='GET', content='null') failed: Buffering capacity 2097152 exceeded

I can’t find a way to increase the buffer size for the request.

My Thing and Channel configuration is

UID: http:url:mowas
label: HTTP Gefahren MoWas
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: https://warnung.bund.de/bbk.mowas/gefahrendurchsagen.json
  refresh: 600
  commandMethod: GET
  contentType: application/json
  timeout: 3000
channels:
  - id: mowasJSON
    channelTypeUID: http:string
    label: JSON von Mowas
    description: ""
    configuration: {}

did I miss something?

Hi Matze,
Do you know that a binding exists for the Kostal Piko BA? Then you can read out all values relatively easily.

That binding works only with Gen1 or Gen3 units. Not with my Gen2 BA8 :wink:

I‘ll have a look. Pretty sure we can solve that before the release. Could you enter an issue on GitHub? Thanks.

1 Like

I have also Generation 2 ;-).

Actually I got in contact with the developer of the binding and he further developed it for Generation 2. This we did already during openHAB 2.X and I used the final development version for almost 2 years now.

Currently I´m supporting him in testing the 3.X binding. In that it will be included by default. It works already for reading all parameters as well as even writing, except the Smart Battery control. On that we are working on.

That’s great! Thanks!

1 Like

Please try update org.openhab.binding.http https://janessa.me/esh/org.openhab.binding.http-3.0.0-SNAPSHOT.jar, you’ll probably need to delete and re-add the thing. There is a new “advanced” config option for the buffer size. The default is 2048 kB (which was the default before). Increase that to 4096 and see if your situation improves.

First of all, also thanks from my side to all the guys having participated by developing this binding. It is great to have a successor of the 1.X binding.

Now to the question. Are there anywhere examples or instructions available how it can be used via configuration files. Somehow I would like to stick to the config files for now.

Actually I need it only for simple purposes, like sending a command via http. In the 1.x binding the following did the job:

Switch Visu_Flur_Neustart { http=">[*:POST:http://192.168.178.29:8080/reboot]" }

Dimmer Visu_Flur_Display “Helligkeit Visu Flur [%.0f %%]” { http=">[OFF:POST:http://192.168.178.29:8080/night] >[*:POST:http://192.168.178.29:8080/day/%2$s]" }

I succeeded already in sending one of the commands by configuring it via the UI, but one the one side I have up to now everything setup in config files, on the other side I believe that it would allow me to easier and faster switch my productive openHAB instance from 2.x to 3.x when I have sooner or later everything prepared.

If someone wants to add that to the documentation, I’ll happily merge it. I won’t write that documentation because IMO textual configuration is complex, error-prone and a pain-in-the-a**. Sorry.

1 Like

Hi Jan
thanks for this update. It solved something strange. A while ago i made it to connect my Kostal inverter via the new http binding which runs with a longer JSON string. I got all values into the items, they were visible. But the entries in the sitemap did not show any values, just empty space. Strange thing, havent had the time yet to look into it.
Now i downloaded your changed binding and immediately the values popped up in the sitemap.

Is the buffer size the only thing you changed compared to the M5 binding? I have a similar issue at another binding so it would be an idea to look into the same topics…

No other changes. I doubt that there is a connection between the two issues. The default buffer size is still the same, so if you didn’t configure something, there is no change at all.

Did you set formatting in the item descriptions? I had something similar a while ago and (I think) that was how I fixed it.

I migrated my mobile alerts setup from OH 2.5.2 / http binding 1.14 to OH3 M5 with http OH3 M5 binding.
I have some troubles with the presentation of humidity values on the sitemap.

OH2 using [%d %%]:
ma_humidity_OH2

OH3 using [%d %%] -> 5800% instead of 58%:
ma_humidity_percent

OH3 using [%d %unit%]
ma_humidity_one

I use the following JS (same in OH2 and OH3):

(function(i) { 
    var re = new RegExp('xxxxxxxxxxxx[\\s\\S]*?Luftfeuchte Innen[\\s\\S]*?<h4>([0-9]+)%');
    var out = i.match(re)[1]; 
    return parseFloat(out);
})(input)

Channel an item definition:

I also have a Netatmo for which I do not have these problems:
netatmo_humidity_percent

All of them together look like this:
humidity_all

I’m getting this partially solved by dividing the output from the JS by 100:

(function(i) { 
    var re = new RegExp('xxxxxxxxxxxx[\\s\\S]*?Luftfeuchte Innen[\\s\\S]*?<h4>([0-9]+)%');
    var out = i.match(re)[1]; 
    return parseFloat(out/100);
})(input)

humidity_all_div_100

My questions are:

  1. How to show the % values for MA Indoor/Outdoor on the picture above?

  2. Need for division by 100: Is this caused by changes from OH2 / http 1.14 to OH3?

Thank you.