Hi All,
I’m trying to set a rule for calculating the average of a set of temperature sensors, but I’m struggling in making the math, Here is the rule
rule “Rule_AAA”
when
Item ThermoSoggiorno_T changed
or
Item ThermoBagnoPT_T changed
then
var t = (ThermoSoggiorno_T.state + ThermoBagnoPT_T.state)
TemperaturaPianoTerra.postUpdate(t)
end
I get this error
An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
I know the avg temperature may be calculated also defining a group, but I’d like to work as I would like to make more sofisticated maths in the rules.
Anyone can help?
Thank you Kim. But I would like, at a later stage, to build more sofisticated math like predictive indicators, and I really don’t understand why I’m not able to make a simple sum between a couple of “double” type numbers. I certainly miss some knowledge about the item state object structure.
Any help?
Thanks again
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
4
I’m far more comfortable with the wiring side of things, but as far as I understand it…
That error message is suggesting that one of your donor values hasn’t been updated with a value yet?
(I see it immediately after a start up, if sensors haven’t been polled.)
There are lots of comments on here about building in resilient against null values (or at least factoring them into rules).
rule “Rule_AAA”
when
Item ThermoSoggiorno_T changed
or
Item ThermoBagnoPT_T changed
then
var t = (ThermoSoggiorno_T.state as Number + ThermoBagnoPT_T.state as Number)
TemperaturaPianoTerra.postUpdate(t)
end
rule "Rule_AAA"
when
Item ThermoSoggiorno_T changed
or
Item ThermoBagnoPT_T changed
then
if(!(ThermoSoggiorno_T.state instanceof Number )) return; // check if ThermoSoggiorno_T.state is of type number
if(!(ThermoBagnoPT_T.state instanceof Number )) return; // check if ThermoBagnoPT_T.state is of type number
// both items have a number value, so calculate...
var t = (ThermoSoggiorno_T.state as Number) + (ThermoBagnoPT_T.state as Number) // beware the brackets!
TemperaturaPianoTerra.postUpdate(t)
end
Maybe you want to see if the rule was cancelled early…
rule "Rule_AAA"
when
Item ThermoSoggiorno_T changed
or
Item ThermoBagnoPT_T changed
then
if(!(ThermoSoggiorno_T.state instanceof Number )) { // check if ThermoSoggiorno_T.state is of type number
logWarn("aaa","ThermoSoggiorno_T has no valid value!")
return;
}
if(!(ThermoBagnoPT_T.state instanceof Number )) { // check if ThermoBagnoPT_T.state is of type number
logWarn("aaa","ThermoBagnoPT_T has no valid value!")
return;
}
// both items have a number value, so calculate...
var t = (ThermoSoggiorno_T.state as Number) + (ThermoBagnoPT_T.state as Number) // beware the brackets!
TemperaturaPianoTerra.postUpdate(t)
end
Does your temp item have units defined like [%.1f *C] the * should be the deg symbol.
Or as Vincent suggest, use the calculation in the rule before .postUpdate
rule “Rule_AAA”
when
Item ThermoSoggiorno_T changed
or
Item ThermoBagnoPT_T changed
then
var k = (ThermoSoggiorno_T.state as Number + ThermoBagnoPT_T.state as Number)
var t = k - 273.15
TemperaturaPianoTerra.postUpdate(t)
end