Problem with persisted states in lambda function / cast error

Hi,

I am having problems with calling a lambda function with a persisted state.

Here the lambda function:

val satVapPressure = [ GenericItem argTemp |

var temp = (argTemp.state as QuantityType<Temperature>).toBigDecimal

0.6108*Math.exp(17.27*temp/(temp+237.3))

]

Calling the function with

logInfo("Button Test Button", "Result satVapPressure {}", satVapPressure.apply(Wetterinformationen_Aussentemperatur))

works fine, however, if I want to do the same with a persisted state

var meanSatVapPressure = satVapPressure.apply(Wetterinformationen_Aussentemperatur.averageSince(now.minusHours(24)) as GenericItem)

logInfo("Button Test Button", "mean Saturation Vapour Pressure {}", meanSatVapPressure)

doesn’t work and gives mit the following log

2025-05-02 00:00:43.784 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'irrigation-1' failed: Could not cast 16.69001355682870 °C to org.openhab.core.items.GenericItem; line 30, column 47, length 84 in irrigation

Using other casts like Number or NumberItem doesn’t work either.

If I log the persisted state without calling the lambda function there is no problem.

Would be great if anyone could point out what I am doing wrong here.

Many thanks

averageSince returns a Quantity type or a DecimalType if there are no units. You are trying to cast it to and test it as an Item.