Issue with .previousState

I’m on OH2.2 and have the following error in my log:

2018-01-13 22:15:47.937 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Calculate Pool Temp Rate': Unknown variable or command '<'; line 120, column 52, length 48

The relevant line in the rule looks like this:

		if (Greenhouse_PoolTemperatureTop.state >= 36 && Greenhouse_PoolTemperatureTop.previousState < 36) {

I suspect that it is the way I use .previousState ? - I cannot find good references to how to use this in rules. Can someone help me on the right track ?

1 Like

be careful while RTFM! :wink:

<item>.previousState()

means:

		if (Greenhouse_PoolTemperatureTop.state >= 36 && Greenhouse_PoolTemperatureTop.previousState() < 36) {

this should work!

source:
https://docs.openhab.org/configuration/persistence.html

hint:
if you don’t want your Action to oszillate, you could use

<item>.averageSince(AbstractInstant)
=>
if (Greenhouse_PoolTemperatureTop.state >= 36 && Greenhouse_PoolTemperatureTop.averageSince(now.minusMinutes(15))< 36) {

OK - your first example gives

ule 'Calculate Pool Temp Rate': Unknown variable or command '<'; line 120, column 52, length 50

But the second one (with average) works !! Thanks !!

glad to hear, it works.
I don’t use .previousState, because all my persistence-related trigger are either temperatures or other means, which aren’t boolean. And I wanted to have some hysterese - and .averageSince does that sufficiently… :wink:

but still - <item>.previousState() … just out of curiosity:

if (Greenhouse_PoolTemperatureTop.state >= 36 && Greenhouse_PoolTemperatureTop.previousState().state < 36) {

another .state after that, should do finally.

Confirmed ! - thanks a million !

The right syntax is:

.previousState().state

Very happy to get this working - and getting rid of the last annoying error in my log…

1 Like