Execute Rule only if Rollershutter value Increased

Im executing this piece of code on every of my rollershutters

  1. If value changed
  2. Check if Temperature is above threshhold and Value is higher than threshhold
  3. Check if Rollershutter was closing (*.state is higher than *.previousState)
val dSomRoll_OgBuero_NW_MAX = 86

rule "dSomRoll_OgBuero_NW_MAX"
    Item dSomRoll_OgBuero_NW changed
    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) {

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

This is a persistence function, retrieves data from your default persistence service, and returns an historicItem type object.

You can’t compare a xxx.state to a historicItem, different objects.

This would return the previous state of the Item that changed to trigger the rule.
I think that’s what you wanted?

1 Like

Im not sure if i get you 100%

Frontail gives me exactly this message right before the rule triggers:

[openhab.event.ItemStateChangedEvent ] - Item 'dSomRoll_OgBueroSeb_NW' changed from 66 to 100

I just want to achieve, that this line


Only triggers, if my blind

  • dSomRoll_OgBuero_NW

exceeded the Threshhold

  • dSomRoll_OgBuero_NW_MAX

but only if the value is higher than its previous value
So only if my blind is closing and not opening

So i need something like the history of the value


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.

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.

Itemzzz.state > previousState
is good syntax.

Now i got you …

This should do the trick!

Thank you very much!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.