esphome:
  name: displaytft
  friendly_name: DisplayTFT

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

# Enable logging
logger:
  

# Enable Home Assistant API
api:
  encryption:
    key: "4Psr1Xhw+JtHxiETM/08BasfkQFC3zwlBDI3rXXyZ/w="

ota:
  - platform: esphome
    password: "a25db714a1af5052cd451cec259745f4"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Displaytft Fallback Hotspot"
    password: "mnSiduqBBZqx"

captive_portal:
    

# Enable MQTT
mqtt:
    discovery: true
    broker: 192.168.178.10
    port: 1883
    username: !secret mqtt_username
    password: !secret mqtt_password
    client_id: DisplayTFT
    topic_prefix: esphome
   

# Subscribe data
text_sensor:
  - platform: mqtt_subscribe
    id: Solar_Einspeisung_Jetzt
    topic: esphome/DisplayTFT/Solar/Einspeisung_Jetzt
  - platform: mqtt_subscribe
    id: Netz_Verbrauch_Jetzt
    topic: esphome/DisplayTFT/Netz/Verbrauch_Jetzt
  - platform: mqtt_subscribe
    id: Solar_Einspeisung_Monat
    topic: esphome/DisplayTFT/Solar/Einspeisung_Monat
  - platform: mqtt_subscribe
    id: Solar_Einspeisung_Heute
    topic: esphome/DisplayTFT/Solar/Einspeisung_Heute
  - platform: mqtt_subscribe
    id: Netz_Verbrauch_Monat
    topic: esphome/DisplayTFT/Netz/Verbrauch_Monat
  - platform: mqtt_subscribe
    id: Netz_Verbrauch_Gestern
    topic: esphome/DisplayTFT/Netz/Verbrauch_Gestern  
  - platform: mqtt_subscribe
    id: Status_Batterie_SoC
    topic: esphome/DisplayTFT/Status/Batterie_SoC
  - platform: mqtt_subscribe
    id: Status_Ladegeraet
    topic: esphome/DisplayTFT/Status/Ladegeraet
  - platform: mqtt_subscribe
    id: Status_Auto
    topic: esphome/DisplayTFT/Status/Auto
  - platform: mqtt_subscribe
    id: Status_Garagentor
    topic: esphome/DisplayTFT/Status/Garagentor
  - platform: mqtt_subscribe
    id: Status_Fenster_Links
    topic: esphome/DisplayTFT/Status/Fenster_Links
  - platform: mqtt_subscribe
    id: Status_Temperatur_Kueche
    topic: esphome/DisplayTFT/Status/Temperatur_Kueche
  - platform: mqtt_subscribe
    id: Status_Feuchtigkeit_Kueche
    topic: esphome/DisplayTFT/Status/Feuchtigkeit_Kueche   
  - platform: mqtt_subscribe
    id: Heizung_VL_Temperatur_Heizkoerper
    topic: esphome/DisplayTFT/Heizung/VL_Temperatur_Heizkoerper
  - platform: mqtt_subscribe
    id: Heizung_RL_Temperatur_Heizkoerper
    topic: esphome/DisplayTFT/Heizung/RL_Temperatur_Heizkoerper
  - platform: mqtt_subscribe
    id: Heizung_VL_Temperatur_Warmwasser
    topic: esphome/DisplayTFT/Heizung/VL_Temperatur_Warmwasser
  - platform: mqtt_subscribe
    id: Heizung_RL_Temperatur_Warmwasser
    topic: esphome/DisplayTFT/Heizung/RL_Temperatur_Warmwasser    
  - platform: mqtt_subscribe
    id: Verbrauch_Warmwasser_Vortag
    topic: esphome/DisplayTFT/Verbrauch/Warmwasser_Vortag
  - platform: mqtt_subscribe
    id: Verbrauch_Heizung_Vortag
    topic: esphome/DisplayTFT/Verbrauch/Heizung_Vortag
  - platform: mqtt_subscribe
    id: Verbrauch_Warmwasser_Heute
    topic: esphome/DisplayTFT/Verbrauch/Warmwasser_Heute
  - platform: mqtt_subscribe
    id: Verbrauch_Heizung_Heute
    topic: esphome/DisplayTFT/Verbrauch/Heizung_Heute
  - platform: mqtt_subscribe
    id: Verbrauch_Warmwasser_Monat
    topic: esphome/DisplayTFT/Verbrauch/Warmwasser_Monat
  - platform: mqtt_subscribe
    id: Verbrauch_Heizung_Monat
    topic: esphome/DisplayTFT/Verbrauch/Heizung_Monat        

