.setLabel doesn't change it's value in sitemap

  • Platform information:
    • Hardware: _ Raspberry Pi 3 Model B Rev 1.2_
    • OS: Raspbian GNU/Linux 10 (buster)
    • Java Runtime Environment: (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
    • openHAB version: 2.5.4-1, NGRE, JSR223/Jython

Hi all,
I’m on the way to migrate my OH-Rules to Python/Jython. Now I have a little problem with the following command-line in my script:

ir.getItem("localDayTempForecast_{}".format(day_count)).setLabel(u"Temperatur-Aussicht:({:>10}): [%s]".format(DateTime.now().plusDays(day_count).toString("EE, d.MMM")))

The command changes the Label of an item, but there is no refresh in the sitemap only if I made it manually via browser.

.items is:

//   ++++++++++++++++++  Concatenation for sitemap presentation +++++++++++++++++++++++++++++++++++++++++++++++
String localDayTempForecast_0 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule
String localDayTempForecast_1 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule
String localDayTempForecast_2 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule
String localDayTempForecast_3 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule
String localDayTempForecast_4 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule
String localDayTempForecast_5 "Vorschau Temp. [%s °C]" <forecast> (gOWM1,gAVGTemp) // Value calculated via Rule

.py is:

from core.rules import rule
from core.triggers import when
from core.date import format_date
from org.joda.time import DateTime

def measurement(measurement_name="localHourlyForecastTemperature_", measurement_day_name="localDayTempAVG_", start_with=0, avg_yesno="yes", multi=1, low_high="no", log="no"):
    Parameters are:
     measurement_name       : is the fixed part of the forecast-items from owm-channels
     measurement_day_name   : is daily aggregation-item of the corresponding forecast-items (measurement_name)
     start_with             : includes (0) or excludes (1) current item-value
     avg_yesno              : is used wether calculate an average or to summarise daily aggregations e.g. Rain or Snow
     multi                  : is used for forecast-items which shows it's values for 1-hour Period only to multiply by 3, e.g Rain or Snow
     low_high               : calculate low and high temp. from the daily "normal" temperature as described in "measurement_name" - values are 'yes' or 'no'
     log                    : log daily measure-list in logger
    if start_with > 1 or multi < 1:
        owm_main.log.info("'start_with' {} or 'multi' {} have not valid values".format(start_with, multi))
    day0 = 1 + 8 - int(round(float(format_date(ir.getItem("localLastMeasurement_00").state, format_string="HH")) / 3))
    time_beam = [start_with, day0, day0+8, day0+16, day0+24, day0+32, 41, 41]
    for dayindex in range(0, 6):
        list_measure = []   # list of daily measure-values
        daily_forcasts = time_beam[dayindex+1] - time_beam[dayindex]
        daily_counts = 0
        for suffix in range(time_beam[dayindex], time_beam[dayindex+1]):
                daily_counts += 1
                # check if daily aggregation has to be done
                if daily_forcasts == daily_counts:
                    # logging information in logger for testing
                    if log == "yes":
                        owm_main.log.info("list of measures: {} days: {} item-Name: {}".format(list_measure, len(list_measure), measurement_day_name + str(dayindex)))
                    # check if daily-average is wanted
                    if avg_yesno == "yes":
                        events.postUpdate("{}".format(measurement_day_name + str(dayindex)), str(sum(list_measure) / len(list_measure)))
                    # daily sums will be determined
                        events.postUpdate("{}".format(measurement_day_name + str(dayindex)), str(sum(list_measure) * multi))
                    # get daily min/max values
                    if low_high != "no":
                        events.postUpdate("{}".format("localDayTempMin_" + str(dayindex)), str(float(min(list_measure))))
                        events.postUpdate("{}".format("localDayTempMax_" + str(dayindex)), str(float(max(list_measure))))

            except BaseException as err:
                owm_main.log.warn("No more items: {} error: {}".format(measurement_name+"{:02d}".format(suffix), err))
                owm_main.log.warn("what happened that i'm landing here: {} {}".format("hallo", "welt"))
#                break
#    owm_main.log.info("End Measurement")

@rule("OpenWeatherMap_list", description="Current Weather and Forecast Information", tags=["owm", "temperature", "rain", "snow"])
#@when("Item owmTriggerSwitch changed to ON") # for testing
@when("Item localLastMeasurement_00 changed")
@when("System started")
def owm_main(event):
    global LOG_OWM
    # calculate daily sums
    measurement(measurement_name="localHourlyForecastTemperature_", measurement_day_name="localDayTempAVG_", start_with=0, avg_yesno="yes", low_high="yes", log="yes")
    measurement(measurement_name="localHourlyForecastRainVolume_", measurement_day_name="localDayRainTotal_", start_with=0, avg_yesno="no", multi=3)
    measurement(measurement_name="localHourlyForecastSnowVolume_", measurement_day_name="localDaySnowTotal_", start_with=0, avg_yesno="no", multi=3)
    measurement(measurement_name="localHourlyForecastPressure_", measurement_day_name="localDayPressureAVG_", start_with=0, avg_yesno="yes", multi=1)
    measurement(measurement_name="localHourlyForecastHumidity_", measurement_day_name="localDayHumAVG_", start_with=0, avg_yesno="yes", multi=1)
    measurement(measurement_name="localHourlyForecastSensTemperature_", measurement_day_name="localDayTempSens_", start_with=0, avg_yesno="yes", multi=1)
#    measurement(measurement_name="localHourlyForecastMiniTemperature_", measurement_day_name="localDayTempMin_", start_with=1, avg_yesno="yes", multi=1)
#    measurement(measurement_name="localHourlyForecastMaxiTemperature_", measurement_day_name="localDayTempMax_", start_with=1, avg_yesno="yes", multi=1)

#  ++++++++++++++++++++++++++++++++++++++++  Concatenate Temperatures for sitemap presentation ++++++++++++++++++++++++++++++++++++++++++++++++++++
    for day_count in range(0, 6):
            ir.getItem("localDayTempForecast_{}".format(day_count)).setLabel(u"Temperatur-Aussicht:({:>10}): [%s]".format(DateTime.now().plusDays(day_count).toString("EE, d.MMM")))
            events.postUpdate("{}".format("localDayTempForecast_" + str(day_count)), u"{:<13}{: 4.1f}/{: 4.1f}/{: 4.1f} °C".format( \
             "min/max/avg:", ir.getItem("localDayTempMin_"+"{}".format(day_count)).state.floatValue(), \
             ir.getItem("localDayTempMax_"+"{}".format(day_count)).state.floatValue(), ir.getItem("localDayTempAVG_"+"{}".format(day_count)).state.floatValue()))
        except BaseException as err:
            owm_main.log.warn("Something went wrong: {} error: {}".format("The error is", err))
            events.postUpdate("{}".format("localDayTempForecast_" + str(day_count)), u"{:<13}{: 4.1f}/{: 4.1f}/{: 4.1f} °C".format("min/max/avg:", 0.0, 0.0, 0.0))
    #  Sometimes give a messsage to show that the Script is still alive and running
    LOG_OWM += 1
    if LOG_OWM >= 4:
        owm_main.log.info("2 End Rule - I'm still alive - Log Count is {} ".format(LOG_OWM))
        LOG_OWM = 0

When the script is triggered sitemap shows:

When making a manual refresh of the sitemap, I get:

Any hints for me ? I am grateful for all the answers.

thx in advance

It’s an undocumented function, the UIs don’t listen for label changes.

1 Like

Thx for reply.
I don’t know if it’s undocumented, as I found information about it here and here and of course here.
As I’m trying to learn Python/Jython/jsr223 and trying to migrate my DSL-Rules to Python-Scripts, I looked here and there and found the above sources.
As said I’m running OH with NGRE/JSR223 on my testmachine, where also the original “owm-script” of Scott is running, which has a lot of such features, and which is the base for my learnings.
Maybe OH3 will understand the code???!! :wink:

There’s no problem with the code. The code is doing as expected, changing the Item label text.
Your problem is the UI doesn’t know or care that it changed.

I don’t expect it’ll be any different in OH3, it might.
In order for this to work as you wish, several things would have to happen -
openHAB core would have to create a new event signalling Item label change.
Every UI would have to be modified to listen out for the new events and update display.

1 Like

thx again.
It’s a pity. But then one can’t do anything. I thought so. Even if I first made the change of the label and then update the item’s value.
So I have to think about to do it like Scott does in his owm.py script. Where he removes and recreates those items “on the fly” and not using items of a textual configuration. But at the moment this is too big stuff for me.
It’s always a pleasure for me to discuss with you and getting a helping hand, as in my former “owm.rules” if you remember. :wink:
Cheers - Peter

1 Like