substitutions:
  devicename: bauhn-01
  Device_Location: bauhn-01
  update_interval: !secret d1-update_interval
  ipaddress: 10.0.0.161

esphome:
  name: $devicename
  friendly_name: bauhn-01

esp8266:
  board: esp01_1m

# Enable logging
logger:
  level: WARN

wifi:
  ssid: !secret mogwai_wifi_name
  password: !secret mogwai_wifi_password
  <<: !include common/network.yaml

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "$devicename Fallback Hotspot"
    password: !secret mogwai_ap_key

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

ota:
  platform: esphome
  password: !secret mogwai_ota_key

captive_portal:

<<: !include common/bauhn-mqtt.yaml

<<: !include common/time.yaml

<<: !include common/website.yaml

<<: !include common/wifi1.yaml

<<: !include common/uptime_formatted.yaml

sensor:

  - <<: !include common/wifi2.yaml

  - <<: !include common/uptime.yaml

text_sensor:

  - <<: !include common/version.yaml

binary_sensor:

  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLUP
      inverted: true
    name: "power_button"
    on_press:
      - switch.toggle: relay1
      - switch.toggle: relay2
    retain: false

  - platform: status
    name: "status"
    retain: false

switch:

  - platform: gpio
    id: blue_led
    name: "blue_led"
    pin:
      number: GPIO13
      inverted: true
    retain: false

  - platform: gpio
    name: "relay1"
    pin: GPIO4
    id: relay1
    retain: false

    on_turn_on:
      - switch.turn_on: blue_led

    on_turn_off:
      - switch.turn_off: blue_led 

  - platform: gpio
    name: "relay2"
    pin: GPIO5
    id: relay2
    retain: false

    on_turn_on:
      - switch.turn_on: blue_led

    on_turn_off:
      - switch.turn_off: blue_led 

interval:

  - <<: !include common/version-interval.yaml