---
substitutions:
  devicename: "nodemcu-16"
  id_name: nodemcu_16
  Device_Location: "Spare Temperature"
  update_interval: !secret d1-update_interval
  ipaddress: 10.0.0.26
  unique_id: "nodemcu-16"
  deep_sleep_interval: !secret deep_sleep_interval

logger:
  level: WARN

esp8266:
  board: nodemcuv2

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

api:
  encryption:
    key: !secret mogwai_api_key

ota:
  platform: esphome
  password: !secret mogwai_ota_key

captive_portal:

<<: !include common/time.yaml

<<: !include common/website.yaml

<<: !include common/wifi1.yaml

<<: !include common/uptime_formatted.yaml

esphome:
  name: $devicename
  friendly_name: "NodeMCU-16 - Spare Sensor"

switch:

  - <<: !include common/nodemcu-led-onboard1.yaml

  - <<: !include common/nodemcu-led-onboard2.yaml

  - <<: !include common/nodemcu-led-onboard1-2-shuffle.yaml

  - platform: template
    name: "10 - Traffic Shuffle"
    optimistic: True
    id: ledtraffic
    turn_on_action:
      - while:
          condition:
            lambda: 'return true;'
          then:
            - output.turn_on: red_light
            - delay: 3s
            - output.turn_on: yellow_light
            - output.turn_off: red_light
            - delay: 500ms
            - output.turn_on: green_light
            - switch.turn_on: led_onboard1
            - output.turn_off: yellow_light
            - delay: 5s
            - switch.turn_off: led_onboard1
            - output.turn_on: yellow_light
            - output.turn_off: green_light
            - delay: 500ms
            - output.turn_off: yellow_light
            - delay: 500ms
            - output.turn_on: yellow_light
            - delay: 500ms
            - output.turn_off: yellow_light
    turn_off_action:
      - output.turn_off: green_light
      - output.turn_off: red_light
      - output.turn_off: yellow_light

interval:

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

  - <<: !include common/whatami.yaml

<<: !include common/external-heapmon.yaml

sensor:

  - <<: !include common/wifi2.yaml

  - <<: !include common/uptime.yaml

text_sensor:

  - <<: !include common/version.yaml


# Define the GPIO pins used for each light
output:
  - platform: gpio
    pin: D3
    id: red_light

  - platform: gpio
    pin: D2
    id: yellow_light

  - platform: gpio
    pin: D1
    id: green_light

<<: !include common/nodemcu-led-onboard-both-mqtt.yaml