Files
hassos_config/esphome/cfg_experimental/display-ttgo.yaml
2024-07-18 09:12:31 +02:00

393 lines
11 KiB
YAML

substitutions:
device_name: "ttgo-display"
friendly_name: "ttgo-display"
comment: "esp32, display, distance"
api_password: !secret ttgo-t-display_api
ota_password: !secret ota_password
wifi_ssid: !secret wifi_ssid
wifi_password: !secret wifi_password
gateway: !secret ip_gateway
subnet: !secret ip_subnet
ip: !secret ttgo-t-display_ip
pin_sda: GPIO21
pin_scl: GPIO22
pin_but0: GPIO0
pin_but1: GPIO35
pin_spi_clk: GPIO18
pin_spi_mosi: GPIO19
pin_lcd_bl: GPIO4
pin_lcd_cs: GPIO5
pin_lcd_dc: GPIO16
pin_lcd_rst: GPIO23
packages:
board: !include boards/esp32_wroom_arduino.yaml
device_base: !include common/common.yaml
connection: !include common/wifi.yaml
logger: !include templates/logger.yaml
time: !include templates/time.yaml
spi:
clk_pin: ${pin_spi_clk}
mosi_pin: ${pin_spi_mosi}
# Define the rotate variable. This indicates if the pages should be rotated or not
globals:
- id: rotate
type: boolean
initial_value: "true"
# Define binary sensors
binary_sensor:
- platform: gpio # Short Press button 0
pin:
number: ${pin_but0}
inverted: true
mode:
input: true
pullup: true
name: "Short Press Button 0"
id: short_press_button_0
on_click:
min_length: 1ms
max_length: 1000ms
then:
- display.page.show_previous: my_display
- component.update: my_display
- platform: gpio # Long Press button 1
pin:
number: ${pin_but1}
inverted: true
name: "Long Press Button 1"
id: long_press_button_1
on_click:
min_length: 1001ms
max_length: 5000ms
then:
- if:
condition:
lambda: |-
return id(rotate);
then:
globals.set:
id: rotate
value: "false"
else:
globals.set:
id: rotate
value: "true"
# Define all the numeric sensors used
sensor:
- platform: homeassistant
entity_id: sensor.views
id: views
- platform: homeassistant
entity_id: sensor.ttgo_display_data
attribute: netto_power
id: nettopower
- platform: homeassistant
entity_id: sensor.esp32_s2_aqs_ikea_temperature
id: office_temperature
- platform: homeassistant
entity_id: sensor.esp32_s2_aqs_ikea_humidity
id: office_humidity
- platform: homeassistant
entity_id: sensor.ttgo_display_data
attribute: temperature
id: outside_temperature
- platform: homeassistant
entity_id: sensor.ttgo_display_data
attribute: wind_speed
id: wind_speed
- platform: homeassistant
entity_id: sensor.exchange_rate_1_btc
id: bitcoin
# Define all the string sensors used
text_sensor:
- platform: homeassistant
entity_id: sensor.ttgo_display_data
attribute: weather_condition_0
id: weather_condition
filters:
- to_upper:
# Define fonts. Use either Google fonts or stored fonts. Stored fonts are stored in esphome/fonts/
font:
- file:
type: gfonts
family: Lato
weight: 400
id: lato
size: 20
- file:
type: gfonts
family: Lato
weight: 700
id: latobold
size: 24
- file:
type: gfonts
family: Lato
weight: 900
id: latoblack
size: 30
- file:
type: gfonts
family: Lato
weight: 900
id: latoblackheading1
size: 50
- file: "fonts/bitcoin/Ubuntu-BoldItalic.ttf"
id: bitcoin_font
size: 30
# Define colors
color:
- id: RED
red: 100%
green: 0%
blue: 0%
- id: GREEN
red: 0%
green: 100%
blue: 0%
- id: BLUE
red: 0%
green: 0%
blue: 100%
- id: YELLOW
red: 100%
green: 100%
blue: 0%
- id: WHITE
red: 100%
green: 100%
blue: 100%
- id: ORANGE
red: 100%
green: 67%
blue: 20%
# Define all the images used. Store the images in the images folder within the esphome folder (esphome/images/)
image:
- file: "images/youtube.png"
id: youtube_image
resize: 80x80
type: RGB24
- file: "images/logo.jpg"
id: logo
resize: 120x120
type: RGB24
- file: "images/electricity-icon.png"
id: electricity_image
resize: 80x80
type: RGB24
- file: "images/bitcoin_logo.png"
id: bitcoin_logo
resize: 80x80
type: RGB24
- file: "images/wind_icon.png"
id: wind_icon
resize: 30x30
type: RGB24
- file: "images/thermometer_icon.png"
id: thermometer_icon
resize: 30x30
type: RGB24
# Define animations
animation:
- file: "images/weather.gif"
id: weather_animation
resize: 80x80
type: RGB24
# Define the graphs for sensors that you want to show on the display
graph:
- id: office_temperature_graph
sensor: office_temperature
duration: 4h
width: 220
height: 90
x_grid: 1min
y_grid: 5
min_range: 5
max_range: 35
min_value: 5
max_value: 35
color: GREEN
- id: office_humidity_graph
sensor: office_humidity
duration: 4h
width: 220
height: 90
x_grid: 1min
y_grid: 25
min_range: 1
max_range: 100
min_value: 1
max_value: 100
color: BLUE
- id: power_graph
sensor: nettopower
duration: 4h
width: 220
height: 90
x_grid: 15min
y_grid: 100.0
color: YELLOW
# - id: office_light_sensor_graph
# duration: 4h
# width: 220
# height: 90
# x_grid: 1h
# traces:
# - sensor: office_light_sensor
# color: ORANGE
# line_type: SOLID
# line_thickness: 5
# Define qr code locations
qr_code:
- id: smarthomejunkie_website
value: smarthomejunkie.net
# Set up the display. This is the main part of the code
display:
- platform: st7789v
model: TTGO_TDISPLAY_135x240
backlight_pin: ${pin_lcd_bl}
cs_pin: ${pin_lcd_cs}
dc_pin: ${pin_lcd_dc}
reset_pin: ${pin_lcd_rst}
rotation: 90°
update_interval: 1s
id: my_display
pages: # Define the pages
- id: showtime
lambda: |-
it.strftime(45, 20, id(latoblack), "%d-%m-%Y", id(homeassistant_time).now());
it.strftime(25, 55, id(latoblackheading1), "%H:%M:%S", id(homeassistant_time).now());
- id: shownettopower
lambda: |-
it.printf(0,0,id(latoblack), WHITE, "NETTO POWER");
it.image(0, 40, id(electricity_image));
if (id(nettopower).has_state()) {
if (id(nettopower).state > -1000) {
it.printf(95, 60, id(latoblack), WHITE, "%.2f kWh", id(nettopower).state);
} else {
it.printf(95, 60, id(latobold), WHITE, "%.2f kWh", id(nettopower).state);
}
} else {
it.printf(95, 65, id(lato), WHITE, "LOADING...");
}
# - id: showbitcoin
# lambda: |-
# it.printf(0,0,id(bitcoin_font), WHITE, "bitcoin");
# it.image(0, 40, id(bitcoin_logo));
# if (id(bitcoin).has_state()) {
# it.printf(95, 60, id(bitcoin_font), WHITE, "%.0f", id(bitcoin).state);
# } else {
# it.printf(95, 65, id(lato), WHITE, "LOADING...");
# }
- id: show_office_temperature_graph
lambda: |-
if (id(office_temperature).has_state()) {
it.printf(0,0,id(latoblack), WHITE, "TEMP: %.1f °C", id(office_temperature).state);
it.graph(10, 40, id(office_temperature_graph));
} else {
it.printf(0,0,id(latoblack), WHITE, "TEMPERATURE");
it.printf(80, 65, id(lato), WHITE, "LOADING...");
}
- id: show_office_humidity_graph
lambda: |-
if (id(office_humidity).has_state()) {
it.printf(0,0,id(latoblack), WHITE, "HUM: %.0f %%", id(office_humidity).state);
it.graph(10, 40, id(office_humidity_graph));
} else {
it.printf(0,0,id(latoblack), WHITE, "HUMIDITY");
it.printf(80, 65, id(lato), WHITE, "LOADING...");
}
- id: show_nettopower_graph
lambda: |-
if (id(nettopower).has_state()) {
it.printf(0,0,id(latoblack), WHITE, "power: %.2f Kwh", id(nettopower).state);
it.graph(10, 40, id(power_graph));
} else {
it.printf(0,0,id(latoblack), WHITE, "PRESSURE");
it.printf(80, 65, id(lato), WHITE, "LOADING...");
}
# - id: show_office_light_sensor_graph
# lambda: |-
# if (id(office_light_sensor).has_state()) {
# it.printf(0,0,id(latoblack), WHITE, "LUX: %.0f lx", id(office_light_sensor).state);
# it.graph(10, 40, id(office_light_sensor_graph));
# } else {
# it.printf(0,0,id(latoblack), WHITE, "LUX");
# it.printf(80, 65, id(lato), WHITE, "LOADING...");
# }
- id: show_weather
lambda: |-
id(weather_animation).next_frame();
it.image(0, 0, id(weather_animation), COLOR_ON, COLOR_OFF);
if (id(weather_condition).state == "CLOUDY" ||
id(weather_condition).state == "RAINY" ||
id(weather_condition).state == "FOG" ||
id(weather_condition).state == "HAIL" ||
id(weather_condition).state == "SNOWY" ||
id(weather_condition).state == "SUNNY" ||
id(weather_condition).state == "WINDY" ) {
it.printf(110,0,id(latoblack), WHITE,"%s",id(weather_condition).state.c_str());
}
if (id(weather_condition).state == "LIGTNING" ||
id(weather_condition).state == "POURING" ) {
it.printf(110,0,id(latobold), WHITE,"%s",id(weather_condition).state.c_str());
}
if (id(weather_condition).state == "PARTLYCLOUDY") {
it.printf(110,0,id(latoblack), WHITE,"PARTLY");
it.printf(110,35,id(latoblack), WHITE,"CLOUDY");
}
if (id(weather_condition).state == "SNOWY-RAIN") {
it.printf(110,0,id(latoblack), WHITE,"SNOWY");
it.printf(110,35,id(latoblack), WHITE,"RAIN");
}
if (id(weather_condition).state == "LIGHTNING-RAINY") {
it.printf(110,0,id(latobold), WHITE,"LIGHTNING");
it.printf(110,35,id(latobold), WHITE,"RAINY");
}
if (id(weather_condition).state == "WINDY-VARIANT") {
it.printf(110,0,id(latoblack), WHITE,"WINDY");
}
if (id(weather_condition).state == "CLEAR-NIGHT") {
it.printf(110,0,id(latoblack), WHITE,"CLEAR");
it.printf(110,35,id(latoblack), WHITE,"NIGHT");
}
if (id(weather_condition).state == "EXCEPTIONAL") {
it.printf(110,0,id(latobold), WHITE,"EXCEPTIONAL");
}
it.image(0, 100, id(thermometer_icon));
it.printf(35,100,id(latobold), WHITE,"%.1f °C", id(outside_temperature).state);
it.image(110, 100, id(wind_icon));
it.printf(145,100,id(latobold), WHITE,"%.2f m/s", id(wind_speed).state);
# - id: showqrcode
# lambda: |-
# it.qr_code(60, 5, id(smarthomejunkie_website), WHITE, 5);
# Define the cycle interval of the pages.
interval:
- interval: 5s
then:
if:
condition:
lambda: 'return id(rotate);'
then:
- display.page.show_next: my_display
- component.update: my_display