I want to calculate the absolute humidity in a room to decide about ventilation. Therefore I use calculations that require exponents for formulas as described here: https://www.wetterochs.de/wetter/feuchte.html
Unfortunately when I have a line like
val sdd = 6.1078 * 10^((7.5*temp)/(237.3+temp))
I get the error
Configuration model 'air_climate.rules' has errors, therefore ignoring it: [33,24]: no viable alternative at input '^'
[35,14]: no viable alternative at input '^'
I didn’t find a description or guide about mathematics in rules, so I would be glad if somebody could give me a hint whether this is possible at all.
Okay - figured it out myself: good old Java does it with Math.pow(x,y) for x^y.
But now I get an error that says
[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule tb: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_multiply(double,byte) on instance: null
rule "tb"
when
Item HUM_AUS_Garage received update or
Item TEMP_AUS_Garage received update
then
val temp = TEMP_AUS_Garage.state
val hum = HUM_AUS_Garage.state
logInfo("AUTOMATION", "TEMP: " + temp + " / HUM: " + hum)
val sdd = 6.1078 * Math.pow(10,((7.5*temp)/(237.3+temp)))
logInfo("AUTOMATION", "SDD = " + sdd)
val dd = hum/100 * sdd
logInfo("AUTOMATION", "DD = " + dd)
val af = Math.pow(10,5) * (8314.3/18.016) * dd/(temp+273.15)
logInfo("AUTOMATION", "AF = " + af)
end
It must happen already in the line that defines sdd, as the log doesn’t show the subsequent output. Yet, the log shows the preceding output for temp and hum:
I’ve declared them now as doubles which leads to a slightly different error:
[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule tb: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_multiply(double,double) on instance: null
The parameters are now double, double but still I don’t get where the “null” comes from as the variables have values which are shown in the preceding log output.