Im executing this piece of code on every of my rollershutters
If value changed
Check if Temperature is above threshhold and Value is higher than threshhold
Check if Rollershutter was closing (*.state is higher than *.previousState)
val dSomRoll_OgBuero_NW_MAX = 86
rule "dSomRoll_OgBuero_NW_MAX"
when
Item dSomRoll_OgBuero_NW changed
then
if ((wTodayMaxTemperature.state as QuantityType<Number>).doubleValue > dSomRoll_ActvTemp_MAX && dSomRoll_OgBuero_NW.state > dSomRoll_OgBuero_NW_MAX){
// Check if blinds went DOWN
if (dSomRoll_OgBuero_NW.state > dSomRoll_OgBuero_NW.previousState) {
dSomRoll_OgBuero_NW.sendCommand(dSomRoll_OgBuero_NW_MAX)
}
}
end
It seems that the .previousState does not work on this?
All of the code worked before, i just added the ".state > *.previousState" condition, giving me this error:
Script execution of rule with UID 'blinds-3' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.lib.NumberExtensions.operator_greaterThan(org.openhab.core.types.Type,java.lang.Number) on instance: null in blinds
There’s two different things with the same name here.
In every rule triggered by change of Itemxxx, previousState is an automatically created variable containing, well, the previous state of Itemxxx.
Itemxxx.previousState is a method of the Item, that fetches data from persistence service related to that Item. It does not return a state, it returns an historicItem - from which you can get state and timestamp etc.
So Itemzzz.state > Itemxxx.previousState
is an error Itemzzz.state > Itemxxx.previousState.state
would be sensible, but you don’t need to do that at all.