HTTP binding - openHAB 3 version

I’m using this one (rename to .jar).

I think it was the last one uploaded for OH2. It’s filesize is a bit larger.

org.openhab.binding.http-2.5.8-SNAPSHOT.txt (59.3 KB)

1 Like

HI,
I have an Item with http GET for the state and http POST for the command, how can I translate in http2 binding? Here is the http1:

{ http=">[*:POST:http://192.168.0.xx:2323/?password=xxx&cmd=setStringSetting&key=screenBrightness&value=%2$s] <[http://192.168.0.xx:2323/?password=xxx&cmd=deviceInfo&type=json:30000:JSONPATH($.screenBrightness)]" }

Thanks for your help

Anyone can help me?
As work around I create 2 things: one for the status and one for the command with a rule to update the status of the command item … but I am sure that it is possible to avoid this stupid thing since I have several items to migrate.

Thanks for your help

I can have a look later. But I think with the current Code this is the way to go.

The state is always GET, the command mode cam be changed. So it should work OOTB for you.

So far I use the snapshot version for both, OH 3 and the HTTP Binding.
Things and 4 channels have been created in UI, three of them are working well:

  • 1 x number and 2 x string channel

Each channel has its own JS script attached to it, I am pasring a local ics.file for the upcoming garbage dates.

The datetime channel is making some trouble, the log says:

2020-10-25 17:03:33.632 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:04:03.802 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:04:33.880 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:05:03.448 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'
2020-10-25 17:05:33.732 [WARN ] [iles.JavascriptTransformationProfile] - Could not transform state 'UNDEF' with function 'abfall_naechste_abholung_datum.js' and format '%s'

I understand, that the default setting is %s, so I tried allready some other settings like [%1$td.%1$tm.%1$tY], but the result is still the same.

Somebody else have seen this?

Can you please show the script, the input and the expected output? Thanks.

Hi Jan, thanks for helping.
Script (rename to abfall_naechste_abholung_datum.js)
abfall_naechste_abholung_datum.txt (6.3 KB)

Input file: (rename to abfall2020.ics)
abfall2020.txt (26.4 KB)

Thing config:
grafik

Channel config:

The output should be just the date, at least it is running like this within the OH 1.x Version.

channel profiles are unrelated to binding transformations.
At OH2, transform profiles were restricted to use with String type Items, I do not think that has been addressed yet.

Thanks for the hint, changed it to string… date is now visible. Since the output ist just being displayed in the sitemap and no further action will be done with it, this is fine for me as well.

It won’t be fixed in OH2, but is already implemented in OH3!

That’s good. :slight_smile:
I suppose it did not work in this case then, because the user’s transform does not output an ISO date string that can be parsed into a DateTime Item state,

Thanks Solved now.
Finally the problem was that I always need to clean the cache after any .things update …

That‘s Why I never use textual configuration.

I will probably move to the visual configuration on OH3 sooner or later (I need to move toons of code rows !) but for the time being I have OH2 on stage and OH3 in testing and it is easy to work on textual configuratrion in OH2 and move it on OH3 for testing.

1 Like

Hi… i am using the OH 3 version of the binding. Want to make a http POST request to a URL with a json payload. the equivalent curl command is:

curl -X POST -d '{"state": "off"}' http://192.168.1.199:5000/device/0/power

is this the right way to configure the binding and channel?

I cant seem to get it done. Logs seem to indicate the command is going but is this is the right way to send a json payload? i suspect its just going as a plain string.

2020-11-14 02:36:28.453 [TRACE] [.HttpDynamicStateDescriptionProvider] - returning new stateDescription for http:url:bf98036307:TV_ON
2020-11-14 02:36:28.453 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'http://192.168.1.199:5000/device/0/power': Method = {POST}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Content-Type: text/plain}, Content = {"state: "on"}
2020-11-14 02:36:28.460 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://192.168.1.199:5000/device/0/power': Code = {500}, Headers = {Date: Fri, 13 Nov 2020 21:06:28 GMT, Content-Length: 89, Content-Type: text/plain; charset=UTF-8}, Content = {{"state":"Error: json: cannot unmarshal string into Go value of type webservice.Request"}}
2020-11-14 02:36:28.461 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://192.168.1.199:5000/device/0/power' (method='POST', content='org.eclipse.jetty.client.util.StringContentProvider@3534c0d2') failed: 500 Internal Server Error

the other side a custom golang microserver expecting a json payload via POST.
any suggestions pls?

Judging from the log your command is missing the double-quote after state

Thanks. Sorry That was a typo. But still getting the same error. Anything else I can do to troubleshoot?

2020-11-14 08:37:20.793 [TRACE] [.HttpDynamicStateDescriptionProvider] - returning new stateDescription for http:url:bf98036307:TV_ON
2020-11-14 08:37:20.794 [TRACE] [nding.http.internal.HttpThingHandler] - Sending to 'http://192.168.1.199:5000/device/0/power': Method = {POST}, Headers = {Accept-Encoding: gzip, User-Agent: Jetty/9.4.20.v20190813, Content-Type: text/plain}, Content = {"state": "on"}
2020-11-14 08:37:20.802 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://192.168.1.199:5000/device/0/power': Code = {500}, Headers = {Date: Sat, 14 Nov 2020 03:07:20 GMT, Content-Length: 89, Content-Type: text/plain; charset=UTF-8}, Content = {{"state":"Error: json: cannot unmarshal string into Go value of type webservice.Request"}}
2020-11-14 08:37:20.803 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'http://192.168.1.199:5000/device/0/power' (method='POST', content='org.eclipse.jetty.client.util.StringContentProvider@1adeda5c') failed: 500 Internal Server Error

Infact the sendHttpPostRequest from a script works just fine

sendHttpPostRequest("http://192.168.1.199:5000/device/0/power", "text/plain", "{\"state\":\"on\"}", 30000)

Can you confirm that it works on the command line?

curl -X POST -d '{"state": "on"}' http://192.168.1.199:5000/device/0/power

Also check to make sure the device is there

Can you post the response of
curl http://192.168.1.199:5000/device/0

It looks like you are missing the curly braces in the on/off value fields, have you tried including them? (try {“state”: “on”} instead of “state”: “on”)

2 Likes