Hi folks,
I’m sorry but I’m struggling with this. I found some great tutorials, e.g., Working with Number:Temperature Items in rules, and a number of related posts, but I’m still lost.
I am attempting to perform a mathematical operation on two time-averaged persisted quantities, Temperature and Relative Humidity (a dewpoint calculation, to be specific). I did happen to find an example of dealing with persisted temperatures, so my average temperature is working. However, dealing with the RH with the percent unit has me stumped. It’s probably something glaringly obvious.
My temperature is persisted as, e.g., 75.254 °F, and my RH is persisted as 71.0 %.
Here is my DSL code. I’m using Windows OH 3.1.0.M4. Any advice greatly appreciated.
var T = new QuantityType(SmartWeatherAir_Temperature.averageSince(now.minusMinutes(5), "rrd4j"), ImperialUnits.FAHRENHEIT).toBigDecimal
// var RH = new QuantityType(SmartWeatherAir_RelativeHumidity.averageSince(now.minusMinutes(5), "rrd4j") .... ????
T = (T - 32) / 1.8
val b = 18.68
val c = 257.14
val gamma = Math.log(RH / 100) + (b * T) / (c + T)
var DP = c * gamma / (b - gamma)
DP = DP * 1.8 + 32
OutsideDewpoint.postUpdate(DP)