Refresh Screen, i.e. Basic UI from rules and binding code

Dear Community,

There are several ways to store, update and delete data in openHAB, for example “rules” or “bindings”.

Usually such changes will be done in the background, i.e. changing the state of a switch item from ON to OFF, but the UI will not be refreshed automatically. What is the most preferred way to tell openHAB to refresh its current user interface or the section of the corresponding item? Thanks in advance.

Best regards,
Jochen

Based strictly on observation and not on looking at the actual code, but I believe the UIs subscribe to a websocket where it receives the stream of events from the EventBus. I suspect that any “changed” event on an Item will cause the UI to refresh that element.

That is in keeping with the EventBus architecture. Everything that needs to know about events in OH (UIs, bindings, Rules, persistence, etc) subscribes to the bus and reacts to those events appropriately. Based on some bugs I’ve seen in the UIs in the past, I doubt there is any “refresh” type event you can publish.

1 Like

Thanks Rich,

here is a code snippet to clarify what I meant:

// set state of text field
try {
    State newState = new StringType(randomLine);
    updateState(CHANNEL_1, newState); ...

I am in the handleCommand() method of the handler class. I got a switch (CHANNEL2) which got triggered after changing the state from ON to OFF. In CHANNEL1 there is the item, a text label which should change its state. In the logfiles I can see that the value of the text changed but in the Basic UI the text is not updated. I hope this explanation makes the situation clearer than before.

Best regards,
Jochen

It’s not really clear what you are talking about. BasicUI is Items based, so channel activity is irrelevant unless/until an Item state update is caused.
Furthermore, it’s designed around Item state updates. Changing the label of an Item is not a state update, so won’t get called upon in whatever the usual refresh process is.

My bad - I changed the value of the item - so I would expect, that an event is triggered.

Does updateState() leads to a refresh on the Basic UI usually?

I do not think so.
I think an Item state change will (eventually) refresh, maybe within a second or five. An update is not necessarily a change.
The Item concerned needs to be active in the current display, I believe. I don’t think invisible Items are refreshed.

There are ways to break the sitemap, that leave an apparently working UI that does not refresh - example getting the filename wrong.

Thanks rossko57,

here is a picture of my logs (left side) and basic UI (right side). As you can see, the item state changed event is triggered, but basic UI stays static. Anyway it is possible to toggle the switch, so the UI is not frozen at all.

Cheers
Jochen !

openhab-error-refresh|690x116

Nobody suggested UI is frozen. Lack of a timely refresh of external changes is not freezing.

There are lots of threads and github issues about UI refresh. It’s all rather creaky, and people get different results in different UI, browsers, etc. The bottom line is that you cannot do anything about that from a binding.

For a sitemap based UI, it is very important that the filename given in the head exactly matches the actual filename of the xxx.sitemap file, including case.

Thanks rossko57,

that seems pretty annoying for developers. In the old Java Swing days the methods which were validating the UI components and were refreshing them, was pretty important. Maybe this feature will be implemented in future in openHAB too, we will see. So I guess it is time to move on and solve other issues in my code.

Best regards,
Jochen