font:
  - file: "Fonts/Verdana.ttf"
    id: Verdana16
    glyphs:
      ['&', '@', '!', ',', '.', '?', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', '/']    
    size: 10


  - file: "Fonts/Verdana.ttf"
    id: Verdana20
    glyphs:
      ['&', '@', '!', ',', '.', '?', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', '/']    
    size: 12


  - file: "Fonts/Verdana.ttf"
    id: Verdana24
    glyphs:
      ['&', '@', '!', ',', '.', '?', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', '/']    
    size: 16


  - file: "Fonts/Verdana_Bold.ttf"
    id: VerdanaBold20
    glyphs:
      ['&', '@', '!', ',', '.', '?', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', '/']    
    size: 16


  - file: "Fonts/materialdesignicons-webfont.ttf"
    id: Icons60
    size: 30
    glyphs:
    - "\U000F0179" # Linie  
    - "\U000F1A74" # Solar
    - "\U000F1904" # Haus
    - "\U000F1AAF" # Heizung
    - "\U000F058F" # Wasserhahn
    - "\U000F0EB8" # Gas
    - "\U000F050F" # Thermometer 
    - "\U000F010B" # Auto
    - "\U000F0080" # Batterie 
    - "\U000F0084" # Batterie laden 
    - "\U000F06D9" # Garage
    - "\U000F06DA" # Garage offen
    - "\U000F17FB" # Garage geschlossen
    - "\U000F11DB" # Fenster 
    - "\U000F05B1" # Fenster offen


# PSRAM configuration 
psram:
  mode: octal
  speed: 80MHz


# Display configuration
spi:
  clk_pin: GPIO12 # SCK
  mosi_pin: GPIO11 # SDI
  miso_pin: GPIO13 # SDO
  

display:
  - platform: ili9xxx
    model: ILI9488
    dc_pin: GPIO9 # Data Command/Register Select
    reset_pin: GPIO8 # RST
    cs_pin: GPIO10 # chip select
    invert_colors: false
    rotation: 90
    update_interval: 1s 
    id: WD1      
    lambda: |-
      it.printf(30, 25, id(Icons60), TextAlign::TOP_RIGHT, "\U000F1A74");
      it.print(85, 20, id(VerdanaBold20), TextAlign::TOP_CENTER, "Leistung");
      it.print(170, 20, id(VerdanaBold20), TextAlign::TOP_CENTER, "Heute");
      it.print(250, 20, id(VerdanaBold20), TextAlign::TOP_CENTER, "Monat");
      it.line(40, 45, 280, 45);
      it.printf(85, 50, id(Verdana24), TextAlign::TOP_CENTER,"%s W", id(Solar_Einspeisung_Jetzt).state.c_str());
      it.printf(170, 50, id(Verdana24), TextAlign::TOP_CENTER,"%s Wh", id(Solar_Einspeisung_Heute).state.c_str());
      it.printf(250, 50, id(Verdana24), TextAlign::TOP_CENTER,"%s kWh", id(Solar_Einspeisung_Monat).state.c_str());
      it.printf(30, 95, id(Icons60), TextAlign::TOP_RIGHT, "\U000F1904");
      it.print(85, 90, id(VerdanaBold20), TextAlign::TOP_CENTER, "Leistung");
      it.print(170, 90, id(VerdanaBold20), TextAlign::TOP_CENTER, "Gestern");
      it.print(250, 90, id(VerdanaBold20), TextAlign::TOP_CENTER, "Monat");
      it.line(40, 115, 280, 115);
      it.printf(85, 120, id(Verdana24), TextAlign::TOP_CENTER,"%s W", id(Netz_Verbrauch_Jetzt).state.c_str());
      it.printf(170, 120, id(Verdana24), TextAlign::TOP_CENTER,"%s kWh", id(Netz_Verbrauch_Gestern).state.c_str());
      it.printf(250, 120, id(Verdana24), TextAlign::TOP_CENTER,"%s kWh", id(Netz_Verbrauch_Monat).state.c_str());
      it.printf(30, 165, id(Icons60), TextAlign::TOP_RIGHT, "\U000F1AAF");
      it.print(85, 160, id(VerdanaBold20), TextAlign::TOP_CENTER, "Vorlauf");
      it.print(170, 160, id(VerdanaBold20), TextAlign::TOP_CENTER, "Rücklauf");
      it.line(50, 185, 210, 185);
      it.printf(85, 190, id(Verdana24), TextAlign::TOP_CENTER,"%s%°C", id(Heizung_VL_Temperatur_Heizkoerper).state.c_str());
      it.printf(170, 190, id(Verdana24), TextAlign::TOP_CENTER,"%s%°C", id(Heizung_RL_Temperatur_Heizkoerper).state.c_str());
      it.printf(30, 235, id(Icons60), TextAlign::TOP_RIGHT, "\U000F058F");
      it.print(85, 230, id(VerdanaBold20), TextAlign::TOP_CENTER, "Vorlauf");
      it.print(170, 230, id(VerdanaBold20), TextAlign::TOP_CENTER, "Rücklauf");
      it.line(50, 255, 210, 255);
      it.printf(85, 260, id(Verdana24), TextAlign::TOP_CENTER,"%s%°C", id(Heizung_VL_Temperatur_Warmwasser).state.c_str());
      it.printf(170, 260, id(Verdana24), TextAlign::TOP_CENTER,"%s%°C", id(Heizung_RL_Temperatur_Warmwasser).state.c_str());
      it.printf(350, 25, id(Icons60), TextAlign::TOP_RIGHT, "\U000F0080");
      it.printf(370, 30, id(Verdana24), TextAlign::TOP_LEFT,"%s%%", id(Status_Batterie_SoC).state.c_str());
      it.printf(350, 65, id(Icons60), TextAlign::TOP_RIGHT, "\U000F0084");
      it.printf(370, 70, id(Verdana24), TextAlign::TOP_LEFT, id(Status_Ladegeraet).state.c_str());
      it.printf(350, 105, id(Icons60), TextAlign::TOP_RIGHT, "\U000F010B");
      it.printf(370, 110, id(Verdana24), TextAlign::TOP_LEFT, id(Status_Auto).state.c_str());
      it.printf(350, 145, id(Icons60), TextAlign::TOP_RIGHT, "\U000F06DA");
      it.printf(370, 150, id(Verdana24), TextAlign::TOP_LEFT, id(Status_Garagentor).state.c_str());
      it.printf(350, 185, id(Icons60), TextAlign::TOP_RIGHT, "\U000F11DB");
      it.printf(370, 190, id(Verdana24), TextAlign::TOP_LEFT, id(Status_Fenster_Links).state.c_str());
      it.line(230, 255, 465, 255);
      it.print(290, 230, id(VerdanaBold20), TextAlign::TOP_CENTER, "Temperatur");
      it.printf(290, 260, id(Verdana24), TextAlign::TOP_CENTER,"%s%°C", id(Status_Temperatur_Kueche).state.c_str());
      it.print(410, 230, id(VerdanaBold20), TextAlign::TOP_CENTER, "Feuchtigkeit");
      it.printf(410, 260, id(Verdana24), TextAlign::TOP_CENTER,"%s%%", id(Status_Feuchtigkeit_Kueche).state.c_str());
