esphome:
  name: $devicename
  comment: $comment
  project:
    name: "growsmart.${devicename}"
    version: "0.1"
  on_boot:
    priority: -100
    then:
      - lambda: |-
          id(sntp_time).update();

substitutions:
  domain: !secret domain
  timezone: !secret timezone
  fan_script: "dummy"
  humidifier_script: "dummy"

preferences:
  flash_write_interval: 15s

logger:
  # level: INFO

api:
  password: !secret api_password
  reboot_timeout: 0s

ota:
  platform: esphome
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on
  reboot_timeout: 1min
  domain: .${domain}
  use_address: ${devicename}.${domain}

web_server:
  port: 80
  local: true
  # include_internal: true

prometheus:
  include_internal: true
  relabel:
    rssi:
      id: rssi
      name: RSSI
    device_uptime:
      id: uptime
      name: Uptime

debug:
  update_interval: 5s

sensor:
  - platform: wifi_signal
    id: rssi
    name: "Wifi Signal"
    update_interval: 60s

  - platform: uptime
    id: device_uptime_seconds
    update_interval: 15s
    internal: true

  # - platform: debug
  #   free:
  #     name: "Device: Heap Free"
  #   block:
  #     name: "Device: Heap Max Block"
  #   loop_time:
  #     name: "Device: Loop Time"
  #   psram:
  #     name: "Device: Free PSRAM"

text_sensor:
  - platform: version
    name: "ESPHome Version"
    hide_timestamp: true

  - platform: debug
    #device:
    #  name: "Device: Info"
    reset_reason:
      name: "Device: Reset Reason"

  - platform: template
    id: device_uptime
    name: "Device: Uptime"
    update_interval: 15s
    lambda: |-
      uint32_t dur = id(device_uptime_seconds).state;
      int dys = 0;
      int hrs = 0;
      int mnts = 0;
      if (dur > 86399) {
        dys = trunc(dur / 86400);
        dur = dur - (dys * 86400);
      }
      if (dur > 3599) {
        hrs = trunc(dur / 3600);
        dur = dur - (hrs * 3600);
      }
      if (dur > 59) {
        mnts = trunc(dur / 60);
        dur = dur - (mnts * 60);
      }
      char buffer[38];
      sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
      return {buffer};

button:
  - platform: restart
    id: device_reset
    name: "Device: Reset"

http_request:
  id: http_request_data
  useragent: esphome/${devicename}
  verify_ssl: false
  timeout: 1s

script:
  - id: dummy
    then:
      - lambda: |-
          return;
