- 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
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:
When making a manual refresh of the sitemap, I get:
Any hints for me ? I am grateful for all the answers.
thx in advance