esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Dew point, frost point calculations component #2770

Open mgrouch opened 2 months ago

mgrouch commented 2 months ago

Describe the problem you have/What new integration you would like

Dew point frost point calculations component needed (using pressure and relative humidity, or more accurate formulas see link)

https://en.wikipedia.org/wiki/Dew_point

Please describe your use case for this integration and alternatives you've tried:

Additional context

nagyrobi commented 2 months ago

Easy to be configured as template sensors: https://esphome.io/cookbook/bme280_environment.html

mgrouch commented 2 months ago

Yes. It’s possible doing manually but why everyone would implement it and possibly introduce errors.

nagyrobi commented 2 months ago

What errors? Just copy and paste carefully.

mgrouch commented 2 months ago

What errors? Just copy and paste carefully.

Errors in source formula too :) Look at Wikipedia article. There are better formulas with less errors. They are 2 different for different temperature ranges.

Also, in the Journal of Applied Meteorology and Climatology,[21] Arden Buck presents several different valuation sets, with different maximum errors for different temperature ranges. Two particular sets provide a range of −40 °C to +50 °C between the two, with even lower maximum error within the indicated range than all the sets above: a = 6.1121 mbar, b = 17.368, c = 238.88 °C; for 0 °C ≤ T ≤ 50 °C (error ≤ 0.05%). a = 6.1121 mbar, b = 17.966, c = 247.15 °C; for −40 °C ≤ T ≤ 0 °C (error ≤ 0.06%).

mgrouch commented 2 months ago

There is also no frost point currently

nagyrobi commented 2 months ago

Alright. Please quote here the correct formulas for the calculations you desire. I'll be happy to check / implement.

mgrouch commented 2 months ago

Alright. Please quote here the correct formulas for the calculations you desire. I'll be happy to check / implement.

I did. They are in the Wikipedia link I sent originally and I pasted them just above

ThomDietrich commented 2 months ago

I support this request. ESPHome does an excellent job providing just the right building blocks for comfortable use case driven configuration. Manually implementing an off-the-shelf formula like for the dew point feels like an odd exception.

Btw I took the formula from here: https://www.kevinahrendt.com/approximating-dew-points

nagyrobi commented 2 months ago

The problem is that there needs to be a consensus on which formulae to use. Various sites show various scientific approaches and not using the exact same formula. Seen from here, it's a subjective approach to say that one formula is better than the other, even saying that the one presented in the cookbook link above is wrong.

I start testing in parallel these: from the ESPHome cookbook:

  lambda: |-
      return (243.5*(log(id(lg_300_hum).state/100)+((17.67*id(lg_300_temp_t7).state)/
      (243.5+id(lg_300_temp_t7).state)))/(17.67-log(id(lg_300_hum).state/100)-
      ((17.67*id(lg_300_temp_t7).state)/(243.5+id(lg_300_temp_t7).state))));

from the above link:

  lambda: |- 
      const float alpha = 6.112;                      // (hPa)
      const float beta = 17.62;
      const float lambda = 243.12;                    // (degrees C)

      float RH = id(lg_300_hum).state;               // Relative Humidity
      float T = id(lg_300_temp_t7).state;            // Temperature in (degrees C)

      float H = log( RH/100 ) + beta*T/(lambda+T);
      return (lambda)*H/(beta - H);

above link corrected with constants suggested above:

  lambda: |- 
      const float alpha = 6.1121;                    // (mbar)
      float beta;
      float lambda;  
      if (id(lg_300_temp_t7).state < 0) {
        beta = 17.368;
        lambda = 238.88;                             // (degrees C)
      } else {
        beta = 17.966;
        lambda = 247.15;                             // (degrees C)
      }

      float RH = id(lg_300_hum).state;               // Relative Humidity
      float T = id(lg_300_temp_t7).state;            // Temperature in (degrees C)

      float H = log( RH/100 ) + beta*T/(lambda+T);
      return (lambda)*H/(beta - H);

using the same sensor sources and

  accuracy_decimals: 1
  update_interval: 120s

Let's see the difference.

It's kinda offtopic here to start debating on this, instead, to eliminate all the possible misunderstandings, if people are unhappy with the formulas used by the templates above, please take the effort and suggest another one here, let's see if other users have anything pro or contra and then, only after then, we'll implement it. Accepting formulas for other useful functions too.

nagyrobi commented 2 months ago

Some results. Pink line is first formula (ESPHome cookbook), light blue is the second, and dark blue is the third one. All 3: image

1-to-1: image image image

Difference is negligible (certainly smaller than the precision of the big majority of the sensors supported). First formula (ESPHome cookbook) and the second one correlate best, I think any one is very good for every day use.

There's no error in the formula presented in the ESPHome docs site.

ThomDietrich commented 2 months ago

@nagyrobi great show of initiative! 🏆 I did not spend the time to compare the different methods. However, I agree with your findings, all of these seem minor in difference. Thought on the third formula: The binary decision introduces an intermittent/discontinuous point at 0°C. Maybe that is acceptable, maybe its an unpleasant behavior.

I personally would go with the second formula and reference the link from above in documentation for interested folks.