HTTP binding - openHAB 3 version

no what I meant was that e.g. I want to make a get request with some authorization, headers etc. In this v2 version I see that you can define them in the things file. However I see no option to use this in a rule as an action. The v1 version can be used as an action in the rule, however there are the limitations with the header, atuh etc.
That’s why I asked if this v2 version can be used within a rule with the additionals extensions listed in the markdown

Ah, I see what you mean now. :upside_down_face:

Give it a try and see if it works as expected. If not maybe a change or feature can be added. :wink:

Can you give an example how that looks? I can’t find documentation in the http binding about actions.

I think @NoneWhereTo refers to this:

I think the “Actions” are actually part of the OH basis and not of the Binding, which can lead to some confusion.

OH2 bindings can offer Actions for use in rules, these are “got hold of” by using a getActions(http, some params) method. I suspect this is not yet existing for the new binding.

@J-N-K how can you get a value from a json array?
In http1 I had: [0].name
I have tried it this way in the new binding: JSONPATH:$[0].name

But I get an exception…

Thanks for your engagement. Upfront, I haven’t validated that yet, but the old binding had a nuisance that if the target was unreachable, it was spitting errors with an error level log. That was very annoying when it’s every n seconds and it was not a (binding) error in fact but server unreachable is a perfectly (well :wink:) normal condition that should not result in error logging.
Please don’t repeat implementing that behavior in your new version.

2 Likes

Can you please show the server response and the exception?

The question is how this should be handled. UNDEF or just ignore the error?

1 Like

Sure. Here is the exception:

2020-07-09 21:40:09.798 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: 

java.lang.IllegalArgumentException: Illegal character in scheme name at index 0: "https://api.github.com/repos/arendst/Tasmota/tags"

	at java.net.URI.create(URI.java:852) ~[?:1.8.0_222]

	at org.eclipse.jetty.client.HttpClient.newRequest(HttpClient.java:442) ~[?:?]

	at org.openhab.binding.http.internal.http.RefreshingUrlCache.refresh(RefreshingUrlCache.java:79) ~[?:?]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_222]

	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[?:1.8.0_222]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[?:1.8.0_222]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[?:1.8.0_222]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_222]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_222]

	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]

Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: "https://api.github.com/repos/arendst/Tasmota/tags"

	at java.net.URI$Parser.fail(URI.java:2848) ~[?:1.8.0_222]

	at java.net.URI$Parser.checkChars(URI.java:3021) ~[?:1.8.0_222]

	at java.net.URI$Parser.checkChar(URI.java:3031) ~[?:1.8.0_222]

	at java.net.URI$Parser.parse(URI.java:3047) ~[?:1.8.0_222]

	at java.net.URI.<init>(URI.java:588) ~[?:1.8.0_222]

	at java.net.URI.create(URI.java:850) ~[?:1.8.0_222]

	... 9 more

Ps.: My bad, I had a look at the exception again and the problem was in the base url, I forgot to delete the quotation marks, it works now!

1 Like

Would you post your example (in case you use text file definition)?

INFO level logging ?
Ideally on state changes only (server gone between last and current request + when server came back)

I’m using PaperUI. Anyway the config is really straightforward.
Define the BaseURL at thing level and add state transform for a channel as you would do in MQTT2 binding.
So state transform should look like this (assuming a json input):

JSONPATH:$[0].name

Thanks for bringing that up!
Yes it was really annoying and it not even showed these errors between the specified poll intervals but every few seconds…
@J-N-K
I think an UNDEF state for channels on a Thing is great for showing unreachable hosts. Maybe also use ThingStatus to represent availability on a Thing level?

For anyone who wants to start off using/migrating textual config, here is a very simple example that works for me:


Thing http:url:exchangerate "USD-EUR Exchange Rate" [ baseURL="https://api.exchangeratesapi.io/latest?symbols=USD", refresh=3600] {
    Channels:
        Type number : USDEUR "Exchange Rate" [ stateTransformation="JSONPATH:$.rates.USD" ]
}

Item:
Number ExchangeRateEURUSD  "EUR - USD [%.3f]"                  <exchangerate>          (gAll)  {channel="http:url:exchangerate:USDEUR"}
2 Likes

There usually ends up being use cases for both ways.

I would suggest a user option , perhaps per data channel
postUndefOnError=true
or something like, defaulting false.

An alternative might be dateTime channel(s) for
lastReadSuccess
lastReadError
which allows users to trap and manage errors for themselves in rules.

The config per channel might be an option. lastReadSuccess is difficult, because it could be that reading one channel is successfull (e.g. with one stateExtension) while another channel (with another stateExtension) always fails. The lastReadSuccess would not help here.

Really I was thinking this would be a built-in channel exposing something about the Thing. It’s the Thing doing the HTTP work from the user viewpoint.

I see this binding does both read and write - so I suppose a better name might be more like
lastCommSuccess
lastCommError
or something if it covers both uses.

Maybe it is less useful these days where Thing status is more accessible from rules, if this Thing reflects its comms problems in its own status…

Hello @J-N-K

thank for creating this new OH2 binding, great job! :slight_smile:

Finally had time to test it.

I have one feature request:

In http1 binding you had the possibility to use up to 3 different urls.

In the new binding there are unfortunately only two:

Simple example: Switch

baseURL + stateExtension
baseURL + commandExtension

.

But there are the following cases possible and in http1 and you were able to do so:

URL1 = ON
URL2 = OFF
URL3 = state

e.g:

ON = 192.168.100.44:3000/on/3ef204
OFF = 192.168.100.44:3000/off/3ef204
state = 192.168.100.44:3000/state/3ef204
.

Example .items file:

Switch GHoma1	"G-Homa Socket 1"	{ http=">[ON:GET:http://192.168.100.44:3000/on/3ef204] >[OFF:GET:http://192.168.100.44:3000/off/3ef204] <[http://192.168.100.44:3000/state/3ef204:60000:MAP(onoff.map)]" } 

.
.

This would be in http2 binding:

baseURL = 192.168.100.44:3000
stateExtension = /state/3ef204
commandExtension = /on/3ef204 OR /off/3ef204
.

But I need one commandExtension for ON and another commandExtention for OFF.

Or can I use commandTransformation? How do I have to use it?
.
.

Second question:

How do I mix GET and POST commands?

e.g:

stateExtension = GET
commandExtension = POST or PUT

Thank you very much. :slight_smile:

I think that /%2$s/3ef204 as commanfExtension should work. You need to set onValue to on and offValue to off.

3 Likes