Java Script Library for UI development

Hello,
I intend to develop a web user interface to control a device via the openHAB
REST API. Since I want to use the user interfaces on several openHAB 2
instances, I do not want to hardcode the REST end-points in the user
interface. Instead, I want to define the thing-type only and the thing and
all relevant URLs of the related items should be discovered automatically.
So in order to control an item, I do not want to control it via its URL.
Instead I only want to specify the relevant channel.

Example:

<thing-type id="tv">
<channels>
 <channel id="volume" typeId="volume" />
 </channels>  
<thing-type>

Client code:

    var openhab = new openHAB() // discovers the openHAB server in the network.
    var myTV = openhab.discover("tv"); // searches all available things for one of type tv
    myTV.set("volume", "80");

Is such a library already available?

Thanks in advance

1 Like

You can look at what HABPanel is doing. Maybe there is something there you can reuse.

But I will say that either your example is a bit contrived to make a point or you don’t really understand how Things work.

First of all there is no “tv” Thing type. Each binding has its own Thing syntax and a typical Thing ID looks like “zwave:device:bb654ed6:node5” or “network:device:richphone”. Assuming there were The channel IDs are typically appended to the Thing ID, e.g. “zwave:device:bb654ed6:node5:alarm_general”. And I could be wrong about this, but I think one can change the Thing ID.

Given this, going after the Things doesn’t buy you anything because you will have to hard code that.

Secondly there are no Things at all for 1.x bindings, only Items.

openHAB is very purposefully set up to to control everything via ITEMS, not Things. If you skip the Items and go straight to the Things you will be bypassing the event bus, persistence, transformations, and rules. This is why the openHAB REST API doesn’t provide a way to control a Thing directly. You should go through the Item.

All that said, you don’t have to hard code in your Items. You can get a list of all the Things and narrow that list down based on some criteria (maybe that it contains “tv” in its ID), and then get the Items mapped to each of the Thing’s channels. From there you will have the name of the Item and can call its REST API.

Thanks for your answer. Let me try to explain a little bit more what I intend to do:

Use Case 1:

A person has two apartments, each equipped with an openHAB gateway and the same TV set model, but some differences in the overall configuration. When moving from one apartment to another the person wants to use the same user interface.

So in this case I can use the process you have described:

“…You can get a list of all the Things and narrow that list down based on some criteria (maybe that it contains “tv” in its ID), and then get the Items mapped to each of the Thing’s channels. From there you will have the name of the Item and can call its REST API.”

Use case 2:

Someone exchanges a new TV set against a new one but wants to keep his familiar user interface. Although the TV set models are not the same model they have some basic common functionality e.g. volume, current channel. So, if both TV sets are modelled by using the same channel-types the following should be possible:

List all available things, and then not to look for certain thing-types, but for a thing that contains certain channel-types. From there and then get the Items mapped to each of the Thing’s channels.

Should this be possible and are there libraries available to sort the things?

Might categories help?

Unless both TV sets use the same Binding they will not have the same channel-types. Channels are completely defined by the binding authors and there is no mechanism within openHAB at this time to support standardization of the channels. Samsung may have samsung:tv:volume and Sharp (btw there is no Sharp 2.0 binding) may have sharp:123456789:vol. And this approach that uses Channels would exclude anything that only has a 1.9 version binding since those don’t support Things and Channels.

And there may never be a standard set of channels since the design of OH is that the common set of standard features are the Items, not the Things and Channels.

There are no libraries. HABPanel may have some code that could be made into a library. But ultimately you will have to work with and figure out how to use the REST API.

In your use case 2, the proper OH 2 approach would be to keep the same Items and just change which Channels the Items are mapped to. No changes necessary to any other part of OH and there shouldn’t be any needed changes to your UI.

Ultimately I think you are missing the point of Items. Items are intended to provide that level of abstraction so you can swap out your TV, update your Items to point to the new TV, and NOTHING else needs to change. That seems to be what you are trying to achieve, only you want to do it without modifying the Items and that is the source of the trouble.