How do I use the temperature and humidity readings from a SCD40 to compensate the VOC readings from a SGP40, both connected to same ESP32?

I have an ESP32 with both a SGP40 and a SCD40 hooked up to it via I2C. The SCD40 reports CO2, temperature, and humidity, and the SGP40 reports VOC and can optionally take in temperature and humidity to compensate those readings.

The docs give this example config, but I don’t know how to define the SCD40 as a source.

# Example configuration entry
sensor:
- platform: sgp4x
    voc:
      name: "VOC Index"
    nox:
      name: "NOx Index"
    compensation:
      humidity_source: dht1_hum
      temperature_source: dht1_temp

Here’s an abridged version of my config:

esphome:
  name: air
  platform: ESP32
  board: esp32doit-devkit-v1

i2c:
  sda: 21
  scl: 22
  scan: True

sensor:
  - platform: sgp4x
    voc:
      name: "VOC Index"
    nox:
      name: "NOx Index"

  - platform: scd4x
    co2:
      name: "Dining Room CO2"
    temperature:
      name: "Dining Room Temperature"
    humidity:
      name: "Dining Room Humidity"
1 Like

I think you would give the temp and humidity sensors an id: and then use that in the sgp

2 Likes

Yep, that worked, thank you. I guess it was kind of obvious, but I had never used ids on sensors before.

New config for anyone that finds this:

sensor:
  - platform: sgp4x
    voc:
      name: "VOC Index"
    nox:
      name: "NOx Index"
    compensation:
      temperature_source: scd40_temperature
      humidity_source: scd40_humidity

  - platform: scd4x
    co2:
      name: "Dining Room CO2"
    temperature:
      name: "Dining Room Temperature"
      id: scd40_temperature
    humidity:
      name: "Dining Room Humidity"
      id: scd40_humidity
2 Likes