ESPHome project for bme680 on a Raspberry Pi Pico W

I had a lot of problems configuring the yaml file for my ESPHome project (bme680 wired to a RP Pico W pins 2 and 3). The example yaml file for the bme680 on the ESPHome website does not compile because the Bosch library is not supported for the RP Pico. After some changes, the project compiled but the Pico would not come online. I now have it working. Include the following in the yaml file after the “fallback hotspot” section. Make sure you use pins 20 and 21 to connect to the bme680.

i2c:
sda: GPIO20
scl: GPIO21
scan: true
id: bus_a

sensor:

  • platform: bme680
    temperature:
    name: “BME680 Temperature”
    oversampling: 16x
    pressure:
    name: “BME680 Pressure”
    humidity:
    id: “humidity”
    name: “BME680 Humidity”
    gas_resistance:
    id: “gas_resistance”
    name: “BME680 Gas Resistance”
    address: 0x77
    update_interval: 60s
  • platform: template
    name: “BME680 Indoor Air Quality”
    id: iaq
    icon: “mdi:gauge”

    caulculation: comp_gas = log(R_gas[ohm]) + 0.04 log(Ohm)/%rh * hum[%rh]

    lambda: |-
    return log(id(gas_resistance).state) + 0.04 * id(humidity).state;

text_sensor:

  • platform: template
    name: “BME680 IAQ Classification”
    icon: “mdi:checkbox-marked-circle-outline”
    lambda: |-
    if (int(id(iaq).state) <= 50) {
    return {“Excellent”};
    }
    else if (int(id(iaq).state) <= 100) {
    return {“Good”};
    }
    else if (int(id(iaq).state) <= 150) {
    return {“Lightly polluted”};
    }
    else if (int(id(iaq).state) <= 200) {
    return {“Moderately polluted”};
    }
    else if (int(id(iaq).state) <= 250) {
    return {“Heavily polluted”};
    }
    else if (int(id(iaq).state) <= 350) {
    return {“Severely polluted”};
    }
    else if (int(id(iaq).state) <= 500) {
    return {“Extremely polluted”};
    }
    else {
    return {“unknown”};
    }

Sorry for the formatting: the bullet points are of course hyphens. I guess there is a better way to include code. I must find out.