Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
esphome:
name: esp_tdisplay
platform: ESP32
board: featheresp32
wifi:
ssid: "some ssid"
password: "wifipassword"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "fallback"
password: "even better"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "something..."
ota:
password: "morestuff"
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_gray
red: 50%
green: 50%
blue: 50%
font:
- file: "Helvetica.ttf"
id: helvetica_48
size: 48
- file: "Helvetica.ttf"
id: helvetica_24
size: 24
- file: "Helvetica.ttf"
id: helvetica_12
size: 12
binary_sensor:
- platform: status
name: "Node Status"
id: system_status
- platform: gpio
pin:
number: GPIO0
inverted: true
name: "T-Display Button Input 0"
id: tdisplay_button_input_0
- platform: gpio
pin:
number: GPIO35
inverted: true
name: "T-Display Button Input 1"
id: tdisplay_button_input_1
# We can still control the backlight independently
switch:
- platform: gpio
pin: GPIO4
name: "Backlight"
id: backlight
#image:
# - file: "mashi-256.jpg"
# id: my_image
# resize: 200x200
# type: RGB24
time:
- platform: homeassistant
id: esptime
timezone: America/Los_Angeles
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
display:
- platform: st7789v
backlight_pin: GPIO4
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
update_interval: 1s
rotation: 270
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_blue));
it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue)); // header bar
//it.strftime((240 / 2), (140 / 3) * 1 + 5, id(helvetica_24), id(my_gray), TextAlign::CENTER, "%Y-%m-%d", id(esptime).now());
//it.strftime((240 / 2), (140 / 3) * 2 + 5, id(helvetica_48), id(my_gray), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());
//it.strftime((240 / 2), (140 / 3) * 1 + 5, id(helvetica_24), id(my_gray), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());
it.print(5, 25, id(helvetica_24), id(my_yellow), TextAlign::TOP_LEFT, "Air Quality Index");
it.print(5, 60, id(helvetica_48), id(my_gray), TextAlign::TOP_LEFT, "PM2.5:");
it.printf(235, 60, id(helvetica_48), id(my_yellow), TextAlign::TOP_RIGHT, "%0.0f", id(pm_2_5_aqi).state);
//it.print(5, 5, id(helvetica_12), id(my_yellow), TextAlign::TOP_LEFT, "ESPHome");
it.strftime(5, 5, id(helvetica_12), id(my_yellow), TextAlign::TOP_LEFT, "%H:%M:%S", id(esptime).now());
// Comment out the above lines to see the image without text overlaid
//it.image(0, 0, id(my_image));
if (id(system_status).state) {
it.print(235, 5, id(helvetica_12), id(my_green), TextAlign::TOP_RIGHT, "Online");
}
else {
it.print(235, 5, id(helvetica_12), id(my_red), TextAlign::TOP_RIGHT, "Offline");
}
# Particulate matter configuration entry
uart:
rx_pin: GPIO27
baud_rate: 9600
sensor:
- platform: pmsx003
id: pmsa003
type: PMSX003
pm_1_0:
id: pm_1_0
name: "Particulate Matter <1.0µm Concentration"
pm_2_5:
id: pm_2_5
name: "Particulate Matter <2.5µm Concentration"
on_value:
lambda: |-
// https://en.wikipedia.org/wiki/Air_quality_index#Computing_the_AQI
if (id(pm_2_5).state < 12.0) {
// good
id(pm_2_5_aqi).publish_state((50.0 - 0.0) / (12.0 - 0.0) * (id(pm_2_5).state - 0.0) + 0.0);
} else if (id(pm_2_5).state < 35.4) {
// moderate
id(pm_2_5_aqi).publish_state((100.0 - 51.0) / (35.4 - 12.1) * (id(pm_2_5).state - 12.1) + 51.0);
} else if (id(pm_2_5).state < 55.4) {
// usg
id(pm_2_5_aqi).publish_state((150.0 - 101.0) / (55.4 - 35.5) * (id(pm_2_5).state - 35.5) + 101.0);
} else if (id(pm_2_5).state < 150.4) {
// unhealthy
id(pm_2_5_aqi).publish_state((200.0 - 151.0) / (150.4 - 55.5) * (id(pm_2_5).state - 55.5) + 151.0);
} else if (id(pm_2_5).state < 150.4) {
// very unhealthy
id(pm_2_5_aqi).publish_state((300.0 - 201.0) / (250.4 - 150.5) * (id(pm_2_5).state - 150.5) + 201.0);
} else if (id(pm_2_5).state < 250.4) {
// hazardous
id(pm_2_5_aqi).publish_state((400.0 - 301.0) / (350.4 - 250.5) * (id(pm_2_5).state - 250.5) + 301.0);
} else if (id(pm_2_5).state < 500.4) {
// hazardous 2
id(pm_2_5_aqi).publish_state((500.0 - 401.0) / (500.4 - 350.5) * (id(pm_2_5).state - 350.5) + 401.0);
}
pm_10_0:
id: pm_10
name: "Particulate Matter <10.0µm Concentration"
- platform: template
name: "PM2.5 AQI"
unit_of_measurement: "AQI"
icon: "mdi:air-filter"
accuracy_decimals: 0
id: pm_2_5_aqi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment