In a rule I want to set the temperature of a radiator control with the help of a variable. The variable is a Number:Temperature item, which is defined like:
Number:Temperature wantedTemperature "Wanted Temperature" (EqpVar_Radiator) ["Point"]
I can set this variable in the UI , print it and compare it with the value of a bounded item (named
setPointTemperature
to control the radiator) like in the following example action part of a rule:
val mailActions = getActions("mail", "mail:smtp:openhab")
if (setPointTemperature.state < wantedTemperature.state)
{
mailActions.sendMail("mail@example.com",
"Temperature setting lower than wanted",
"setPointTemperature = " + setPointTemperature.state + "\n" +
"wantedTemperature = " + wantedTemperature.state + "\n")
}
But what I can’t do is to set the bounded item to the value of the variable item. If I try this by putting the following line in the rule:
setPointTemperature.sendCommand(wantedTemperature.state)
I’ll get an error message like the following in the log file:
2021-01-23 13:01:41.013 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'radiator-control-1' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null in radiator-control
The following command without using a variable works as aspected:
setPointTemperature.sendCommand(20)
Based on the error message, I assume there is a casting problem here. I have already tried in vain to cast the variable with one of the following commands:
val settingValue = wantedTemperature.state as Number
val settingValue = wantedTemperature.state as DecimalType
val settingValue = wantedTemperature.state as String
Therefore my questions:
- How can I use the variable item here?
- Does the class Number have a property of type DecimalType or how else can I cast it to a plain number?
Thanks for your help.