Hi there
I want to use in my openHAB 3.2.0 (on RASPI 3) environment the following Script/Rule, to display the ‘Temperature Trend’ in my Habpanel, but if i run the rule the system get’s extremly slow and things began to go offline and online as i can see in the log file.
This what i want to do:
This is the Script/Rule that calculate average of last 1h - first 30 mins compared to last 30 minutes of the hour - and based on that posts an update that i use:
- 1 if temperature is raising,
- 0 if temperature did not change,
- -1 if temperature is falling.
val updateDiff = [ GenericItem sourceItem, GenericItem item, double limit, String name, int offset |
val n = 30
var nn = 0
var double avgPre = 0
var double avg = 0
var i = 2 * n + 1
while(( i = i - 1 ) >= n) {
val historicState = sourceItem.historicState(now.minusMinutes(i + offset))
if (historicState !== null) {
var y = (historicState.state as DecimalType).doubleValue
avgPre = avgPre + y
nn = nn + 1
}
}
avgPre = avgPre / nn
nn = 0
i = n + 1
while(( i = i - 1 ) >= 0) {
val historicState = sourceItem.historicState(now.minusMinutes(i + offset))
if (historicState !== null) {
var y = (historicState.state as DecimalType).doubleValue
avg = avg + y
nn = nn + 1
}
}
avg = avg / nn
val diff = avg - avgPre
//logInfo("TTM", "result {}: {} <- {} vs {}", name, diff, avgPre, avg)
if (diff > limit) {
item.postUpdate(1)
} else if (diff >= -limit) {
item.postUpdate(0)
} else {
item.postUpdate(-1)
}
]
rule "Temperature Trend Monitor"
when
Time cron "1 * * * * ?"
then
updateDiff.apply(Outside_ds18b20_temperature, Outside_ds18b20_temperature_slope, 0.35, "Outdoor", 0)
updateDiff.apply(FF_Nik_Room_temperature, FF_Nik_Room_temperature_slope, 0.10, "Nik's Room", 0)
updateDiff.apply(FF_Bed_Room_temperature, FF_Bed_Room_temperature_slope, 0.10, "Eva's Room", 0)
end
and this is what i get in the log-file when the script is running:
as i told, the system begans to get extremley slow, so i have to disable the script/rule and reboot the system.
Is there abetter way to to do, what i want to do, or a better script/rule to do this?