---
substitutions:
  device: m5paper
  name: M5Paper
  area: DEV
  comment: "${area} | M5Paper"

esphome:
  name: mcu-${device}
  friendly_name: ${name}
  area: ${area}
  comment: ${comment}

esp32:
  variant: esp32
  framework:
    type: esp-idf

psram:

external_components:
  - source: github://Passific/m5paper_esphome

packages:
  common: !include common/common.yaml

time:
  - platform: homeassistant
    id: ha_time
    timezone: Europe/Bratislava
    on_time_sync:
      - bm8563.write_time
  - platform: bm8563
    id: rtc_time
    sleep_duration: 3600000ms

m5paper:
  battery_power_pin: GPIO5
  main_power_pin: GPIO2
  # update_interval: 10s
  # battery_voltage:
  #   name: "${name} Battery"

# 0x44 SHT30
# 0x50
# 0x51
# 0x5D GT911

i2c:
  - id: i2c_main
    sda: 21
    scl: 22
    scan: true #false
  # - id: i2c_a
  #   sda: 25
  #   scl: 32
  #   scan: true #false
  # - id: i2c_b
  #   sda: 26
  #   scl: 33
  #   scan: true #false
  # - id: i2c_c
  #   sda: 18
  #   scl: 19
  #   scan: true #false

spi:
  clk_pin: 14
  miso_pin: 13
  mosi_pin: 12

binary_sensor:
  - platform: gpio
    name: ${name} Button UP
    id: button_up
    pin:
      number: 37
      inverted: true
    on_press:
      - component.update: m5paper_display
    on_release:
      - component.update: m5paper_display
  - platform: gpio
    name: ${name} Button Press
    id: button_press
    pin:
      number: 38
      inverted: true
  - platform: gpio
    name: ${name} Button Down
    id: button_down
    pin:
      number: 39
      inverted: true
  - platform: touchscreen
    name: ${name} Top Left Touch Button
    id: top_left_touch_button
    touchscreen_id: gt911_touchscreen
    internal: true
    x_min: 0
    x_max: 100
    y_min: 0
    y_max: 100
    on_press:
      # Example of applying the sleep duration and shutting down to the lowest power mode
      - bm8563.apply_sleep_duration
      - delay: 1s
      - m5paper.shutdown_main_power

font:
  - file: "gfonts://Roboto"
    id: font_default
    size: 20
  - file: "gfonts://Roboto"
    id: roboto_32
    size: 32
  - file: "gfonts://Roboto"
    id: roboto_24
    size: 24
  - file: "gfonts://Roboto"
    id: roboto_12
    size: 12

display:
  - platform: it8951e
    id: m5paper_display
    cs_pin: GPIO15
    reset_pin: GPIO23
    busy_pin: GPIO27
    rotation: 90
    reversed: False
    update_interval: "never"
    lambda: |-
      it.printf(25, 25, id(roboto_32), "%.1f°", id(current_temperature).state);
      it.strftime(350, 25, id(roboto_32), "%H:%M:%S", id(rtc_time).now());

touchscreen:
  - platform: gt911
    display: m5paper_display
    id: gt911_touchscreen
    interrupt_pin: GPIO36

# display:
#   - platform: waveshare_epaper
#     cs_pin: 15
#     model: 2.90in
#     full_update_every: 30
#     lambda: |-
#       it.print(0, 0, id(font1), "Hello World!");

sensor:
  - platform: sht3xd
    temperature:
      name: Temperature
      id: current_temperature
    humidity:
      name: Humidity
    address: 0x44
    update_interval: 60s

# touchscreen:
#   - platform: gt911
#     interrupt_pin: 36
