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

**URL:** <https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489>\
**Category:** Scripts & Rules\
**Tags:** jsr223, scripts, sitemap1\
**Created:** [May 9, 2020, 11:59pm UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489 "2020-05-09T23:59:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fibu-freak](https://community.openhab.org/user_avatar/community.openhab.org/fibu-freak/32/29710_2.png) [@fibu-freak](https://community.openhab.org/u/fibu-freak)\
**Post date:** [May 9, 2020, 11:59pm UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489/1 "2020-05-09T23:59:05Z")

</div>

- 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:

```auto
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:

```csv
// ++++++++++++++++++ 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:

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

LOG_OWM = 4
#-----------------------------------------------------------------------------------------------------------------------------------------------------------
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))
        return
    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]):
            try:
                list_measure.append(float("{:.2f}".format(ir.getItem(measurement_name+"{:02d}".format(suffix)).state.floatValue())))
                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
                    else:
                        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))))
                else:
                    pass

            except BaseException as err:
                owm_main.log.warn("No more items: {} error: {}".format(measurement_name+"{:02d}".format(suffix), err))
            except:
                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):
        try:
            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:

 ![grafik](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/7/9/79c8a256a164527b7cb387ce7c56359a7a3d727d.png)  
When making a manual refresh of the sitemap, I get:  
 ![grafik](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/c/4/c4673fb24b843a68313fa4ae053f2fb900f5a46b.png)

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

thx in advance

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 10, 2020, 12:54am UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489/2 "2020-05-10T00:54:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fibu-freak](https://community.openhab.org/user_avatar/community.openhab.org/fibu-freak/32/29710_2.png) [@fibu-freak](https://community.openhab.org/u/fibu-freak)\
**Post date:** [May 10, 2020, 4:01am UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489/3 "2020-05-10T04:01:46Z")

</div>

Thx for reply.  
I don’t know if it’s undocumented, as I found information about it [here](https://community.openhab.org/t/experimental-next-gen-rules-engine-documentation-4-of-writing-scripts/55963) and [here](https://community.openhab.org/t/solved-using-item-label-in-timer-routine/86015/3) and of course [here](https://openhab-scripters.github.io/openhab-helper-libraries/search.html?q=setlabel&check_keywords=yes&area=default).  
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???!! 😉

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [May 10, 2020, 9:00am UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489/4 "2020-05-10T09:00:26Z")

</div>

> [@fibu-freak](#):
>
> Maybe OH3 will understand the code?

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.

---

<div class="post-metadata">

**Author:** ![fibu-freak](https://community.openhab.org/user_avatar/community.openhab.org/fibu-freak/32/29710_2.png) [@fibu-freak](https://community.openhab.org/u/fibu-freak)\
**Post date:** [May 10, 2020, 12:03pm UTC](https://community.openhab.org/t/setlabel-doesnt-change-its-value-in-sitemap/98489/5 "2020-05-10T12:03:47Z")

</div>

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. 😉  
Cheers - Peter
