Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for BSEC 2.0.6 and BSEC_OUTPUT_GAS_ESTIMATE_1/2/3/4 #1332

Open
mjdyson opened this issue Aug 1, 2021 · 8 comments · May be fixed by esphome/esphome#4585
Open

Support for BSEC 2.0.6 and BSEC_OUTPUT_GAS_ESTIMATE_1/2/3/4 #1332

mjdyson opened this issue Aug 1, 2021 · 8 comments · May be fixed by esphome/esphome#4585

Comments

@mjdyson
Copy link

mjdyson commented Aug 1, 2021

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

Support for the customised BME688 algorithm that is learned from the dev-board and then put through the Bosch ML software tool. For Arduino sketches, I believe additional config files need to be included in the main program, which allow a customised data model to be referenced. BSEC 2.0.6 is the latest version, which is only available from the BoschSensorTec website after signing a form. The BoschSensorTec github is not currently at this version.

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

By using the ML output from a sensor board, the BME688 claims to be able to distinguish between different types of gases. A trained model should be able to tell the difference between coffee and tea for example. The use case I am looking to achieve is to be able to detect 3d printer fumes from various filament types, including ABS and PLA.

Additional context

I dont believe the latest API is in the ESPHome code base.
Specifically there are outputs returned from the sensor called "BSEC_OUTPUT_GAS_ESTIMATE_1" (and 2/3/4), which show "Gas_Estimate [probability 0.00-1]. Outputs corresponding to different target groups(Classes) with the probability of occurrence".
These target groups (classes) are specified during the ML training and are for the different types of gas that you want to test for.

There is a lot of information in the zip file that is available from the Bosch website, after signing up for the download file, including test data.

@mjdyson
Copy link
Author

mjdyson commented Aug 1, 2021

@michaelm-github
Copy link

michaelm-github commented Jan 20, 2022

I am interested in BME688 support also. I found this Arduino library that does not include BSEC, but might at least allow readings from the BME688 VOC sensor.

https://github.com/BoschSensortec/BME68x-Sensor-API

@neffs
Copy link

neffs commented Feb 15, 2022

I just updated the existing component to the BSEC2 library: https://github.com/neffs/esphome/tree/bsec2

Before creating a PR we should figure out if it should be an additional component (e.g. bme68x_bsec) or replace the old version. In theory this should also work with BME680, but I don't have one to check. Help would be appreciated.

Adding the additional GAS_ESTIMATE values will be easy, but we also need to provide a way to configure the model.

@nagyrobi
Copy link
Member

nagyrobi commented Jul 6, 2022

Please submit a PR with your work.

@Schluggi
Copy link

Before creating a PR we should figure out if it should be an additional component (e.g. bme68x_bsec) or replace the old version. In theory this should also work with BME680, but I don't have one to check. Help would be appreciated.

Thank you @neffs <3 !
I would love to see your work inside the current bme680_bsec component.
Moreover I can approve that it does work totally fine on an ESP32-C3 with an BME680 (#2072).

@bootmagic
Copy link

It also works on a Pico W with the following build flags modified from #3917

esphome:
  name: <device-name>
  platformio_options:
    build_flags: 
      - -I /data/<device-name>/.piolibdeps/<device-name>/BSEC2\ Software\ Library/src/inc
      - -L /data/<device-name>/.piolibdeps/<device-name>/BSEC2\ Software\ Library/src/cortex-m0plus
      - -lalgobsec

Thanks @neffs.

Before creating a PR we should figure out if it should be an additional component (e.g. bme68x_bsec) or replace the old version. In theory this should also work with BME680, but I don't have one to check. Help would be appreciated.

Could the bme680_bsec component be depreciated and replaced with a bme68x_bsec2 component? This would cover the newer bme688 sensor.

@X4V1
Copy link

X4V1 commented Mar 22, 2023

Hello,

First, thank you @neffs for your contributions, it's really cool to have the support for bme688 :)

I'm trying to test the code from you pull request and I can't compile it.
I'm getting the error "Platform not found: 'sensor.bme68x_bsec'."
Any idea what I'm doing wrong ? I see that your PR passed firsts compile tests so I suppose the problem is between the chair and the keyboard ^^

This is my configuration:

external_components:
  - source: github://neffs/esphome@bsec2_bme68x
    components:
      - bme68x_bsec

substitutions:
  devicename: esp32-5

packages:
  device_base: !include common/boards/arduino/d1-mini32.yaml

i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_i2c

bme68x_bsec:
  address: 0x77
  state_save_interval: 30min
  bsec_configuration: 0,0,4,2,189,... (it is complete in my yaml, but let's not polluate the topic) # bme688_sel_33v_300s_4d

sensor:
  - platform: bme68x_bsec
    temperature:
      name: "BME688 Temperature"
      filters:
        - median
    pressure:
      name: "BME688 Pressure"
      filters:
        - median
    humidity:
      name: "BME688 Humidity"
      filters:
        - median
    iaq:
      name: "BME688 IAQ"
      filters:
        - median
    iaq_static:
      name: "BME688 Static IAQ"
      filters:
        - median
    co2_equivalent:
      name: "BME688 CO2 Equivalent"
      filters:
        - median
    breath_voc_equivalent:
      name: "BME688 Breath VOC Equivalent"
      filters:
        - median
    gas_resistance:
      # Gas resistance in Ω
      name: "BME688 Gas Resistance"
      filters:
        - median

@TCB13
Copy link

TCB13 commented Jan 9, 2024

Here's my config for an ESP32-S2 Mini board (lolin_s2_mini) + ### BME680:

esphome:
  name: esp-device-name

external_components:
  - source: github://neffs/esphome@bsec2_bme68x
    components:
     - bme68x_bsec

esp32:
  board: lolin_s2_mini
  variant: ESP32S2
  framework:
    type: arduino

# Enable logging
logger:

api:
  encryption:
    key: "xxxxxxxxxxxxx"

ota:

wifi:
  ssid: "xxxxxxxxx"
  password: "xxxxxxxxxx"

captive_portal:

i2c:
  sda: 11
  scl: 12

bme68x_bsec:
  # Default: 0x76 or 0x77
  address: 0x77
  temperature_offset: 0
  # Default: static or mobile
  # iaq_mode: static # currently not working
  # Default: lp or ulp
  sample_rate: lp
  # Default: 6h
  state_save_interval: 6h
  # Download from Bosch website: https://www.bosch-sensortec.com/software-tools/software/bme688-software/
  # File: BSEC 2.x
  # bsec2-4-0-0_generic_release_23012023.zip\BSEC2.4.0.0_Generic_Release_23012023\config\bme680\bme680_iaq_33v_3s_28d
  bsec_configuration: 0,0,4,2,189,1,0,0,(...copy from the file above...)

sensor:
  - platform: bme68x_bsec
    temperature:
      name: "Temperature"
      id: "temperature"
    humidity:
      name: "Humidity"
      id: "humidity"
    pressure:
      name: "Pressure"
      id: "pressure"
      icon: "mdi:gauge"
    co2_equivalent:
      name: "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_bsec
    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"};
      }

This config should work for both the BME680 and BME688.

Thank you @neffs for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants