Curious. I have a long winded dewpoint calc rule, cribbed from somewhere - wiil not vouch for accuracy (and welcome impovement)
Ignore the fetch-Item-from-group stuff, I just pasted as-is and added a timer
Note - that I do not have Math imports in this file. Is that contributing??
val Number DewMargin = 1.0 // temp margin for condensation alert
// Dew check
rule "dew check"
when
Member of gIntHumids changed
then
val long start = now.millis
val rootname = triggeringItem.name.split("_").get(1) // derive partners name
val tempname = "nm_" + rootname + "_temp" // derive temp name
val dewname = "vsw_" + rootname + "_dew" // derive dew alert
logInfo("dewcalc", "Seeking " + tempname + " " + dewname)
val myTemp = gIntTemps.members.findFirst[ i | i.name == tempname ] // get temp item
val myDew = gDewAlerts.members.findFirst[ j | j.name == dewname ] // get dew item
// THE DEWPOINT CALC
if (myTemp !== null && myDew !== null) {
val humidRH = triggeringItem.state as Number
val tempC = myTemp.state as Number
val e = 2.71828 // for nat log
logInfo("dewcalc", "Temp " + tempC.toString + " Humid " + humidRH.toString)
// Magnus formula
val Number satvap = 6.112 * Math.pow(e, (17.62 * tempC)/(243.12 + tempC))
val absvap = (satvap / 100 * humidRH).floatValue // need for the log
val Number inter = Math.log(absvap/6.112)
val Number dewpoint = (235 * inter) / (17.1 - inter)
logInfo("dewcalc", "Dewpoint " + dewpoint.toString +" OutC " + nm_Out_temp.state.toString)
if (nm_Out_temp.state != NULL) { // compare to wall temp
val worrypoint = (nm_Out_temp.state as Number) + DewMargin
if (dewpoint > worrypoint && myDew.state != ON) {
logInfo("dewcalc", "Dew alarm " + myDew.name)
myDew.postUpdate(ON) // set alarm
} else if ((dewpoint + DewMargin) < worrypoint && myDew.state != OFF) { // with hysteresis
logInfo("dewcalc", "Dew Okay " + myDew.name)
myDew.postUpdate(OFF) // clear alarm
}
}
} else {
logInfo("dewcalc", "CONFIG ERROR matching humid sensor name")
}
val long stop = now.millis
logInfo("Test", "The Rule took " + (stop - start) + " ms to run")
end
Running OH2.4 on Win7 centrino laptop.
No particular issue noted with loading rules file.
Execution times, first and second, 24 and 17mS
2019-10-23 01:32:53.633 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'enviro.rules'
2019-10-23 01:33:00.855 [INFO ] [lipse.smarthome.model.script.dewcalc] - Temp 15.5 Humid 30.0
2019-10-23 01:33:00.864 [INFO ] [lipse.smarthome.model.script.dewcalc] - Dewpoint -2.01572707 OutC 6.01
2019-10-23 01:33:00.870 [INFO ] [.eclipse.smarthome.model.script.Test] - The Rule took 24 ms to run
2019-10-23 01:33:35.795 [INFO ] [lipse.smarthome.model.script.dewcalc] - Temp 15.5 Humid 40.0
2019-10-23 01:33:35.801 [INFO ] [lipse.smarthome.model.script.dewcalc] - Dewpoint 1.93618021 OutC 6.01
2019-10-23 01:33:35.805 [INFO ] [.eclipse.smarthome.model.script.Test] - The Rule took 17 ms to run
Edit - out of curiosity, I moved the timer-begin to after the Item fetching clutter and got 20mS/11mS
Obviously it would be more sluggish on a Pi.