Hello,
I want to compare a variable in a rule. I tried this:
var Number Delta = ((AZSollTemp.state as DecimalType) - (AZIstTemp.state as DecimalType)).floatValue
if (Delta > 2) {logInfo(“Heizung”, " > 2.0")}
if (Delta = 2) {logInfo(“Heizung”, " = 2.0")}
if (Delta < 2) {logInfo(“Heizung”, " < 2.0")}
None of these if’s is ever true. What I’m doing wrong here?
As Delta should be of type float, I would suggest to compare with 2.0
Another thing is, if comparing equality , you have to use == and not =.
I see the wrong quotes in your posting. While this can be originated by the forum software, because of not using code fences, please keep that in mind also. The complete rule should look like
rule "get delta"
when
Item AZSollTemp changed or
Item AZIstTemp changed
then
var Number Delta = ((AZSollTemp.state as DecimalType) - (AZIstTemp.state as DecimalType)).floatValue
if (Delta > 2.0)
logInfo("Heizung", " > 2.0")
if (Delta == 2.0)
logInfo("Heizung", " = 2.0")
if (Delta < 2.0)
logInfo("Heizung", " < 2.0")
end
There is no need for curly brackets if only one command is executed by the if clause.