Skip to content

Instantly share code, notes, and snippets.

@geekuillaume
Created January 5, 2022 21:19
Show Gist options
  • Save geekuillaume/f412c634637039f17a5bef2e588f5a33 to your computer and use it in GitHub Desktop.
Save geekuillaume/f412c634637039f17a5bef2e588f5a33 to your computer and use it in GitHub Desktop.
Configuration for ESPHome + LilyGo T5 4.7"
esphome:
name: lilygo-t5
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "XXX"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
time:
- platform: homeassistant
id: ntp
external_components:
- source:
type: git
url: https://github.com/vbaksa/esphome
ref: dev
components:
- lilygo_t5_47_battery
- lilygo_t5_47_display
sensor:
- platform: lilygo_t5_47_battery
update_interval: 5s
id: batt_volt
voltage:
name: "Battery Voltage"
- platform: template
name: "${esp_name} Battery"
id: batt
unit_of_measurement: "%"
accuracy_decimals: 0
device_class: battery
lambda: |-
int y = (1-(4.1-id(batt_volt).voltage->state)/(4.1-3.3))*100;
if (y < 100) {return y;} else {return 100;};
- platform: homeassistant
entity_id: sensor.openweathermap_forecast_precipitation_probability
id: prec_perc
internal: true
- platform: homeassistant
entity_id: sensor.openweathermap_forecast_temperature_low
id: fc_low
internal: true
- platform: homeassistant
entity_id: sensor.openweathermap_forecast_temperature
id: fc_high
internal: true
- platform: homeassistant
entity_id: sensor.openweathermap_feels_like_temperature
id: temp_outside
internal: true
- platform: homeassistant
entity_id: sensor.temperature_chambre
id: temp_chambre
internal: true
- platform: homeassistant
entity_id: sensor.temperature_salon
id: temp_salon
internal: true
- platform: homeassistant
entity_id: sensor.coffee_machine_temperature
id: coffee_temp
internal: true
filters:
- throttle: 10s
on_value:
then:
- script.execute: all_data_received
- platform: homeassistant
entity_id: sensor.octoprint_job_percentage
id: printer_percentage
internal: true
filters:
- throttle: 10s
on_value:
then:
- script.execute: all_data_received
text_sensor:
- platform: homeassistant
entity_id: media_player.spotify_guillaume_besson
attribute: media_title
id: spotify_playing_title
internal: true
- platform: homeassistant
entity_id: media_player.spotify_guillaume_besson
attribute: media_artist
id: spotify_playing_artist
internal: true
on_value: # Actions to perform once data for the last sensor has been received
then:
- script.execute: all_data_received
- platform: homeassistant
entity_id: sensor.openweathermap_precipitation_kind
id: fc_prec
internal: true
- platform: homeassistant
entity_id: sensor.openweathermap_forecast_condition
id: fc_weather
internal: true
on_value: # Actions to perform once data for the last sensor has been received
then:
- script.execute: all_data_received
binary_sensor:
- platform: gpio
pin:
number: GPIO39
inverted: true
name: "lilygo-t5 Button 1"
on_press:
then:
- component.update: t5_display
- platform: gpio
pin:
number: GPIO34
inverted: true
name: "lilygo-t5 Button 2"
- platform: gpio
pin:
number: GPIO35
inverted: true
name: "lilygo-t5 Button 3"
- platform: homeassistant
internal: true
entity_id: binary_sensor.coffee_machine_pid_on
id: coffee_pid_on
on_state:
then:
- script.execute: all_data_received
- platform: homeassistant
internal: true
entity_id: binary_sensor.octoprint_printing
id: printer_printing
on_state:
then:
- script.execute: all_data_received
font:
- file: "fonts/GoogleSans-Bold.ttf"
id: font_name
size: 38
glyphs: |-
!"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'éèàòùç/&ôœìïöñ
- file: "fonts/GoogleSans-Medium.ttf"
id: font_value
size: 56
glyphs: |-
!"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'éèàòùç/&ôœìïöñ
- file: "fonts/GoogleSans-Medium.ttf"
id: font_footer
size: 28
glyphs: |-
!"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz'éèàòùç/&ôœìïöñ
# https://pictogrammers.github.io/@mdi/font/5.3.45/
- file: 'fonts/materialdesignicons-webfont.ttf'
id: font_icons
size: 160
glyphs:
- "\U000F0594" # clear-night
- "\U000F0590" # cloudy
- "\U000F0595" # partlycloudy
- "\U000F0591" # fog
- "\U000F0592" # hail
- "\U000F0593" # lightning
- "\U000F067E" # lightning-rainy
- "\U000F0596" # pouring
- "\U000F0597" # rainy
- "\U000F0F36" # snowy
- "\U000F067F" # snowy-rainy
- "\U000F0599" # sunny
- "\U000F059D" # windy
- "\U000F059E" # windy-variant
- "\U000F0F38" # exceptional
- file: 'fonts/materialdesignicons-webfont.ttf'
id: font_icons_small
size: 56
glyphs:
- "\U000F10C2" # Temperature High
- "\U000F10C3" # Temperature Low
- "\U000F07E4" # CO2
- "\U000F054B" # umbrella
- "\U000F0592" # hail
- "\U000F0593" # lightning
- "\U000F067E" # lightning-rainy
- "\U000F0597" # rainy
- "\U000F0F36" # snowy
- "\U000F0594" # clear-night
- "\U000F0599" # sunny
- "\U000F07CA" # fuel
- "\U000F024A" # flower
- "\U000F051F" # time-remaining
- "\U000F140B" # Energy
- "\U000F109F" # Coffee
- "\U000F02E3" # Bed
- "\U000F0531" # Tree
- "\U000F0E5B" # 3D Printer
script:
- id: all_data_received
then:
# - component.update: batt_volt
# - component.update: batt
- component.update: t5_display
display:
- platform: lilygo_t5_47_display
id: t5_display
rotation: 0
update_interval: 60s
lambda: |-
#define xres 960
#define yres 540
#define x_pad 10 // border padding
#define y_pad 10 // border padding
#define cat_pad 80 // padding before category
#define val_pad 70 // padding before value
#define icon_pad 35 //padding after icons
#define x1n 20 //x position 1st column name
#define x1v 25 //x position 1st column value
#define x1i 50 //x position 1st column icon
#define x2n ((xres/3) * 1) //x position 2nd column name
#define x2v ((xres/3) * 1) //x position 2nd column value
#define x2i ((xres/3) * 1) //x position 2nd column icon
#define x3n ((xres/3) * 2) //x position 3rd column name
#define x3v ((xres/3) * 2) //x position 3rd column value
#define x3i ((xres/3) * 2) //x position 3rd column icon
int y1 = 0;
int y2 = 0;
int y3 = 0;
// Date
it.strftime(
xres/2,
y1+y_pad,
id(font_name),
TextAlign::TOP_CENTER,
"%A %d/%b/%Y",
id(ntp).now()
);
y1+=cat_pad+20;
y2+=cat_pad+20;
y3+=cat_pad+20;
// Currently playing on column 1 and 2
it.print(x1n, y1, id(font_name), TextAlign::BASELINE_LEFT, "Currently playing");
y1+= val_pad;
y2+= val_pad;
it.printf(x1v, y1, id(font_value), TextAlign::BASELINE_LEFT, "%.20s", id(spotify_playing_title).state.c_str());
y1 += icon_pad;
y2 += icon_pad;
it.printf(x1v, y1, id(font_footer), TextAlign::BASELINE_LEFT, "%.40s", id(spotify_playing_artist).state.c_str());
y1 += val_pad;
y2 += val_pad;
#define weather_icon_x x3i + xres/6
y3 += 40;
//Weather forecast Icon
if (id(fc_weather).state == "clear-night") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0594");}
if (id(fc_weather).state == "cloudy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0590");}
if (id(fc_weather).state == "partlycloudy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0595");}
if (id(fc_weather).state == "fog") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0591");}
if (id(fc_weather).state == "hail") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0592");}
if (id(fc_weather).state == "lightning") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0593");}
if (id(fc_weather).state == "lightning-rainy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F067E");}
if (id(fc_weather).state == "pouring") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0596");}
if (id(fc_weather).state == "rainy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0597");}
if (id(fc_weather).state == "snowy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0F36");}
if (id(fc_weather).state == "snowy-rainy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F067F");}
if (id(fc_weather).state == "sunny") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0599");}
if (id(fc_weather).state == "windy") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F059D");}
if (id(fc_weather).state == "windy-variant") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F059E");}
if (id(fc_weather).state == "exceptional") {
it.printf(weather_icon_x, y3, id(font_icons), TextAlign::CENTER, "\U000F0F38");}
y3 += 160;
// High/Low Temperature
it.printf(x3i+30, y3-15, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F10C2"); // temp high
it.printf(x3i+30+icon_pad, y3-10, id(font_value), TextAlign::BASELINE_LEFT, "%.1f °C", id(fc_high).state);
it.printf(x3i+30, y3+15, id(font_icons_small), TextAlign::TOP_CENTER, "\U000F10C3"); // temp low
it.printf(x3i+30+icon_pad, y3+10, id(font_value), TextAlign::TOP_LEFT, "%.1f °C", id(fc_low).state);
y3+=cat_pad+50;
// Precipitation
it.print(x3n, y3, id(font_name), TextAlign::BASELINE_LEFT, "Precipitation");
y3+=val_pad;
#define temp_icon_x x3i+30
if (id(fc_prec).state == "None") {
it.printf(temp_icon_x, y3, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F054B");}
if (id(fc_prec).state == "Hail") {
it.printf(temp_icon_x, y3, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F0592");}
if (id(fc_prec).state == "Rain") {
it.printf(temp_icon_x, y3, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F0597");}
if (id(fc_prec).state == "Snow") {
it.printf(temp_icon_x, y3, id(font_icons_small), TextAlign::BASELINE_CENTER, "\U000F0F36");}
it.printf(temp_icon_x+icon_pad, y3, id(font_value), TextAlign::BASELINE_LEFT, "%3.0f %%", id(prec_perc).state);
y3 +=cat_pad;
// Bedroom
it.print(x1n, y1, id(font_name), TextAlign::BASELINE_LEFT, "Bedroom");
y1+= val_pad;
it.printf(x1n, y1, id(font_icons_small), TextAlign::BASELINE_LEFT, "\U000F02E3");
it.printf(x1v + 60, y1, id(font_value), TextAlign::BASELINE_LEFT, "%.1f °C", id(temp_chambre).state);
y1 += cat_pad;
// Outside
it.print(x2n, y2, id(font_name), TextAlign::BASELINE_LEFT, "Outside");
y2+= val_pad;
it.printf(x2n, y2, id(font_icons_small), TextAlign::BASELINE_LEFT, "\U000F0531");
it.printf(x2v + 60, y2, id(font_value), TextAlign::BASELINE_LEFT, "%.1f °C", id(temp_outside).state);
y2 += cat_pad;
// Coffee machine
it.print(x1n, y1, id(font_name), TextAlign::BASELINE_LEFT, "Coffee");
y1+= val_pad;
it.printf(x1n, y1, id(font_icons_small), TextAlign::BASELINE_LEFT, "\U000F109F");
if (!isnan(id(coffee_temp).state)) {
it.printf(x1v + 60, y1, id(font_value), TextAlign::BASELINE_LEFT, "%.1f °C", id(coffee_temp).state);
} else {
it.printf(x1v + 60, y1, id(font_value), TextAlign::BASELINE_LEFT, "Off");
}
// 3D printer
it.print(x2n, y2, id(font_name), TextAlign::BASELINE_LEFT, "3D Printer");
y2+= val_pad;
it.printf(x2n, y2, id(font_icons_small), TextAlign::BASELINE_LEFT, "\U000F0E5B");
if (id(printer_printing).state) {
it.printf(x2v + 60, y2, id(font_value), TextAlign::BASELINE_LEFT, "%.0f %%", id(printer_percentage).state);
} else {
it.printf(x2v + 60, y2, id(font_value), TextAlign::BASELINE_LEFT, "Off");
}
// Footer
it.strftime(xres/2, yres-y_pad/2, id(font_footer), TextAlign::BASELINE_CENTER, "Updated: %H:%M", id(ntp).now());
//it.printf(xres-x_pad, yres-y_pad/2, id(font_footer), TextAlign::BASELINE_RIGHT, "%.2fV/%.0f%%", id(batt_volt).voltage->state, id(batt).state);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment