I was having a very difficult time using temperature values in my calculations until I stumbled across a lambda function that provided the hints for conversions. If you are working with scalars such as percent, you can work with it like so:
var myPcntType = 10|%
if (myPcntType < 11|%) {
// do something
}
Or, convert them from an item to some Number:
val org.eclipse.xtext.xbase.lib.Functions$Function2<Double, Double, Double> calculateDewPoint = [
double temperature, double humidity
|
var double a
var double b
var double SDD
var double DD
var double v
var double TD
a = 7.5
b = 237.3
SDD=(6.1078 * Math::pow(10.0, ((a*temperature)/(b+temperature)).doubleValue)).doubleValue
DD = (humidity/100*SDD).doubleValue
v = Math::log10((DD/6.107).doubleValue)
TD = ((b*v)/(a-v)).doubleValue
TD
]
rule "lampsCtrl"
when
// Time cron "0 * * * * ?"
Item weatherunderground_weather_local_current_relativeHumidity received update
then
var ts = 40 // temperature setpoint
var dpd = 5 // delta degrees for dew point turn on
var h = (weatherunderground_weather_local_current_relativeHumidity.state as Number).doubleValue
var t = (weatherunderground_weather_local_current_temperature.state as Number).doubleValue
var dp = calculateDewPoint.apply(t, h)
// logInfo("Logger","lampsCtrl humidity is " + h)
// logInfo("Logger","lampsCtrl temperature is " + t)
logInfo("Logger","lampsCtrl dew point is " + dp)
if (dp > (t - dpd) ) {
if (laserLamp.state == OFF){laserLamp.sendCommand(ON);}
if (gooseLampEngine.state == OFF){gooseLampEngine.sendCommand(ON);}
if (gooseLampInterior.state == OFF){gooseLampInterior.sendCommand(ON);}
}
if (t < ts) {
if (laserLamp.state == OFF){laserLamp.sendCommand(ON);}
}
if (dp < (t-dpd) &&
t > ts) {
if (laserLamp.state == ON){laserLamp.sendCommand(OFF);}
if (gooseLampEngine.state == ON){gooseLampEngine.sendCommand(OFF)};
if (gooseLampInterior.state == ON){gooseLampInterior.sendCommand(OFF)};
}
end