Integrating SGP30 Air Quality Sensor with ESP32 via ESPHome
Integrate the SGP30 module to monitor indoor air quality by measuring equivalent carbon dioxide (eCO2) and Total Volatile Organic Compounds (TVOC). The SGP30 communicates over I2C, requiring the bus to be configured in the ESPHome project before adding the sensor entity.
Access the ESPHome dashboard and open the existing node configuration. Since prior peripherals did not utilize I2C, initialize the bus at the top of the configuration file.
i2c:
- id: comm_bus
sda: GPIO21
scl: GPIO22
scan: true
Apend the SGP30 platform block to the sensor section. Specify the previously defined I2C bus and configure the eCO2 and TVOC output parameters.
sensor:
- platform: sgp30
i2c_id: comm_bus
address: 0x58
eco2:
name: "Indoor eCO2"
accuracy_decimals: 1
tvoc:
name: "Indoor TVOC"
accuracy_decimals: 1
store_baseline: true
update_interval: 5s
Below is the complete configuration file incorporating the binary light, NeoPixel strip, DHT11, and the newly added SGP30 module:
captive_portal:
i2c:
- id: comm_bus
sda: GPIO21
scl: GPIO22
scan: true
light:
- platform: binary
name: "Main Switch"
output: relay_1
- platform: neopixelbus
type: GRB
variant: WS2812
pin: GPIO4
num_leds: 25
name: "Ambient Strip"
output:
- id: relay_1
platform: gpio
pin: GPIO2
sensor:
- platform: dht
pin: GPIO5
temperature:
name: "Ambient Temp"
humidity:
name: "Ambient Humidity"
model: DHT11
update_interval: 10s
- platform: sgp30
i2c_id: comm_bus
address: 0x58
eco2:
name: "Indoor eCO2"
accuracy_decimals: 1
tvoc:
name: "Indoor TVOC"
accuracy_decimals: 1
store_baseline: true
update_interval: 5s
Save the configuration and compile the firmware. Flash the generated binary file onto the ESP32 board. Connect the SGP30 module to the designated I2C pins (SDA to GPIO21, SCL to GPIO22) and power the device. Once the board reboots and reconnects to the network, the new entities will automatically populate in Home Assistant with out requiring manual device addition.