#  _____               _   _____               _____         _         _
# |   __|_____ ___ ___| |_|  |  |___ _____ ___|   __|___ ___| |_ ___  |_|___
# |__   |     | .'|  _|  _|     | . |     | -_|  |  | -_| -_| '_|_ -|_| | . |
# |_____|_|_|_|__,|_| |_| |__|__|___|_|_|_|___|_____|___|___|_,_|___|_|_|___|
#
# https://www.smarthomegeeks.io/smart-awning/

substitutions:
  device_name: "Awning"
  friendly_name: "Awning"
  travel_time: 31.7s
  open_pin: GPIO0
  stop_pin: GPIO4
  close_pin: GPIO5
  button_delay: 200ms

esphome:
  name: awning
  friendly_name: ${friendly_name}
  project:
    name: "smarthomegeeks.${friendly_name}"
    version: "2026.02"  
  on_boot:
    priority: -100
    then:
      - delay: 2s
      - switch.turn_on: sw_close
      - delay: ${button_delay}
      - switch.turn_off: sw_close  

esp8266:
  board: esp01_1m
  restore_from_flash: true

logger:

api:
  encryption:
    key: !secret api_encryption_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  min_auth_mode: WPA2
  ap:
    ssid: "${friendly_name} Fallback"
    password: !secret ap_password
    
captive_portal:

sensor:
  - platform: wifi_signal
    name: "${friendly_name} Wifi RSSI"
    update_interval: 60s

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${friendly_name} IP"

switch:
  - platform: gpio
    id: sw_open
    pin:
      number: ${open_pin}
      inverted: true
    restore_mode: ALWAYS_OFF

  - platform: gpio
    id: sw_close
    pin:
      number: ${close_pin}
      inverted: true
    restore_mode: ALWAYS_OFF

  - platform: gpio
    id: sw_stop
    pin:
      number: ${stop_pin}
      inverted: true
    restore_mode: ALWAYS_OFF

cover:
  - platform: time_based
    id: awning_cover
    name: "${friendly_name}"
    device_class: awning
    has_built_in_endstop: true

    open_action:
      - switch.turn_on: sw_open
      - delay: ${button_delay}
      - switch.turn_off: sw_open

    close_action:
      - switch.turn_on: sw_close
      - delay: ${button_delay}
      - switch.turn_off: sw_close

    stop_action:
      - switch.turn_on: sw_stop
      - delay: ${button_delay}
      - switch.turn_off: sw_stop

    open_duration: ${travel_time}
    close_duration: ${travel_time}