Help needed: Comparing Numbers (.previousState vs. .state)


I would like to compare two numbers in a rule when the according item changes:

rule "Heat_HzSoll check"
	Item Heat_HzSoll changed
	if(Heat_HzSoll.state >= Heat_HzSoll.previousState(true,"jdbc") as Number) {
		if(Heat_HzMode.state == "night" && G_Melder.state == ON) {
			if(Z_Alexa.state == ON && AmazonThing.state == ON) Alexa_Text.sendCommand("Die Heizung soll hochgestellt werden aber die Fenster sind offen. Bitte prüfen.")
			logInfo("heating.rules: ", "Heating Temp increased, but windows open (Night Mode)!")

but I get

Rule 'Heat_HzSoll check': Could not cast org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@13fed0c to java.lang.Number; line 490, column 36, length 48

als this does not work:

if(Heat_HzSoll.state as Number >= Heat_HzSoll.previousState(true,"jdbc") as Number) {

nor this:

if(Heat_HzSoll.state >= Heat_HzSoll.previousState(true,"jdbc")) {

I may be wrong, but wouldn’t you need to store the state first?

Edit: Have you checked the persistence service is storing the info.

Thanks for your response.
Yes, the historic data is there (visible in habpanel chart).

You could use just:

if(Heat_HzSoll.state >= Heat_HzSoll.previousState.state) {
1 Like