-
Platform information:
- Hardware:RPi 3b
- OS: Release = Raspbian GNU/Linux 9 (stretch)
- Kernel = Linux 4.19.58-v7+
- Platform = Raspberry Pi 3 Model B Rev 1.2
-
Java Runtime Environment:
openjdk version “1.8.0_222”
OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation) -
2.5.0M2
I want to make a new variable out of two, to summarise in that variable within a rule.
So I have the following variables.
.rules (snippet)
rule "Test mit Variablen"
when
Item Dummy4 changed to ON
then
logInfo ("Test", "Starts" + " + " + triggeringItem)
var tmp_timestamp = new DateTime().toString("yyMMdd")
........
//++++ Temperature Results for the days
var Number sum_temp_day0 = 0
var Number sum_temp_day1 = 0
var Number sum_temp_day2 = 0
var Number sum_temp_day3 = 0
var Number sum_temp_day4 = 0
var Number sum_temp_day5 = 0
var Number avg_temp_day0 = 0
var Number avg_temp_day1 = 0
var Number avg_temp_day2 = 0
var Number avg_temp_day3 = 0
var Number avg_temp_day4 = 0
var Number avg_temp_day5 = 0
//+++++ for daily MIN/MAX Temperature-Values
var Number min_temp_day0 = 999.9
var Number min_temp_day1 = 999.9
var Number min_temp_day2 = 999.9
var Number min_temp_day3 = 999.9
var Number min_temp_day4 = 999.9
var Number min_temp_day5 = 999.9
.......
val suffix_day0 = "day0"
val suffix_day1 = "day1"
val suffix_day2 = "day2"
val suffix_day3 = "day3"
val suffix_day4 = "day4"
val suffix_day5 = "day5"
var suffixTemp_day "day"
// somewhere in the rule
switch(tmp_timestamp) {
case temp_day.get(0): {
logInfo("owm-rules-test","Zeitstempel {} Count_Day0 {} test {} ", tmp_timestamp, temp_day.get(vCounter_day) ) // test 15.8.19
count_day0 = count_day0 + 1
sum_temp_day0 = sum_temp_day0 + tempItemTemperature.getStateAs(DecimalType)
//++++++++++++++++ Temperature Minimum of the day +++++++++++++++++++++++++++++++++++++++++++++++++
var Number min = 0
min = min + tempItemTemperature.getStateAs(DecimalType)
if (min_temp_day0 > min) {
min_temp_day0 = min
}
//+++++++++++++++ Temperature Maximum of the day +++++++++++++++++++++++++++++++++++++++++++++++++
var Number max = 0
max = max + tempItemTemperature.getStateAs(DecimalType)
if (max_temp_day0 < max) {
max_temp_day0 = max
}
//+++++++++++++++ Rain Sum of the day +++++++++++++++++++++++++++++++++++++++++++++++++
sum_rain_day0 = sum_rain_day0 + tempItemRainVolume.getStateAs(DecimalType)
//+++++++++++++++ Snow Sum of the day +++++++++++++++++++++++++++++++++++++++++++++++++
sum_snow_day0 = sum_snow_day0 + tempItemSnowVolume.getStateAs(DecimalType)
}
case temp_day.get(1): {
vCounter_day =1
logInfo("owm-rules-test","Zeitstempel {} Count_Day1 {} test {} ", tmp_timestamp, temp_day.get(vCounter_day) ) // test 15.8.19
count_day1 = count_day1 + 1
sum_temp_day1 = sum_temp_day1 + tempItemTemperature.getStateAs(DecimalType)
//++++++++++++++++ Temperature Minimum of the day +++++++++++++++++++++++++++++++++++++++++++++++++
var Number min = 0
At the moment this means in each “case” of the statemachine I summerize my values in fix-named variables like
count_day0 = count_day0 + 1
sum_temp_day0 = sum_temp_day0 + tempItemTemperature.getStateAs(DecimalType)
So my question is whether it’s possible to declare a temporary suffix in the “case” like this:
case temp_day.get(0): {
logInfo("owm-rules-test","Zeitstempel {} Count_Day0 {} test {} ", tmp_timestamp, temp_day.get(vCounter_day) ) // test 15.8.19
suffixTemp_day = suffix_day0
and then make the calculation after switch/case in this way:
sum_temp_+suffixTemp_day = sum_temp_+suffixTemp_day + tempItemTemperature.getStateAs(DecimalType)
Hope my explanation is understandable. Maybe there’s someone to help me.
thx in advance.