Skip to content

Instantly share code, notes, and snippets.

@Savjee
Created September 27, 2021 13:39
Show Gist options
  • Save Savjee/b38e7667f6d28503056ce2f840332946 to your computer and use it in GitHub Desktop.
Save Savjee/b38e7667f6d28503056ce2f840332946 to your computer and use it in GitHub Desktop.
esphome:
name: "air-quality-indoor"
platform: ESP32
board: "featheresp32"
wifi:
ssid: "YOUR WIFI NETWORK NAME"
password: "YOUR WIFI PASSWORD"
logger:
# Enable Home Assistant API
api:
password: "A PASSWORD FOR HOME ASSISTANT"
ota:
password: "A PASSWORD FOR OTA UPDATES"
# CO2 sensor
uart:
rx_pin: 27
tx_pin: 26
baud_rate: 9600
# Dipslay driver: ST7789
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
font:
- file: "Oswald-Light.ttf"
id: font_70
size: 70
glyphs: 0123456789 # Only used for CO2 level
- file: "Oswald-Light.ttf"
id: font_30
size: 30
color:
- id: color_black
red: 0%
green: 0%
blue: 0%
white: 0%
- id: color_green
red: 0%
green: 100%
blue: 0%
- id: color_yellow
red: 100%
green: 100%
blue: 0%
- id: color_orange
red: 100%
green: 55%
blue: 0%
- id: color_red
red: 100%
green: 0%
- id: color_white
red: 100%
green: 100%
blue: 100%
display:
- platform: st7789v
id: my_display
backlight_pin: GPIO4
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
brightness: 100%
rotation: 90
pages:
# Page 1: Current CO2 levels
# 0 - 1000 -> Green
# 1000 - 1600 -> Yellow
# 1600 - 2000 -> Orange
# >2000 -> Red
- id: page1
lambda: |-
if(!id(co2_sensor).has_state() ){
it.print(
it.get_width()/2,
it.get_height()/2,
id(font_70),
color_white,
TextAlign::CENTER,
"Starting..."
);
return;
}
auto bg_color = id(color_black);
auto text_color = id(color_green);
auto co2 = id(co2_sensor).state;
if(co2 > 1000) text_color = id(color_yellow);
if(co2 > 1600) text_color = id(color_orange);
if(co2 > 2000){
text_color = id(color_white);
bg_color = id(color_red);
}
it.filled_rectangle(0, 0, it.get_width(), it.get_height(), bg_color);
it.printf(
it.get_width()/2,
it.get_height()/2,
id(font_70),
text_color,
TextAlign::CENTER,
"%.0f",
co2
);
# Page 2: WiFi information
- id: page2
lambda: |-
it.print(
0, 0,
id(font_30),
id(color_white),
"WiFi details"
);
it.printf(
0, 30,
id(font_30),
id(color_white),
"%s",
id(wifi_ssid).state.c_str()
);
it.printf(
0, 60,
id(font_30),
id(color_white),
"%s",
id(wifi_ip_addr).state.c_str()
);
switch:
- platform: gpio
pin: GPIO4
id: backlight
internal: true
sensor:
- platform: mhz19
co2:
name: "CO2 Indoor"
id: "co2_sensor"
temperature:
name: "Temperature"
internal: true
update_interval: 60s
automatic_baseline_calibration: false
text_sensor:
- platform: wifi_info
ip_address:
internal: true
id: wifi_ip_addr
ssid:
internal: true
id: wifi_ssid
binary_sensor:
# Button to cycle through pages on the display
- platform: gpio
pin:
number: GPIO35
inverted: true
id: button_1
on_click:
then:
- display.page.show_next: my_display
- component.update: my_display
# Button to toggle the backlight (for use at night)
- platform: gpio
pin:
number: GPIO0
inverted: true
id: button_2
on_click:
then:
- switch.toggle: backlight
@Savjee
Copy link
Author

Savjee commented Dec 20, 2022

According to https://esphome.io/components/sensor/dht.html
It should be as simple as:

sensor:
  - platform: dht
    pin: PIN_NUMBER_HERE
    temperature:
      name: "Living Room Temperature"
    humidity:
      name: "Living Room Humidity"

Just make sure to add the correct pin number.

@LS-PER
Copy link

LS-PER commented Oct 18, 2024

Hello @Savjee.
Can you help me with the yml file? How to add a relay switching in 1000ppm for 60 seconds? on which pin, the best?
Thank you.

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