I´m trying to set up a simple rule when temperature is changing, but all I get is an error message in the logfile
“[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘SaunaTemp’: An error occurred during the script execution: index=1, size=1”
I already searched for this kind of error, but didn´t get it resolved.
Also checked all brackets with Notepad++ and realized that the bracket behind the number 70.0 stays black. (usually the corresponding bracket reverts red and is displayed in the editor). Could this be the reason?
What I´m doing wrong and how do I fix it?
rule "SaunaTemp"
when
Item SaunaTemp changed
then
if (Double::parseDouble(SaunaTemp.state.toString) > 70.0) {
logInfo("SaunaTemp above 70")
}
else if (Double::parseDouble(SaunaTemp.state.toString) < 70.0) {
logInfo("SaunaTemp under 70")
}
end
70.56|°C > 70|°C is true, so I’d expect nothing to happen in your rule. What happened to the the half ? Did you remove the other rule? If not, you would have two rules with the same name, which would make one not execute. When troubleshooting a rule, logging is one of the best tools. Try this…
rule "SaunaTemp test"
when
Item SaunaTemp changed
then
logWarn("Test", "SaunaTemp: {}, SaunaTemp.getStateAs(QuantityType) < 70|°C: {}", SaunaTemp.state, SaunaTemp.getStateAs(QuantityType) < 70|°C)
if (SaunaTemp.getStateAs(QuantityType) < 70|°C) {
logInfo("Sauna", "Sauna under 70")
} else {
logInfo("Sauna", "Sauna equal to or above 70")
}
end
You must compare QuantityType to QuantiityType. You can use a conversion, but there is no need to throw out data that might be useful. Comparisons between QuantityType and Number are always true, which should really be entered as a bug.
I´ve just tested your code and got following down below.
(I replaced 70 with 22 for testing current temp values )
so what I do not understand: It always says “…equal to or above 22”, but it definitely lower than 22.
and the other question: how to send the message just one time, e.g. when 22 is reached, and not at every update at values above of 22.
OK, so we got out into the weeds . The log shows that SaunaTemp is not using QuantityType (note the state of SaunaTemp is just a plain number without unit). Either change your Item definition to use Number:Temperature or just use…
rule "SaunaTemp test"
when
Item SaunaTemp changed
then
if (SaunaTemp.state < 22) {
logInfo("Sauna", "Sauna under 22")
} else {
logInfo("Sauna", "Sauna equal to or above 22")
}
end
You are very welcome! QuantityTypes are very useful when you need them. In your new rule, it looks like you have some extra left curly brackets, and you may need to use SaunaTemp.state.toString in a few places where you are concatenating strings.