Skip to content

Instantly share code, notes, and snippets.

@letsautomatenet
Created December 27, 2023 15:24
Show Gist options
  • Save letsautomatenet/d1f52e55f6d4d463d1c95bb613a9a74f to your computer and use it in GitHub Desktop.
Save letsautomatenet/d1f52e55f6d4d463d1c95bb613a9a74f to your computer and use it in GitHub Desktop.
BME680 Air Quality Sensor
esphome:
name: bme680
friendly_name: Air Quality Sensor
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
# If you go to this page it generates one for you automatically!
# https://esphome.io/components/api.html#configuration-variables
key: "Generate a key and put it here"
ota:
password: "randomsecurepassword"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "BME680 Fallback Hotspot"
password: "randompassword"
captive_portal:
i2c:
scl: D1
sda: D2
scan: true
id: bus_a
text_sensor:
- platform: template
name: "BME680 IAQ Classification"
icon: "mdi:checkbox-marked-circle-outline"
lambda: |-
if (int(id(iaq).state) <= 50) {
return {"Excellent"};
}
else if (int(id(iaq).state) <= 100) {
return {"Good"};
}
else if (int(id(iaq).state) <= 150) {
return {"Lightly polluted"};
}
else if (int(id(iaq).state) <= 200) {
return {"Moderately polluted"};
}
else if (int(id(iaq).state) <= 250) {
return {"Heavily polluted"};
}
else if (int(id(iaq).state) <= 350) {
return {"Severely polluted"};
}
else if (int(id(iaq).state) <= 500) {
return {"Extremely polluted"};
}
else {
return {"unknown"};
}
sensor:
- platform: bme680
temperature:
name: "BME680 Temperature"
oversampling: 16x
pressure:
name: "BME680 Pressure"
humidity:
id: "humidity"
name: "BME680 Humidity"
gas_resistance:
id: "gas_resistance"
name: "BME680 Gas Resistance"
address: 0x77
update_interval: 60s
- platform: template
name: "BME680 Indoor Air Quality"
id: iaq
icon: "mdi:gauge"
# caulculation: comp_gas = log(R_gas[ohm]) + 0.04 log(Ohm)/%rh * hum[%rh]
lambda: |-
return log(id(gas_resistance).state) + 0.04 * id(humidity).state;
# VL53L0X Distance Sensor
# Comment this section out if just using the BME680 sensor.
# This section is here because this sensor was also in the same YouTube video.
- platform: vl53l0x
name: "Distance Sensor"
id: distance1
i2c_id: bus_a
address: 0x29
# enable_pin: GPIO14
timeout: 200us
update_interval: 500ms
unit_of_measurement: "m"
long_range: false
internal: false
# filters:
# - clamp:
# min_value: 10
# max_value: 75
# ignore_out_of_range: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment