Null error when rule tries to use item's value

Tags: #<Tag:0x00007f6171bacd20> #<Tag:0x00007f6171bacc58>

The weather where I live has been flaky lately - it was in the 80s on Saturday and today the high is 66. So I’m trying to set up a basic set of rules for the thermostat that I can tweak by adjusting a selector in my openHAB app. Here is the error I get:

2020-05-18 17:00:00.094 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘daytime test’: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_minus(int,byte) on instance: null

And here is my selector item:

Number thermostat_adjustment

And the sitemap:

Frame label=“Climate” icon=“temperature” {
Selection item=thermostat_adjustment label=“Adjust Thermostat” mappings=[-3=“Very Cold”, 2=“Cold”, -1=“Cool”, 0=“Normal”, 1=“Warm”, 2=“Hot”, 3=“Very Hot”]}

And finally, a rule:

rule “wakeup temp”

when
Time cron “0 0 5 ? * * *”
then
var delta = thermostat_adjustment.state
thermostatCoolPoint.postUpdate(74 - delta)
thermostatHeatPoint.postUpdate(70 - delta)
end

If I set the variable delta to a fixed number, e.g. -1 the script runs fine. It just isn’t playing well with the item. Any idea what I need to do to get the item to interact properly?

Thanks.

Mike

I run into this kind of error all the time. An item’s type does not mean that [item].state returns a variable type that you can use directly depending on your intended purpose. You need to be more explicit about the type of your variable.

var delta = thermostat_adjustment.state as DecimalType

That’s a different rule to one shown so far.

That did it! Thanks!

All of my rules are identical. I just grabbed a different one.