Openhab Rest Api Event Source

I am trying to hear the status of items about the rest of Api in conjunction with event sourcing. However, I never get an answer from any item.

I have already tried all possibilities I found here or on the net.

Does anyone have an example that works? Or is there a documentation somewhere? There is nothing in the official documentation of Openhab Rest Api.

Have you installed RestDocs and tried from its WebUI?

It’s not clear what you are after. You want to subscribe to events on Items on some external program? If so you need to subscribe to the SSE feed openHAB provides. You can find an example of that for Python discussed at Python Example of Subscribing to openHAB's SSE Feed

Note that SSE is one-way, meaning you can only subscribe not publish. If you also want to send events to OH Items you need to use the OH REST API which is thoroughly documented in the REST API Docs addon you can find to install in the UIs tab in PaperUI.

I’m programming a dashboard for myself with Angular and of course I want to display/query the current values of my different devices there.
Of course I could also query the rest service in an interval. But that is not so nice.

Tried it once with this. Chrome also shows me that the request is kept open. But somehow nothing ever gets through to me/client.

    const eventSource = new EventSource("http://adress:8080/rest/events?topics=smarthome/items/RaspberryPi4_Sensors_CPUTemperature/statechanged");

eventSource.onmessage = function (eventPayload) {
  var event = JSON.parse(eventPayload.data);
  console.log(event);
};

This worked for me

It’s practically the same code, if you think of HTML without it. The same thing happens as with me. Connection is kept open but somehow I don’t get an answer.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.