I am trying to evaluate the minimal temperature over a given timespan.
Therefore I have the following:
items:
Number:Temperature HEATING_WOHNBEREICH_TEMPERATURE "Temperature Wohnbereich [%.1f %unit%]" <temperature> {channel="mqtt:topic:mosquitto:aqaraTemperatureWohnbereich:temperature"}
Rules DSL excerpt:
val Number historicValuesTimespan = 120
val Number currentTemperature = (HEATING_WOHNBEREICH_TEMPERATURE.state as QuantityType<Number>).toBigDecimal
val Number maxTempInTimeFrame = (HEATING_WOHNBEREICH_TEMPERATURE.maximumSince(now.minusMinutes(historicValuesTimespan)).state as QuantityType<Number>).toBigDecimal
val Number minTempInTimeFrame = (HEATING_WOHNBEREICH_TEMPERATURE.minimumSince(now.minusMinutes(historicValuesTimespan)).state as QuantityType<Number>).toBigDecimal
logInfo(LOGGER, "current:" + currentTemperature + ", max:" + maxTempInTimeFrame + ", min:" + minTempInTimeFrame)
This just gathers the current Temperature and max/min within the last 120 minutes.
So when I set historicValuesTimespan to 1 (1 minute), everything works fine. Log outputs this:
2022-02-26 13:36:47.128 [INFO ] [ore.model.script.heating.wohnbereich] - current:23.27, max:23.27, min:23.27
However 1 minute is not helpful in this case, just shows that in this case, everything seems to work fine, as all variables have assigned a correct value.
Now changing historicValuesTimespan to 120 minutes, I receive an error message:
2022-02-26 13:38:28.923 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'heating_wohnbereich-1' failed: Could not cast 21.72 to org.openhab.core.library.types.QuantityType; line 61, column 38, length 116 in heating_wohnbereich
Line 61 is actually the 3rd line (“minimumSince”).
Anyone an idea what might be causing this error?