REST API Eventstream filtering

  • Platform information:
    • Hardware: Intel NUC i3 16Gb RAM 500Gb SSD
    • OS: Ubuntu 20.04LTS
    • Java Runtime Environment: Zulu JRE11
    • openHAB version:3.1.0

Issue of the topic:
I’m building a React UI which uses the REST API event streams in a CQRS manner in that the UI only ever reflects the state of the system. Commands sent from the UI only result in changes to the UI after openHAB emits an event relating to the completion of the requested command.

I receive most of the needed information from

const eventUrl="";

But in order to ensure that elements of my home system which go offline are properly displayed in the UI I am also subscribing to the status stream at

const statusUrl = ''

This stream is fine for startup but once the current status of the home items has been established I would like to use a “statuschanged” stream so that I am only having to interpret a small number of events e.g. when lights get switched off at the wall or sensors are unplugged.

I have tried the following url variations to achieve what I want but with no success.

const changedUrl = '*/statuschanged'
const changedUrl = ''
const changedUrl = '*/statuschanged'
const changedUrl = ''
const changedUrl = '*/statuschanged'
const changedUrl = ''
const changedUrl = '*/statuschanged'
const changedUrl = ''

I all cases the stream I receive seems to contain all events for state and status rather than a filtered stream.

I am clearly missing something in the url syntax.

Can anyone point me in the right direction please?

Many thanks in advance
Ian Carson

Answering my own question:

The correct URL form for filtering on ThingStatusInfoChangedEvent is*/statuschanged

Unlike my many other unsuccessful attempts the proper call needs to

  • use “topics” not “topic”
  • start the topic with “openhab” not “smarthome”
  • use a wildcard of “*” to substitute for any “{thingUID}” in that place in the topic

All working nicely now.

Hopefully this little nugget of information will be useful to someone else as well


1 Like