skylarstein / bme280-sensor

A Node.js I2C module for the Bosch BME280 Humidity, Barometric Pressure, and Temperature Sensor
MIT License
36 stars 22 forks source link

Heat Index Calculation is Incorrect #14

Open Whobeu opened 3 months ago

Whobeu commented 3 months ago

The Heat Index calculation function is not using the latest algorithm as documented at http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml. I use the following implementation to calculate the heat index. The formula is designed for Fahrenheit so in order to work with Celsius the temperature must be converted to Fahrenheit in the function before calculating the heat index and then converted back to Celsius.

function calculateHeatIndexCelsius(temperature_C, humidity) {
  const t = temperature_C * 1.8 + 32;
  let hi = -42.379 + 2.04901523 * t + 10.14333127 *
    humidity - 0.22475541 * t * humidity -
    0.00683783 * t * t - 0.05481717 *
    humidity * humidity + 0.00122874 *
    t * t * humidity + 0.00085282 *
    t * humidity * humidity - 0.00000199 *
    t * t * humidity * humidity;

  if (t < 80) {
    hi = 0.5 * (t + 61.0 + (t - 68.0) * 1.2 + humidity * 0.094);
  } else {
    if (humidity < 13 && (t >= 80 && t <= 112)) {
      hi -= (13 - humidity) / 4 * Math.sqrt((17 - Math.abs(t - 95.0)) / 17);
    }

    if (humidity > 85 && (t >= 80 && t <= 87)) {
      hi += (humidity - 85) / 10 * ((87 - t) / 5);
    }
  }

  return (hi - 32) / 1.8;
}