esphome:
  name: beer-light
  friendly_name: Beer Light

esp8266:
  board: nodemcu

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret beerlight_api_encryption_key

ota:
  - platform: esphome
    password: !secret beerlight_ota_pw

wifi:
  ssid: !secret iot_wifi_ssid
  password: !secret iot_wifi_psk

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Beer-Light Fallback Hotspot"
    password: !secret beerlight_fallback_ap_pw

captive_portal:

text_sensor:
  - platform: version
    name: "Beer Light ESPHome Version"

output:
  - platform: gpio
    pin: D0
    id: gpio_d0
  - platform: gpio
    pin: D1
    id: gpio_d1
  - platform: gpio
    pin: D2
    id: gpio_d2
  - platform: gpio
    pin: D3
    id: gpio_d3

light:
  - platform: binary
    name: "Beer LED 1"
    id: beer_led1
    output: gpio_d0
  - platform: binary
    name: "Beer LED 2"
    id: beer_led2
    output: gpio_d1
  - platform: binary
    name: "Beer LED 3"
    id: beer_led3
    output: gpio_d3
  - platform: binary
    name: "Beer LED 4"
    id: beer_led4
    output: gpio_d2

switch:
  - platform: template
    name: "Carousel"
    optimistic: yes
    id: carousel
    turn_on_action:
      - while:
          condition:
            lambda: 'return true;'
          then:
            - light.turn_on: beer_led1
            - delay: 50ms
            - light.turn_off: beer_led1
            - light.turn_on: beer_led2
            - delay: 50ms
            - light.turn_off: beer_led2
            - light.turn_on: beer_led3
            - delay: 50ms
            - light.turn_off: beer_led3
            - light.turn_on: beer_led4
            - delay: 50ms
            - light.turn_off: beer_led4
    turn_off_action:
      - light.turn_off: beer_led1
      - light.turn_off: beer_led2
      - light.turn_off: beer_led3
      - light.turn_off: beer_led4