I must be doing something wrong? Calculate Dewpoint from BME280 sensor

I am trying ESP fo the first time and want to calculate Dewpoint from the RH and Temperature sensor of a BME280 sensor.

I get readings for the RH and T from the sensor fine, but can’t get the calulation to work.

Say the RH is 57.4 and the T is 23.4, I should get about 14.5C for the Dewpoint

All the methods I try result in about 67C - any ideas what I am doing wrong?

  - platform: bme280
    temperature:
      name: "Conservatory BME280 Temperature (ESP)"
      id: bme280_temperature
      oversampling: 16x
    pressure:
      name: "Conservatory BME280 Pressure (ESP)"
      id: bme280_humidity
    humidity:
      name: "Conservatory BME280 Humidity (ESP)"
      id: bme280_pressure
      
    address: 0x76
    update_interval: 60s  

  - platform: template
    name: "1 Conservatory BME280 Dew Point (ESP)"
    #//https://community.home-assistant.io/t/how-to-do-maths-in-sensor-template-with-esphome-on-hassio/193994/4
    lambda: |-
      const float a = 17.27;   //const from https://planetcalc.com/248/
      const float b = 237.7;   //const from https://planetcalc.com/248/
      return ( (b * ( (id(bme280_temperature).state * a) / ( b + id(bme280_temperature).state) + 
      logf (id(bme280_humidity).state/100) ) )/( a - ( (id(bme280_temperature).state * a) / 
      ( b + id(bme280_temperature).state) + logf (id(bme280_humidity).state/100) ) ) ); 
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'
    update_interval: 15s

  - platform: template
    name: "2 Conservatory BME280 Dew Point (ESP)"
    lambda: |-
      return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
      (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
      ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'
    update_interval: 15s

  - platform: template
    name: "3 Conservatory BME280 Dew Point (ESP)"
    lambda: |-
      return (
      (pow(id(bme280_humidity).state/100.0,1.0/8.0))
      *
      (((0.9*id(bme280_temperature).state)+112.0))
      +
      (((0.1*id(bme280_temperature).state)-112.0))
      );
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'
    update_interval: 15s

  - platform: template
    name: "4 Conservatory BME280 Dew Point (ESP)"
    lambda: !lambda |-
        return 243.04*(log(id(bme280_humidity).state/100.) + ((17.625*id(bme280_temperature).state)/(243.04+id(bme280_temperature).state)))/(17.625-log(id(bme280_humidity).state/100.)-((17.625*id(bme280_temperature).state)/(243.04+id(bme280_temperature).state)));
# Dewpoint calculated using equation (21) of this paper: Alduchov, O. A., and R. E. Eskridge, 1996: Improved Magnus' form approximation of saturation vapor pressure. J. Appl. Meteor., 35, 601–609
#[https://doi.org/10.1175/1520-0450(1996)035%3C0601:IMFAOS%3E2.0.CO;2]
    unit_of_measurement: "°C"
    icon: 'mdi:thermometer-alert'
    update_interval: 15s

What about using a simpler calculation like
Td = T - ((100 - RH)/5.)
I see people complaining the relative humidity on BME280 isn’t that accurate to start with. See if it suits your use.

Do you already have a working ESP module that is reporting values?

The BME280 is imo a good sensor. Also see: https://scienceinhydroponics.com/2020/04/the-best-cheap-sensor-setup-for-relative-humidity-in-hydroponic-automation-projects.html

What formula do you use to calculate the 14,5 degrees Celsius? Is it similar to that used in the lambda part of the .yaml for you device? Could be that the formula in the yaml isn’t good.

If you are using the ESP together with Home Assistant, you can also use the Thermal Comfort addon.

Also after some searching found this alternative code for calculating dewpoint: https://github.com/rikdc/esphome-config/blob/e466667d4d00c3515bc0ccba1fcc7f22a7ee1ab0/config/common/sensor/dewpoint.yaml

Try this:

  - platform: template
    name: "Dew Point"
    lambda: |-
      return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
      (243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
      ((17.67*id(bme280_temperature).state)/(243.5+id(bme280_temperature).state))));
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'

Embarrassingly I have discovered the problem. If I had posted ALL the code I am sure someone would have spotted it. I went to work and came back to it about 16 hours later and spotted it straight away.

I had given the id of bme280_temperature to the temperature value and the id of bme280_humidity to the pressure value. Total idiot.

As it turns out all the methods I tried do actually work and give answers within 0.1C of each other…

1 Like

This is very common. People want help but only post the portion of code they think is the problem. It’s like they unwittingly just want confirmation bias I guess. You don’t have to share all your networking details or sensitive information but it’s best to post all the code because it is often something simple or some small detail that was overlooked and it’s the one thing you think couldn’t or wouldn’t be the problem. Good for you for being humble enough to see the mistake and acknowledge it. Most people will just argue and insist the problem is in the block of code they think its in.

1 Like

Yes, indeed. It is a lesson learned (I hope) :slight_smile:

If ever you are interested, you could plug the values into this HACS integration : GitHub - dolezsa/thermal_comfort: Thermal Comfort sensor for HA (absolute humidity, heat index, dew point, thermal perception). Get some saucy stuff and it’s pretty easy to set up.