SSE Events - How to use /sitemaps/events/{subscriptionid}

Hello guys,

i try to use SSE events from openhab for an interative sitemap for a native sailfis-os app with this two endpoints here:

POST /rest/sitemaps/events/subscribe
GET /rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid"

The first endpoint is working fine, i get a 200 with the subscription-id.

Test-setup: I call second endpoint to open event-stream and afterwards i change via openhab interface an item related to this sitemap, to check if an event is coming in.

When i try to use the second endpoint, i get nothing back in the event-stream. I also tried to call the endpoint manually, but there i receive nothing as well:

curl -N 'http://exampleip:8080/rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:14 --:--:--     0

I also tried it with sitemap and page-id as optional paramter:

curl -N 'http://exampleip:8080/rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid?sitemap=Test'

curl -N 'http://exampleip:8080/rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid?sitemap=Test?pageid=0000'

with same result. Do you know what i did wrong and can you help me here, guys?

sidenote: if i try to call the following endpoint, i receive a bunch of events every time:

curl -N 'http://exampleip:8080/rest/events'

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0event: alive
data: {"type":"ALIVE","interval":10}

100    51    0    51    0     0     22      0 --:--:--  0:00:02 --:--:--    22event: message

but if i understood it right this endpoint should not be used to stream events for a sitemap, because there are all possible events and not the events for the sitemap only.

i also tried to use events from all sitemaps, but there are no events coming in - even if i change the state of items:

curl -N 'http://exampleip:8080/rest/sitemaps/events/bf665415-d941-4606-9b94-6598db977b2e/*'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:30:16 --:--:--     0

You need to provide the Sitemap name and the pageId as query params, the API Explorer in Main UI also shows this:

When providing the source of the servlet, an LLM should also be able to help you with the subscription:

Thanks Florian, i already tried this in this two combinations (with sitemap-Name + Id, with sitemap-name without id):

curl -N 'http://exampleip:8080/rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid?sitemap=Test'

curl -N 'http://exampleip:8080/rest/sitemaps/events/7a814d7c-e916-4966-934a-exampleid?sitemap=Test?pageid=0000'

result:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:03:57 --:--:--     0

I tried it directly within cpp and with curl in the command line – same result. Do you have any ideas what i do wrong here? I also already asked LMM before, will try it again with the reference to the code implementation

I have the following sitemap:

sitemap page_04a97f4baa label="Sitemap" {
    Switch item=Florians_Verstarker_Stumm_schalten
}

with this UID: page_04a97f4baa

Listening to the changes on the root page (which is the only one in this example) works for me like this:

~> curl -X POST "http://localhost:8080/rest/sitemaps/events/subscribe" -H "Accept: application/json"
{"status":"CREATED","context":{"headers":{"Location":["http://localhost:8080/rest/sitemaps/events/baeface2-ed57-4c9d-b8b5-e0bdf70ef84a"]},"committingOutputStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false},"entityAnnotations":[],"entityStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false}}}⏎           

~> curl -N -X GET "http://localhost:8080/rest/sitemaps/events/baeface2-ed57-4c9d-b8b5-e0bdf70ef84a?sitemap=uicomponents_page_04a97f4baa&pageid=uicomponents_page_04a97f4baa" -H "Accept: text/event-stream"
event: event
data: {"widgetId":"00","label":"Stumm schalten","labelSource":"ITEM_LABEL","icon":"soundvolume_mute","reloadIcon":true,"visibility":true,"item":{"state":"OFF","lastState":"ON","lastStateUpdate":1771864031325,"lastStateChange":1771864031325,"type":"Switch","name":"Florians_Verstarker_Stumm_schalten","label":"Stumm schalten","category":"SoundVolume_Mute","tags":["SoundVolume","Switch"],"groupNames":["Florians_Verstarker"]},"descriptionChanged":false,"sitemapName":"uicomponents_page_04a97f4baa","pageId":"uicomponents_page_04a97f4baa"}

You may be missing the Accept header.

i tried it with the same setup now:

subscription:

{"status":"CREATED","context":{"headers":{"Location":["http://10.10.0.20:8080/rest/sitemaps/events/879aaeef-df22-410b-abc5-2e6dc0ca7897"]},"committingOutputStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false},"entityAnnotations":[],"entityStream":{"bufferSize":0,"directWrite":true,"isCommitted":false,"isClosed":false}}}

sitemap:

homepage":{"id":"Test","title":"TEST","link":"http://10.10.0.20:8080/rest/sitemaps/Test/Test"

Subpage:
"id":"0000","title":"Erdgeschoss","icon":"groundfloor","link":"http://10.10.0.20:8080/rest/sitemaps/Test/0000"

command for main page:

 curl -N -X GET "http://10.10.0.20:8080/rest/sitemaps/events/879aaeef-df22-410b-abc5-2e6dc0ca7897?sitemap=Test" -H "Accept: text/event-stream"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:33 --:--:--     0

command for sub-page:

 curl -N -X GET "http://10.10.0.20:8080/rest/sitemaps/events/879aaeef-df22-410b-abc5-2e6dc0ca7897?sitemap=Test&pageid=0000" -H "Accept: text/event-stream"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:37 --:--:--     0

Unfortunately there are no error-logs within openhab. I also changed the logging from INFO to DEBUG with no success. Is it maybe my Openhab-version? I have installed currently 5.1.0. Or does any UI-Settings prevent the sitemaps-events from being generated (But should not be the case because the eventstreaming seems to work on iOS app as well).

I don’t think there is an error in openHAB. Basic UI, Android App & iOS App, all work fine with it.
BTW tip: You can also check the network tab of the browser dev tools when navigating Basic UI to watch the network requests made.

ok thank you i will try this as well. Yeah you’re right, the other apps are working, so it something i did wrong with the subscription. I will investigate further.

1 Like