Skip to content

Instantly share code, notes, and snippets.

@TitleOS
Last active April 6, 2023 14:36
Show Gist options
  • Save TitleOS/95186b43dd0659d9ee99b6a3a3b1b3ff to your computer and use it in GitHub Desktop.
Save TitleOS/95186b43dd0659d9ee99b6a3a3b1b3ff to your computer and use it in GitHub Desktop.
ESPHome Yaml for the Ruach Air Quality Sensor
esphome:
name: "ruach-living-room"
esp32:
board: adafruit_qtpy_esp32s2
framework:
type: arduino
globals:
- id: iaq_index
type: int
restore_value: no
initial_value: '0'
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Ruach-living-room Diag Hotspot"
password: !secret wifi_password
captive_portal:
i2c:
- id: stemma
sda: 41
scl: 40
scan: true
sensor:
- platform: sgp30
eco2:
id: eco2_monitor
name: "Living Room eCO2"
accuracy_decimals: 1
tvoc:
id: tvoc_monitor
name: "Living Room TVOC"
accuracy_decimals: 1
store_baseline: yes
address: 0x58
update_interval: 1s
compensation:
temperature_source: temperature_monitor
humidity_source: humidity_monitor
- platform: bme680
temperature:
filters:
offset: -7
name: "Living Room Temperature"
id: temperature_monitor
oversampling: 16x
pressure:
name: "Living Room Air Pressure"
humidity:
id: humidity_monitor
name: "Living Room Humidity"
gas_resistance:
id: gas_resistance_monitor
name: "Living Room Gas Resistance"
address: 0x77
update_interval: 1s
text_sensor:
- platform: template
name: "Living Room IAQ"
icon: "mdi:air-filter"
lambda: |-
id(iaq_index) = 0;
if (id(humidity_monitor).state < 10 or id(humidity_monitor).state > 90) {
id(iaq_index) += 1;
}
if (id(humidity_monitor).state < 20 or id(humidity_monitor).state > 80) {
id(iaq_index) += 2;
}
if (id(humidity_monitor).state < 30 or id(humidity_monitor).state > 70) {
id(iaq_index) += 3;
}
if (id(humidity_monitor).state < 40 or id(humidity_monitor).state > 60) {
id(iaq_index) += 4;
}
if (id(humidity_monitor).state >= 40 and id(humidity_monitor).state <= 60) {
id(iaq_index) += 5;
}
if (id(eco2_monitor).state <= 600) {
id(iaq_index) += 5;
}
if (id(eco2_monitor).state <= 800) {
id(iaq_index) += 4;
}
if (id(eco2_monitor).state <= 1000) {
id(iaq_index) += 3;
}
if (id(eco2_monitor).state <= 1500) {
id(iaq_index) += 2;
}
if (id(eco2_monitor).state > 2000) {
id(iaq_index) += 1;
}
if (id(tvoc_monitor).state <= 65) {
id(iaq_index) += 5;
} if (id(tvoc_monitor).state <= 220) {
id(iaq_index) += 4;
} if (id(tvoc_monitor).state <= 660) {
id(iaq_index) += 3;
} if (id(tvoc_monitor).state <= 1000) {
id(iaq_index) += 2;
} if (id(tvoc_monitor).state <= 2000) {
id(iaq_index) += 1;
}
if(id(gas_resistance_monitor).state <= 50000) {
id(iaq_index) += 5;
}
if(id(gas_resistance_monitor).state <= 40000) {
id(iaq_index) += 4;
}
if(id(gas_resistance_monitor).state <= 30000) {
id(iaq_index) += 3;
}
if(id(gas_resistance_monitor).state <= 20000) {
id(iaq_index) += 2;
}
if(id(gas_resistance_monitor).state <= 10000) {
id(iaq_index) += 1;
}
if(id(gas_resistance_monitor).state = 0) {
id(iaq_index) += 0;
}
if (id(iaq_index) <= 7) {
return {"Toxic"};
}
else if (id(iaq_index) <= 10) {
return {"Poor"};
}
else if (id(iaq_index) <= 13) {
return {"Moderate"};
}
else if (id(iaq_index) <= 15) {
return {"Good"};
}
else if (id(iaq_index) > 15) {
return {"Excellent"};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment