Error comparing DecimalType values


I’m needing a little help. I’m trying to write a rule to compair my current household power usage with the value last week and OpenHAB 1.8.3 is giving me a strange error.

Here is my rule so far:

rule "Announce Power Usage"
Item EnergyUseCurrent changed

var DecimalType EnergyUseCurrentDecimalType = EnergyUseCurrent.state as DecimalType;
var DecimalType compareWith = EnergyUseLastWk.state as DecimalType;

logInfo("EnergyUseCurrent", ".. Line 229, compare " + EnergyUseCurrentDecimalType + " with " + compareWith)
if ( EnergyUseCurrentDecimalType >= compareWith ) {
	logInfo("EnergyUseCurrent", ".. Line 231")
	logInfo("EnergyUseCurrent", "Current consumption " + EnergyUseCurrent.state + " Kwh is now higher than this time last week " + EnergyUseLastWk.state + " Kwh" )
	sendCommand(vrPowerHigh, ON)
} else {
	logInfo("EnergyUseCurrent", ".. Line 235")


my logs prints out “[.script.EnergyUseCurrent] - … Line 229, compare 1.05750 with 0.731” but then it stops and I get this error

[ERROR] [.s.ScriptExecutionThread] - Error during the execution of rule ‘Announce Power Usage’: Could not invoke method: org.openhab.model.script.lib.NumberExtensions.operator_greaterEqualsThan(org.openhab.core.types.Type,java.lang.Number) on instance: null

I cant understand it since I know from “Line 229” that nether value is null. Can anyone offer any suggestion on what I’m missing?


Instead of using DecimalType for EnergyUseCurrentDecimalType and comapreWith, try using Number.

It should work as written but since it doesn’t that is the first thing I would try.

You also might try loading the rule in Designer to see if there is a syntax error we are not noticing.