Controlling power to BME280 sensor with ESPhome

Not sure if I’m close to a solution or a million miles away, but in short BME sensors generate a little bit of heat when they’re powered. I’ve found the most reliable way to get a good measurement from them is to power them up briefly, take a measurement, then disconnect to let them reach ambient again before the next attempt.

Here’s what I have so far:

sensor:
  - platform: bme280
    id: bme_sensor
    temperature:
      name: "BME280-garage Temperature"
      oversampling: 1x
    pressure:
      name: "BME280-garage Pressure"
      oversampling: 1x
    humidity:
      name: "BME280-garage Humidity"
      oversampling: 1x
    address: 0x76
    update_interval: never
    
  - platform: template
    id: dummy_sensor
    lambda: |-
      digitalWrite(5, HIGH);
      delay(3000);
      id(bme_sensor).update();
      digitalWrite(5, LOW);
      return NAN;
    update_interval: 10s

I can confirm this sends power to the sensor for the 3 seconds, but no data is being returned to home assistant (I’m using MQTT for reference). I’m pretty new to HA and ESPHome but not new to IoT/electronics/sensors. Hoping someone can spot some dumb newbie error I’m making or just knows a smarter way to do this…

Narrowed it down a little: the i2c bus loses the sensor when it turns off. Any way to restart or reinitialize it?

Some possible useful code for others:

esphome:
  name: garage
  platform: ESP8266
  board: d1_mini
  on_boot:
    - lambda: |-
        pinMode(5, OUTPUT);
        digitalWrite(5, HIGH);

(some other stuff)

sensor:
  - platform: bme280
    id: bme_sensor
    #operation_mode: 2
    temperature:
      name: "BME280-garage Temperature"
      oversampling: 1x
    pressure:
      name: "BME280-garage Pressure"
      oversampling: 1x
    humidity:
      name: "BME280-garage Humidity"
      oversampling: 1x
    address: 0x76
    update_interval: never
    
  - platform: template
    id: dummy_sensor
    lambda: |-
      digitalWrite(5, HIGH);
      delay(5000);
      id(bme_sensor).update();
      delay(1000);
      digitalWrite(5, LOW);
      return {};
    update_interval: 10s

a fun error message that I can get:

[18:15:38][C][mqtt.sensor:028]:   State Topic: 'garage/sensor/bme280-garage_humidity/state'
[18:15:48][W][i2c:070]: Received NACK on transmit of address 0x76
[18:15:48][W][bme280.sensor:190]: Invalid temperature, cannot read pressure & humidity values

Are you using a BME sensor breakout board powered by 5V? If so, the heat is the regulator. Use a board without the regulator or bypass the regulator with a blob of solder and power from 3.3V. I ran into the same issue.

That would assume that the LDO is the source of the heat, which it does contribute to but is not the real problem. Example:

FLIR0038

This is a breakout board with the LDO removed, 3.3v being fed from a very low noise lab supply. The heat is exactly where the BME sensor is. Here’s that same board before removing the regulator being fed 5v, for reference:

FLIR0036

And showing the board with the modification to test:

The reality is these are active components, not like an NTC or something, and that means they generate heat when powered. There needs to be a way to remove that power for the time that the unit is not being measured to minimize the thermal buildup.

Interesting. My issue was solved via bypassing the regulator. Had maybe a 1 degree rise, which I consider acceptable.

Unfortunately I can’t help you with the ESPHome aspect as I don’t use it.