Java Runtime Environment:
openjdk version “11.0.7” 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Raspbian-3deb10u1)
OpenJDK Server VM (build 11.0.7+10-post-Raspbian-3deb10u1, mixed mode)
openHAB 2.5.5 (Release Build)
Hello OpenHAB Community,
I am using the OpenWeather binding to display multi-day forecasts in a sitemap, with each day’s forecast in a separate frame. I’m using groups to do this, but the labels for the groups soon become rather confusing to the user. To overcome this, I’ve created a rule, which I’ve successfully implemented as a test for “Today”. See below.
One thing that puzzles me though is why the following does not set the label of gTodays_Weather_Forecasts as expected.
gTodays_Weather_Forecasts.label = gTodays_Weather_Forecasts_Label.label // Results in "Label: Weather Forecasts for", instead of "Weather Forecasts for Wednesday, May 27, 2020 (Today)"
rule "Update Label Test" // Test for dynamically updating the label of Today's weather frame.
Time cron "0/30 0/1 * 1/1 * ? *" // Fires every 30 seconds for test puposes since I don't want to wait until midnight
//Time is midnight
gTodays_Weather_Forecasts_Label.postUpdate(Weather_Forecasts_Date.state.format("%1$tA, %1$tB %1$td, %1$tY").toString)
gTodays_Weather_Forecasts.label = String::format("Weather Forecasts for %s (Today)", gTodays_Weather_Forecasts_Label.state)
logInfo("openweather.rules", "Update Label Test rule completed")
Could you perhaps tell us what you actually get that you do not expect?
However, there’s no reason to think that gTodays_Weather_Forecasts_Label.state has the value you expect when you use it.
postUpdate is asynchronous, the request goes on to openHABs event bus, and eventually the Item state actually gets updated. It likely only takes a few milliseconds, but the rule does not stop and wait.
That means that if you read the same Item’s state in the next line you will almost certainly get the “old” value.
That’s fine, you don’t need to read back the state because you already know exactly what you just postUpdated to it.
Note that in-flight editing of labels is an undocumented feature, and different UIs may be more or less effective at refreshing any changes.