esphome:
  name: epaper75
 
esp32:
  board: esp32dev
  framework:
    type: arduino
 
# Enable logging
logger:
 
# Enable Home Assistant API
api:
  encryption:
    key: "tY/skPnkQn1sZRBYYJ4LL571z+aA1P463WvaX58ju2w="

ota:
  platform: esphome
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
 
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Epaper75 Fallback Hotspot"
    password: "FALLBACKPW"
 
captive_portal:
 
 
# Example configuration entry
spi:
  clk_pin: 13
  mosi_pin: 14
 
# --- Fonts --------------------------------------------------------------------  
font:
  - file: 'fonts/OpenSans-Bold.ttf'
    id: openSansBold_font
    size: 20
    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', 'å', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', '/', '€', '’', 'ß']
 
  - file: 'fonts/OpenSans-Bold.ttf'
    id: watch_font
    size: 90
    glyphs:
      [':', ".", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
       
  # https://pictogrammers.github.io/@mdi/font/6.5.95/    Unicodes
  - file: 'fonts/materialdesignicons-webfont.ttf'
    id: materialdesign_icons_25
    size: 25
    glyphs: [
      "\U000F050F", # mdi-thermometer
      "\U000F0F55", # mdi-home-thermometer-outline
      "\U000F0F54", # mdi-home-thermometer
      "\U000F058E", # mdi-water-percent
      "\U000F029A", # mdi-gauge
      "\U000F059B", # mdi-weather-sunset
      "\U000F059C", # mdi-weather-sunrise
      "\U000F10C2", # mdi-thermometer-high
      "\U000F10C3"  # mdi-thermometer-low
      ]
       
  - file: 'fonts/materialdesignicons-webfont.ttf'
    id: materialdesign_icons_32
    size: 32
    glyphs: [
      "\U000F091F", # mdi-wifi-strength-1
      "\U000F0922", # mdi-wifi-strength-2
      "\U000F0925", # mdi-wifi-strength-3
      "\U000F0928", # mdi-wifi-strength-4
      "\U000F092B", # mdi-wifi-strength-alert-outline
       
      "\U000F0590", # weather-cloudy
      "\U000F0F2F", # weather-cloudy-alert
      "\U000F0E6E", # weather-cloudy-arrow-right
      "\U000F0591", # weather-fog
      "\U000F0592", # weather-hail
      "\U000F0F30", # weather-hazy
      "\U000F0898", # weather-hurricane
      "\U000F0593", # weather-lightning
      "\U000F067E", # weather-lightning-rainy
      "\U000F0594", # weather-night
      "\U000F0F31", # weather-night-partly-cloudy
      "\U000F0595", # weather-partly-cloudy
      "\U000F0F32", # weather-partly-lightning
      "\U000F0F33", # weather-partly-rainy
      "\U000F0F34", # weather-partly-snowy
      "\U000F0F35", # weather-partly-snowy-rainy
      "\U000F0596", # weather-pouring
      "\U000F0597", # weather-rainy
      "\U000F0598", # weather-snowy
      "\U000F0F36", # weather-snowy-heavy
      "\U000F067F", # weather-snowy-rainy
      "\U000F0599", # weather-sunny
      "\U000F0F37", # weather-sunny-alert
      "\U000F14E4", # weather-sunny-off
      "\U000F059A", # weather-sunset
      "\U000F059B", # weather-sunset-down
      "\U000F059C", # weather-sunset-up
      "\U000F0F38", # weather-tornado
      "\U000F059D", # weather-windy
      "\U000F059E" # weather-windy-variant
      ]
       
  - file: 'fonts/materialdesignicons-webfont.ttf'
    id: materialdesign_icons_50
    size: 80
    glyphs: [
      "\U000F0590", # weather-cloudy
      "\U000F0F2F", # weather-cloudy-alert
      "\U000F0E6E", # weather-cloudy-arrow-right
      "\U000F0591", # weather-fog
      "\U000F0592", # weather-hail
      "\U000F0F30", # weather-hazy
      "\U000F0898", # weather-hurricane
      "\U000F0593", # weather-lightning
      "\U000F067E", # weather-lightning-rainy
      "\U000F0594", # weather-night
      "\U000F0F31", # weather-night-partly-cloudy
      "\U000F0595", # weather-partly-cloudy
      "\U000F0F32", # weather-partly-lightning
      "\U000F0F33", # weather-partly-rainy
      "\U000F0F34", # weather-partly-snowy
      "\U000F0F35", # weather-partly-snowy-rainy
      "\U000F0596", # weather-pouring
      "\U000F0597", # weather-rainy
      "\U000F0598", # weather-snowy
      "\U000F0F36", # weather-snowy-heavy
      "\U000F067F", # weather-snowy-rainy
      "\U000F0599", # weather-sunny
      "\U000F0F37", # weather-sunny-alert
      "\U000F14E4", # weather-sunny-off
      "\U000F059A", # weather-sunset
      "\U000F059B", # weather-sunset-down
      "\U000F059C", # weather-sunset-up
      "\U000F0F38", # weather-tornado
      "\U000F059D", # weather-windy
      "\U000F059E" # weather-windy-variant
    ]
 
 
# --- Display Layout -----------------------------------------------------------
display:
  - platform: waveshare_epaper
    cs_pin: 15
    dc_pin: 27
    busy_pin: 25
    reset_pin: 26
    model: 7.50inv2
    update_interval: 60s
    lambda: |
     int x, y;
      
     // Grid
     it.line(0, 108, 800, 108); // Horizontal header
     it.line(0, 440, 800, 440); // Horizontal footer
     it.line(266, 108, 266, 440); // Vertical first line
     it.line(532, 108, 532, 440); // Vertical second line
      
    
      
     // Temperature inside / outside
     it.printf(100, 35, id(materialdesign_icons_25), TextAlign::BASELINE_LEFT, "\U000F0F54"); 
     //it.printf(130, 40, id(openSansBold_font), TextAlign::BOTTOM_LEFT, "%s °C", id(tim_zimmer_temp).state.c_str()); // use your own temp sensor
      
     it.printf(100, 65, id(materialdesign_icons_25), TextAlign::BASELINE_LEFT, "\U000F0F55"); 
     //it.printf(130, 70, id(openSansBold_font), TextAlign::BOTTOM_LEFT, "%s °C", id(tim_zimmer_hum).state.c_str());// use your own temp sensor
      
     //Time
     it.strftime(540, 100, id(watch_font),TextAlign::BOTTOM_LEFT, "%H:%M", id(time_homeassistant).now());
     it.strftime(540, 110, id(openSansBold_font),TextAlign::BOTTOM_LEFT, "%A, %d.%m.%y, KW %W", id(time_homeassistant).now());
       
     // Current weather 
     // https://www.home-assistant.io/integrations/weather/
     // weahtericon;temperature;humidity,pressure;wind_speed
     // ex. data:   cloudy;5,9;50;1025,6;16,9
 
     std::map <std::string, std::string> weatherMap =  {
      std::make_pair("exceptional","\U000F0F2F"),
      std::make_pair("cloudy","\U000F0590"),
      std::make_pair("cloudy-alert","\U000F0F2F"),
      std::make_pair("fog","\U000F0591"),
      std::make_pair( "hail","\U000F0592"),
      std::make_pair( "hazy","\U000F0F30"),
      std::make_pair( "hurricane","\U000F0898"),
      std::make_pair( "lightning","\U000F0593"),
      std::make_pair( "lightning-rainy","\U000F067E"),
      std::make_pair( "night","\U000F0594"),
      std::make_pair( "clear-night","\U000F0594"),
      std::make_pair( "night-partly-cloudy","\U000F0F31"),
      std::make_pair( "partly-cloudy","\U000F0595"),
      std::make_pair( "partlycloudy","\U000F0595"),
      std::make_pair( "partly-lightning","\U000F0F32"),
      std::make_pair( "partly-rainy","\U000F0F33"),
      std::make_pair( "partly-snowy","\U000F0F34"),
      std::make_pair( "partly-snowy-rainy","\U000F0F35"),
      std::make_pair( "pouring","\U000F0596"),
      std::make_pair( "rainy","\U000F0597"),
      std::make_pair( "snowy","\U000F0598"),
      std::make_pair( "snowy-heavy","\U000F0F36"),
      std::make_pair( "snowy-rainy","\U000F067F"),
      std::make_pair( "sunny","\U000F0599"),
      std::make_pair( "sunny-alert","\U000F0F37"),
      std::make_pair( "sunny-off","\U000F14E4"),
      std::make_pair( "tornado","\U000F0F38"),
      std::make_pair( "windy","\U000F059D"),
      std::make_pair( "windy-variant","\U000F059E")};
       
    
     // -- Footer ---
     //IP Adress
     if (id(ip_address).has_state()) {
         it.printf(5, 470, id(openSansBold_font), TextAlign::BASELINE_LEFT, "IP: %s", id(ip_address).state.c_str());
     }
       
     // WiFi Signal Strength
     if(id(wifisignal).has_state()) {
       x = 210, y = 475;
       if (id(wifisignal).state >= -50) {
           it.print(x, y, id(materialdesign_icons_32), TextAlign::BOTTOM_RIGHT, "\U000F0928");
           ESP_LOGI("WiFi", "Exellent");
       } else if (id(wifisignal).state  >= -60) {
           it.print(x, y, id(materialdesign_icons_32), TextAlign::BOTTOM_RIGHT, "\U000F0925");
           ESP_LOGI("WiFi", "Good");
       } else if (id(wifisignal).state  >= -67) {
           it.print(x, y, id(materialdesign_icons_32), TextAlign::BOTTOM_RIGHT, "\U000F0922");
           ESP_LOGI("WiFi", "Fair");
       } else if (id(wifisignal).state  >= -70) {
           it.print(x, y, id(materialdesign_icons_32), TextAlign::BOTTOM_RIGHT, "\U000F091F");
           ESP_LOGI("WiFi", "Weak");
       } else {
           it.print(x, y, id(materialdesign_icons_32), TextAlign::BOTTOM_RIGHT, "\U000F092B");
           ESP_LOGI("WiFi", "Unlikely");
       }
     }
      
     // ESP Home UpTime
     if (id(uptime_human).has_state()) {
         it.printf(520, 470, id(openSansBold_font), TextAlign::BASELINE_LEFT, "UpTime: %s", id(uptime_human).state.c_str());
     }
      
      
      
     
 
# --- Sensors ------------------------------------------------------------------
sensor:
 
    # ESP Home UpTime
  - platform: uptime
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + ":" : "000:") +
                (hours ? String(hours) + ":" : "00:") +
                (minutes ? String(minutes) + ":" : "00:") +
                (String(seconds) + "")
              ).c_str();  
  - platform: wifi_signal
    id: wifisignal
    update_interval: 60s

  - platform: homeassistant
    id: tim_zimmer_temp
    entity_id: sensor.esphome_web_ebe170_tim_zimmer_temperatur
    internal: true

  - platform: homeassistant
    id: tim_zimmer_hum
    entity_id: sensor.esphome_web_ebe170_tim_zimmer_luftfeuchte
    internal: true


  - platform: homeassistant
    id: sollar_power
    entity_id: sensor.shellyplus1pm_4855199bbb3c_switch_0_power
    internal: true

  - platform: homeassistant
    id: gesammtverbrauch
    entity_id: sensor.gesamtverbrauch
    internal: true
 
text_sensor:
  # ESP WLAN IP Address
  - platform: wifi_info
    ip_address:
      name: "${name} IP Address"
      id: ip_address
  # ESP Home UpTime
  - platform: template
    id: uptime_human
    icon: mdi:clock-start


time:
  - platform: homeassistant
    id: time_homeassistant