hass-weatherflow2mqtt icon indicating copy to clipboard operation
hass-weatherflow2mqtt copied to clipboard

Add Apparent Temperature

Open GlennGoddard opened this issue 2 years ago • 2 comments

New Feature

I always wanted a better 'feels like temperature' that incorporates sun light, I finally found it. I just didn't know it was call apparent temperature.

def calculate_apparent_temperature(temperature, relative_humidity, wind_speed, solar_radiation):
    # Constants
    T = temperature  # Air Temperature
    rh = relative_humidity  # relative humidity
    v = wind_speed  # Wind speed
    Sr = solar_radiation  # Solar Radiation
    
    # Apparent temperature calculation
    e = 6.11 * math.pow(10, (7.5 * T) / (237.3 + T)) * rh # Vapor pressure 
    w = 0.62198 * e / (273.16 + T) #Humidity index
    AT = T + 0.348 * e - 0.7 * v + 0.7 * Sr # Apparent temperature formula
    return AT

Additional context

I won't overload you with PRs at this time. I will wait until 'Current Conditions' is done. This is just the bulk of the calculation, making it pretty comes later.

GlennGoddard avatar Jan 11 '23 04:01 GlennGoddard

oh, we could do vapor pressure and humidity index as their own sensors also. I did see that you had vapor pressure in your original UDP repository but I don't see it here, is there a reason or just forgot?

GlennGoddard avatar Jan 11 '23 04:01 GlennGoddard

Updated, still testing. Waiting for an 80F day.

// Apparent Temperature: The perceived temperature in degrees Fahrenheit derived from either a combination of temperature and wind (Wind Chill) or temperature and humidity (Heat Index) for the indicated hour. When the temperature at a particular grid point falls to 50 F or less, wind chill will be used for that point for the Apparent Temperature. When the temperature at a grid point rises above 80 F, the heat index will be used for Apparent Temperature. Between 51 and 80 F, the Apparent Temperature will be the ambient air temperature
// https://meteor.geol.iastate.edu/~ckarsten/bufkit/apparent_temperature.html

T = msg.temperature
rh = msg.humidity
v = msg.wind_speed
sr = msg.sr  // Solar Radiation
wind_chill = msg.wind_chill
c1 = -42.38
c2 = 2.049
c3 = 10.14
c4 = -0.2248
c5 = -0.006838
c6 = -0.05482
c7 = 0.001228
c8 = 0.0008528
c9 = -0.00000199

HI = c1 + c2*T + c3*rh + c4*T*rh + c5*T*T + c6*rh*rh + c7*T*T*rh + c8*T*rh*rh + c9*T*T*rh*rh

if (T <= 50) {
    AT = wind_chill;
} else if (T <= 80){
    AT = T;
} else{
    AT = HI;
}

AT = Math.round(AT*100)/100
//AT = (Math.round(((AT * 1.8) + 32)*100))/100
msg.payload = AT
return msg;

GlennGoddard avatar Feb 05 '23 06:02 GlennGoddard