Http1 binding using a base url

Hey Community,
I’ve configured http1 binding to pull from and push to a Fully Kiosk Browser installed tablet. This Android app has a nice REST API to query data and to set values. Thus one can easily control the tablet via Openhab. To conveniently create many items it would be very helpful if http1 binding would accept a base url. Ideally I’d like to achieve the following:

services/http.cfg:

 eg-oh-tablet.url=http://192.168.1.123:2323/?password=my_password&type=json
 eg-oh-tablet.updateInterval=30000

This part of the URL is always the same in any item. In the item config I’d like to add the item specifig URL part like this:

{ http="<[eg-oh-tablet&cmd=deviceInfo:30000:JSONPATH($.batteryLevel)]" }

As you can see, I have used the config from http.cfg and extended by some more characters which will return the device info in JSON.

When testing this I received the following debug error message in openhab log.

2018-07-31 09:26:22.545 [DEBUG] [ab.binding.http.internal.HttpBinding] - item 'eg_flur_tablet_bat2' is not a valid URL or is a cache id yet to be initialised (eg-oh-tablet&cmd=deviceInfo)

In fact I suspect my idea does not work.
Does anyone have an idea how to shorten the items config while remaining flexible? Is this worth a feature request on github?

Thanks for your help.
Best Sebastian

I don’t think you can use http binding that way… You cannot put a base html in http.cfg and append something in the item definition. You have to use the full url.
I’m also using Fully Kiosk, see my post.

Hey @Mihai_Badea,
thanks for your reply. As I received an error message I know that the binding cannot be used like this. I was more asking for alternatives or if it would make sense to file a feature request.
In case I’m NOT the only one who would like to use the binding this way, it might make sense to have this implemented.

Th configuration you enter in http.conf is a cachedItem.
As per documentation:

Caching is usable when multiple items could be parsed from the same URL. 

and that is the case here, with deviceConfig from Fully’s REST API. The binding queries that url and cache the response. You then use the cached response and extract form there whatever info you want.
If you want to append something to the base URL, I think it will defeat the purpose of caching, isn’t it?
Appending something will change the URL so you might as well use it directly in the items definition as it will not retrieve the date from cacheItemName.

Number Fully_Battery { http="<[http://192.168.1.123:2323/?password=my_password&type=json&cmd=deviceInfo:30000:JSONPATH($.batteryLevel)]"}

You’re absolutely right. For inbound items that do not change frequently caching is a valid use-case.
For outbound items using POST method, you dont need caching and this is where “base-url” would come in handy. FKB currently supports adjusting 112+ settings. The URL differs in exactly one parameter. In order to shorten the item config I asked myself about the base-url feature that some other tools have. Less manual typing is less error prone, easier to read and to adjust.
In case you are security concerned you might want to change the FKB password. One would be able to do this in the base-url config, rather than in ALL configured items.
Thanks

It sounds like a good addition for the http binding. I’m not certain it is feasible to implement though. In the mean time you can consolidate them all into a single Rule and apply Design Pattern: Associated Items and/or Design Pattern: Encoding and Accessing Values in Rules Approach 3. Basically use sendHttpGetRequest and the name of the Item to build the URL to query.

It might require creation of proxy Switch Items so you would have to decide whether 2x unbound items is less onerous to repeating the http binding config over and over.

1 Like