[SOLVED] OpenHab Eventstream

Hi everyone,
I have an OpenHab runtime running and communicating with it over REST-API. To implement a pushed based model into my application I have to subscribe from the OH SSE Stream. I can luckely connect to the stream to receive item events.
http://localhost:8080/rest/events?topic=smarthome/items/
I know that I can filter it by adding an item id(name). But my question is how can I receive all item change events, so the sse will only send me a message when a switch for example was triggered.
My next question is because I found no documentation for that, how can I subscribe to inbox events, so the sse will message me if a new ad hoc device was found for example in my zwave network. In common what types of event subscription are possible? Thanks in advance.

It’s been a while since I played with the REST API and SSE, but I believe you can do something along the lines of this:

http://localhost:8080/rest/events?topics=smarthome/items/{item}/statechanged

Have you installed the REST API documentation ‚Äúmodule‚ÄĚ (using PaperUI)? I am not sure if this answers your question, but it is a place to start at least.

http://localhost:8080/rest/events?topics=smarthome/items/{item}/statechanged

Yes exactly but I need to know how to receive all statechanges of all items without explicit adding an item id -> {item}
so something like
http://localhost:8080/rest/events?topics=smarthome/items/statechanged

Ah! OK, then I think you will need to simply ‚Äúsubscribe‚ÄĚ to the following (to get ‚Äúeverything‚ÄĚ) and do proper filtering on the event messages you receive:

http://localhost:8080/rest/events?topics=smarthome/items

Here is an example of an event message from my system:

event: message
data: {"topic":"smarthome/items/SystemInfoOdin_sCPU_Load/statechanged","payload":"{\"type\":\"Decimal\",\"value\":\"0.9\",\"oldType\":\"Decimal\",\"oldValue\":\"0.5\"}","type":"ItemStateChangedEvent"}

So, if you filter on ‚Äútype = ItemStateChangedEvent‚ÄĚ you should get what you want, or?

Hmm… I just did a simple test of the following:

https://home.myopenhab.org/rest/events?topics=smarthome/items/*/statechanged

And it seems to work well, i.e. it gives me only ‚ÄústateChangedEvents‚ÄĚ for all items.

Is this what you want/need?

1 Like

yes thanks a lot!