esphome:
  name: oled-tim-mini
  friendly_name: OLED Tim Mini

esp8266:
  board: esp01_1m

# 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: "Esphome-Web-D05329"
    password: "ZqgvIQnFz4Ib"

captive_portal:


globals:
  - id: page
    type: int
    initial_value: "1"


font:
  - file: './fonts/OpenSans-Light.ttf'
    id: font1
    size: 10

  - file: './fonts/OpenSans-Light.ttf'
    id: font2
    size: 22

  - file: './fonts/OpenSans-Light.ttf'
    id: font3
    size: 14

time:
  - platform: homeassistant
    id: esptime
    timezone: Europe/Berlin

sensor:
  - 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

  - platform: homeassistant
    id: P1P_Precent
    entity_id: sensor.p1p_01s00c343000157_druckfortschritt
    internal: true

  - platform: aht10
    variant: AHT10
    temperature:
      name: "Tim Schreibtisch Temperatur"
      id: "tim_schreib_temp"
    humidity:
      name: "Tim Schreibtisch Luftfeuchte"
      id: "tim_schreib_hum"

text_sensor:
  - platform: homeassistant
    id: P1P_Status
    entity_id: sensor.p1p_01s00c343000157_aktueller_arbeitsschritt
    internal: true 


i2c:
  sda: 4 #Lila / D2
  scl: 5 #Grau / D1
  scan: True

display:
  - platform: ssd1306_i2c
    id: "OLED"
    model: "SH1106 128x64"
    address: 0x3C
    pages:
      lambda: |-
        // Print time in HH:MM format
        it.strftime(0, 0, id(font2), TextAlign::TOP_LEFT, "%H:%M", id(esptime).now());

        // Print Gesammtverbrauch (from homeassistant sensor)
        if (id(gesammtverbrauch).has_state()) {
        it.printf(0, 60, id(font3), TextAlign::BASELINE_LEFT , "%.1fW", id(gesammtverbrauch).state);
        }

        // Print inside temperature (from homeassistant sensor)
        if (id(tim_schreib_temp).has_state()) {
        it.printf(126, 0, id(font3), TextAlign::TOP_RIGHT , "%.1f°", id(tim_schreib_temp).state);
        }
    
        // Print Inside Humidity (from homeassistant sensor)
        if (id(tim_schreib_hum).has_state()) {
        it.printf(126, 32, id(font3), TextAlign::CENTER_RIGHT , "%.1f%%", id(tim_schreib_hum).state);
        }

        // Print Solar Power (from homeassistant sensor)
        if (id(sollar_power).has_state()) {
        it.printf(126, 60, id(font3), TextAlign::BASELINE_RIGHT , "%.1fW", id(sollar_power).state);
        }

        // Print Print Progress (from homeassistant sensor)
        if (id(P1P_Status).state == "printing") {
        it.printf(0, 37, id(font3), TextAlign::CENTER_LEFT , "%.f%%", id(P1P_Precent).state);
        }
