📌 30 de Novembro, 2024
ESPHome: BME680 with BSEC 2
ESP32 / AVR / MCUs · Informática · Programação
ESPHome provides built-in support for the BME680 sensor with a fully open-source implementation; however, it is not compatible with all the sensor’s features. The project also includes Bosch’s proprietary BSEC v1 and v2 software libraries that support different ESP boards. Learn how to set up and configure your sensors in this post with examples for the ESP32 S2 and C3 boards.
The BSEC is a proprietary library by Bosch that offers Index for Air Quality (IAQ) measurement derived from the gas resistance sensor’s response to specific Volatile Organic Compounds (VOC). It also estimates values for CO₂ and Breath Volatile Organic Compounds (b-VOC) using the correlation between VOC and CO₂ in human exhaled breath.
While both BSEC versions deliver the same functionality, only v2 includes binaries for the ESP32-S2 and ESP32-C3. Based on the information provided here and here I managed to compile list of CPU support for each version of the library:
Platform | Compiler | Library | CPU / TYPE |
ESP8266 | xtensa-lx106-elf-gcc | v1 | v2 | ESP8266 |
ESP32 | xtensa-esp32-elf-gcc | v1 | v2 | ESP32 |
ESP32-S2 | xtensa-esp32s2-elf-gcc | v2 | ESP32-S2 |
ESP32-S3 | xtensa-esp32s3-elf-gcc | v2 | ESP32-S3 |
ESP32-C3 | riscv32-esp-elf-gcc | v2 | ESP32-C3 |
Cortex-ARM | ARMCC | v1 | Cortex-M0, M0+, M3, M4, M4_FPU, M7 |
Cortex-ARM | GCC | v1 | v2 | Cortex-M0, M0+, M3, M4, M4_FPU, M7, M33, M33_FPU |
Cortex-ARM | IAR | v1 | Cortex-M0, M0+, M3, M4, M4_FPU, M7 |
Cortex-A* | GCC | v1 | Cortex-A7 |
AVR_8bit | AVR-GCC | v1 | MegaAVR, XMEGA |
AVR_32bit | AVR-GCC | v1 | 32-bit AVR UC3 |
MSP430 | msp430-elf-gcc | v1 | MSP430 |
Android system-x86 | gcc | v1 | x86, x86_64 |
Android system-arm | gcc | v1 | arm, arm64 |
Raspberry PI 0 linux | arm-linux-gnueabihf-gcc | v1 | armv6-32bits |
Raspberry PI3 linux | arm-linux-gnueabihf-gcc | v1 | armv8-a-64bits |
BSEC Version: Which One to Pick?
- https://esphome.io/components/sensor/bme680_bsec.html
- https://esphome.io/components/sensor/bme68x_bsec2.html
The project recommends using the newer bme68x_bsec2
component whenever possible. In my experience BSEC v2 provides considerable more accurate readings, so if you board supports it just go for it.
Now I’ll share full configuration examples for the ESP32 S2 and ESP32 C3 boards, you should then be able to replicate this with all the other boards supported by the v2.
ESP32 S2 Mini Board
This board is also konw as lolin_s2_mini
.
Board documentation available at: https://www.wemos.cc/en/latest/s2/s2_mini.html
esphome:
name: "demo-esp32-s2"
friendly_name: demo-esp32-s2
external_components:
- source: github://TCB13/esphome@bsec2_bme68x
components:
- bme68x_bsec
refresh: 0s
esp32:
board: lolin_s2_mini
variant: ESP32S2
framework:
type: arduino
# Enable logging
logger:
level: ERROR
api:
encryption:
key: "YYYYYYYYYYYYYYYYY"
ota:
- platform: esphome
password: "XXXXXXXXXXXXXXX"
safe_mode:
disabled: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
#ap:
# ssid: "Esphome-Web-aaaaaaaaa"
# password: "xxxxxxxxxxxx"
#captive_portal:
#web_server:
# port: 80
# version: 2
# ota: false
# auth:
# username: !secret ws_username
# password: !secret ws_password
i2c:
sda: 11
scl: 12
bme68x_bsec2_i2c:
# Default: 0x76 or 0x77
address: 0x77
model: bme680
temperature_offset: 4.9 # 4.9
# operating_age: 4d or 28d depending on how long your sensor has been running
operating_age: 28d
# sample_rate: LP => every 3 seconds (default). ULP => every 5 minutes
sample_rate: LP
state_save_interval: 6h
sensor:
- platform: bme68x_bsec2
temperature:
name: "Temperature"
id: "temperature"
humidity:
name: "Humidity"
id: "humidity"
pressure:
name: "Pressure"
id: "pressure"
icon: "mdi:gauge"
co2_equivalent:
name: "CO2 Equivalent"
id: "co2_equivalent"
icon: "mdi:molecule-co2"
breath_voc_equivalent:
name: "VOC Equivalent"
icon: "mdi:molecule"
iaq:
name: "IAQ"
id: iaq
icon: "mdi:approximately-equal"
gas_resistance:
name: "Gas Resistance"
icon: "mdi:omega"
- platform: absolute_humidity
name: Absolute Humidity
icon: "mdi:water"
temperature: temperature
humidity: humidity
text_sensor:
- platform: bme68x_bsec2
iaq_accuracy:
name: "IAQ Accuracy"
- platform: template
name: "IAQ Classification"
icon: "mdi:checkbox-marked-circle-outline"
lambda: |-
if ( int(id(iaq).state) <= 50) {
return {"Excellent"};
}
else if (int(id(iaq).state) >= 51 && int(id(iaq).state) <= 100) {
return {"Good"};
}
else if (int(id(iaq).state) >= 101 && int(id(iaq).state) <= 150) {
return {"Lightly polluted"};
}
else if (int(id(iaq).state) >= 151 && int(id(iaq).state) <= 200) {
return {"Moderately polluted"};
}
else if (int(id(iaq).state) >= 201 && int(id(iaq).state) <= 250) {
return {"Heavily polluted"};
}
else if (int(id(iaq).state) >= 251 && int(id(iaq).state) <= 350) {
return {"Severely polluted"};
}
else if (int(id(iaq).state) >= 351) {
return {"Extremely polluted"};
}
else {
return {"error"};
}
- platform: template
name: "CO2 Classification"
icon: "mdi:checkbox-marked-circle-outline"
lambda: |-
if ( int(id(co2_equivalent).state) <= 400) {
return {"Excellent"};
}
else if (int(id(co2_equivalent).state) >= 401 && int(id(co2_equivalent).state) <= 1000) {
return {"Normal"};
}
else if (int(id(co2_equivalent).state) >= 1001 && int(id(co2_equivalent).state) <= 2000) {
return {"Unhealty"};
}
else if (int(id(co2_equivalent).state) >= 2001 && int(id(co2_equivalent).state) <= 5000) {
return {"Health Risk"};
}
else if (int(id(co2_equivalent).state) >= 5001) {
return {"DANGER!"};
}
else {
return {"error"};
}
ESP32 C3 Super Mini
This board is also know as esp32-c3-devkitm-1
.
Board documentation available at: https://wiki.icbbuy.com/doku.php?id=developmentboard:esp32-c3mini
(same as the S2 example)
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
(same as the S2 example)
i2c:
sda: 8
scl: 9
(same as the S2 example)
Enjoy!