esphome: 
  name: "tr-air-quality"
  platform: ESP32
  board: featheresp32

logger:
  level: DEBUG
  logs:
    sensor: INFO
    pmsx003: INFO

wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password  
  on_connect:
    then:
      - lambda: |-
          id(wifi_status).publish_state("Connected");
  on_disconnect:
    then:
      - lambda: |-
          id(wifi_status).publish_state("Disconnected");

ota:
  platform: esphome
  password: !secret ota_password_1

mqtt:
  id: mqtt_client
  broker: 'mqtt2.bigasterisk.com'
                                               
# light:
#   - platform: status_led
#     id: "status_out"
#     pin: 2

    # pms pin 1 to 5V
    # pms pin 2 to gnd
    # pms pin 3 NC
# original setup
# GPIO13/RXD2 num 16 = pms tx (pin 5)
# GPIO15/TXD2 num 17 = pms rx (pin 4)
# or on T-Display ESP32, 
#   pms tx pin 5 to esp 13
#   pms rx pin 4 tp esp 12
uart:
  rx_pin: 13
  baud_rate: 9600

sensor:
  - platform: pmsx003
    type: PMS5003T
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
    temperature:
      name: "air temperature C"



spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

font:
  - file: 'fonts/DejaVuSerif.ttf'
    id: font_14
    size: 14
    glyphs: "!%()+,-/_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"
 

color:
  - id: color_red
    red: 1
    green: 0
    blue: 0
  - id: color_green
    red: 0
    green: 1
    blue: 0
  - id: color_blue
    red: 0
    green: 0
    blue: 1
  - id: color_gray
    red: 0.2
    green: 0.2
    blue: 0.2
  - id: color_teal_blue
    red: 0
    green: 0.5
    blue: 0.45

switch:
  - platform: gpio
    pin: GPIO4
    name: "Backlight"
    id: backlight              
    restore_mode: ALWAYS_ON

display:
  - platform: ili9xxx
    model: ST7789V
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
    rotation: 90°
    update_interval: 5s
    lambda: |-
      auto bg = Color(30, 0, 0);
      auto wifi_status2 = id(wifi_status).state;
      # it.fill(bg);
      it.print(0, 0, id(font_14), Color(255,0,0), "WiFi Status:");
      it.print(0, 20, id(font_14), Color(255,0,0), wifi_status2.c_str());

text_sensor:
  - platform: template
    name: "WiFi Status"
    id: wifi_status
    update_interval: 1s