# ----------------------------------------------------------------
# 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
# HomeAssistant API is disabled by default. You can enable this 
# if you prefer this over MQTT.
# 
# ----------------------------------------------------------------

# ----------------------------------------------------------------
# Module configuration
# ----------------------------------------------------------------
# Configure generic module settings
esphome:
  #name: esp_5a098d
  name: wastebin_notifier
  platform: ESP8266
  board: d1_mini

# 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

# Enable captive portal in case wifi connection fails
captive_portal:

# Configure minimal logging
logger:
  level: WARN
    
# Configure Over-the-Air updates
ota:
  password: !secret OTA_KEY

## Configure Home Assistant API
#api:

# Configure MQTT
mqtt:
  broker: !secret MQTT_BROKER
  topic_prefix: "test/waste/notifier"

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

# Binary sensors ("status" is always available)
binary_sensor:
  - platform: status
    name: wastebin_status
  - platform: gpio
    pin: 
      number: GPIO0
      inverted: true
    name: wastebin_lidswitch
    filters:
        # debounce delay
      - delayed_off: 10ms

# Sensors ("uptime" is always available)
sensor:
  - platform: uptime
    name: wastebin_uptime
    update_interval: 3600s

# Switches ("restart" is always available)
switch:
  - platform: restart
    name: wastebin_restart
  - platform: gpio
    pin: GPIO2
    name: wastebin_lidswitch_disable
    restore_mode: ALWAYS_OFF

# Lights
light:
  - platform: fastled_clockless
    chipset: WS2812
    rgb_order: GRB
    pin: GPIO4
    num_leds: 5
    name: wastebin_lid