[SOLVED] How to Access/Controll OH Items from other applications

hello friends,

I want to Develop a ui to visualize and controll my OH Items. my Plan ist to use a mqtt Broker as the central point and on the OH side the mqtt Binding to send the Item states to the topics and so on. then, my own application (angular 4 based) will also subscribe the topics of the items. the angular application will have the posibility to change the item states as well as the simple visualisation of the current item state.

what my question is to you, does this make sense to use the planned mqtt way or do you think that there is an other maybe a less hard way of getting and changing the item states from a other application (ui) ?

it would be very helpful to get your tips and advices.

cheers, tobi

You can use MQTT or use /rest/events as an EventSource in your client. Every item change will be in that event source. To submit a change you can send a POST/PUT/etc to /rest/item. These are all documented…

If you want to be more creative, create a websocket on the server side (Java) and connect your clients to that. You can get rid of POSTing (or any REST calls) since the websocket can be designed (by you) to be two-way.

Since you are using Angular I’m assuming this is a webbased UI. Since that is the case I would go down the REST approach like Lucky suggests.

Look at how the other OH UIs use web sockets and the REST API to interact with OH. All of the OH UIs use this approach.

Hello Guys,

thank you for your tips. i will try the REST way. do you know if there is a tutorial or something helpful to get this done? i have never worked with REST APIs by myself and OH.

cheers, tobi

I suggest you read up on online tutorials regarding web/REST APIs. Start with that first, then move on to OH. I’m just a bit confused on your experience regarding web development. Angular is an advanced framework… so I suggest you first start with making your first hello world REST request using vanilla JS

hey lucky,

thanks for your message. i think my answer was a little bit confusing to you, what i wanted to say is that i have, in my openhab projects no experience with using a REST API, i have always used mqtt for transmitting states and so on. with my post i wanted to ask if you you think that the use of REST APIs for that purpose would be a better choice than mqtt.

cheers tobi

That’s exactly what I’m trying to say. If you have an MQTT client, then that client must be POSTing to the MQTT server. That itself is a REST call. If you’re trying to create a web-based UI and want to use MQTT, you still need to know how REST works.

Hi Tobias,

Have you tried to install the REST documentation in your openHAB environment? (Paper-UI / Add-ons / MISC / REST documentation)

If I recall correctly, after installing it, you will find a new tile in your home page while accesing your openHAB web. That tile will give you access to play with REST api in a very simple and effective way.

Hope this helps.

1 Like

Thank you Daniel, that’s very interesting and helpful!
cheers, tobi