# ----------------------------------------------------------------
# This file configures a D1 mini for displaying the next waste
# container for collection.
# 
# This is done by defining a strip of WS2811 LEDs as light and
# setting the color through an automation in HomeAssistant.
# The switch in the lid can be used as acknowledge that the
# wastebin has been placed for collection.
# 
# D1 wiring:
# 5V power for LED strip
#  G ground for LED strio
# D4 (GPIO2) data signal for LED strip
# D2 (GPIO4) internal status LED and power for lid switch,
#            allowing for the disabling of the switch
# D3 (GPIO0) lid switch input
# 
# !secret variables are defined in secrets.yaml file
# ----------------------------------------------------------------

# ----------------------------------------------------------------
# Substitutions
# ----------------------------------------------------------------

# The name of the node
# This is used in all sensor definitions.
substitutions:
  name: esp-5a098d

# ----------------------------------------------------------------
# Module configuration
# ----------------------------------------------------------------

# Configure generic module settings
esphome:
  comment: "Terrain wastebin notifier"
  name: ${name}

esp8266:
  board: d1_mini

# Enable Home Assistant API# Configure minimal logging
logger:
  level: WARN

api:
  encryption:
    key: !secret API_KEY

ota:
  - platform: esphome
    password: !secret OTA_KEY

# Configure Network settings
wifi:
  ssid: !secret WIFI_SSID
  password: !secret WIFI_KEY
  domain: !secret WIFI_DOMAIN
  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: !secret FALLBACK_AP_SSID
    password: !secret FALLBACK_AP_KEY

captive_portal:

# ----------------------------------------------------------------
# I/O configuration
# ----------------------------------------------------------------

# Binary sensors ("status" is always available)
binary_sensor:
  - platform: status
    name: ${name}_status
  - platform: gpio
    pin: 
      number: GPIO0
      inverted: true
    name: ${name}_lidswitch
    filters:
      - delayed_off: 10ms
    on_press:
      then:
      - light.turn_off: lid

# Sensors ("uptime" is always available)
sensor:
  - platform: uptime
    name: ${name}_uptime
    update_interval: 3600s

# Switches ("restart" is always available)
switch:
  - platform: restart
    name: ${name}_restart
  - platform: gpio
    pin: GPIO2
    name: ${name}_lidswitch_disable
    restore_mode: ALWAYS_OFF
    
# Lights
light:
  - platform: neopixelbus
    variant: WS2812
    type: GRB
    pin: GPIO4
    num_leds: 5
    id: lid
    name: ${name}_lid
