Skip to content

Instantly share code, notes, and snippets.

@fatihboy
Created October 21, 2016 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatihboy/41d2fb93e5cbcc534a9d4307941f695a to your computer and use it in GitHub Desktop.
Save fatihboy/41d2fb93e5cbcc534a9d4307941f695a to your computer and use it in GitHub Desktop.
Openhab humidex calculation rule for Turkey
import org.eclipse.smarthome.core.library.types.DecimalType
rule "Hissedilen sicakligi hesapla"
when
Item sensor_sicaklik changed or
Item sensor_nem changed
then
var double sonuc
var double sicaklik
var double sicaklikF
var double sicaklikF2
var double nem
var double nem2
sicaklik = 0
nem = 0
if (sensor_sicaklik.state instanceof DecimalType) {
sicaklik = (sensor_sicaklik.state as DecimalType).doubleValue
}
if (sensor_nem.state instanceof DecimalType) {
nem = (sensor_nem.state as DecimalType).doubleValue
}
sicaklikF = (sicaklik * 1.8) + 32
sicaklikF2 = Math::pow(sicaklikF,2)
nem2 = Math::pow(nem,2)
sonuc = ((0 - 42.379 + 2.04901523 * sicaklikF + 10.1433127 * nem - 0.22475541 * sicaklikF * nem - 0.00683783 * sicaklikF2 - 0.05481717 * nem2 + 0.00122874 * sicaklikF2 * nem + 0.00085282 * sicaklikF * nem2 - 0.00000199 * sicaklikF2 * nem2) - 32.0) / 1.8
sicaklik_hissedilen.postUpdate(sonuc)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment