---
substitutions:
  devicename: "nodemcu-07"
  id_name: nodemcu_07
  Device_Location: Alarm System
  update_interval: !secret d1-update_interval
  ipaddress: 10.0.0.17
  unique_id: "nodemcu-07"
  sensor_off_interval: !secret sensor_off_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/nodemcu-led-onboard-both-mqtt.yaml

<<: !include common/time-sntp.yaml

<<: !include common/website.yaml

<<: !include common/wifi1.yaml

<<: !include common/uptime_formatted.yaml

esphome:
  name: "nodemcu-07"
  friendly_name: "NodeMCU-07 - Alarm"

switch:

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

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

  - <<: !include common/restart.yaml

  - platform: template
    name: "00 - Led Shuffle"
    optimistic: True
    id: redtemp
    turn_on_action:
      - while:
          condition:
            lambda: 'return true;'
          then:
            - switch.turn_on: led_onboard1
            - switch.turn_off: led_onboard2
            - delay: 500ms
            - switch.turn_off: led_onboard1
            - switch.turn_on: led_onboard2
            - delay: 500ms
    turn_off_action:
      - switch.turn_off: led_onboard1
      - switch.turn_off: led_onboard2
    retain: False

interval:

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

  - <<: !include common/whatami.yaml

sensor:

  - <<: !include common/wifi2.yaml

  - <<: !include common/uptime.yaml

  - <<: !include common/free_space.yaml

text_sensor:

  - <<: !include common/version.yaml

binary_sensor:

  - platform: gpio
    on_press:
      then:
        - mqtt.publish:
            topic: /sensors/nodemcu-07/alarm/bedroom
            payload: "ON"
            retain: False
    pin:
      number: D1
      mode: INPUT_PULLUP
    name: "1 - Bedroom"
    filters:
      - delayed_on: 10ms
      - delayed_off: $sensor_off_interval

  - platform: gpio
    on_press:
      then:
        - mqtt.publish:
            topic: /sensors/nodemcu-07/alarm/study
            payload: "ON"
            retain: False
    pin:
      number: D7
      mode: INPUT_PULLUP
    name: "2 - Study"
    filters:
      - delayed_on: 10ms
      - delayed_off: $sensor_off_interval

  - platform: gpio
    on_press:
      then:
        - mqtt.publish:
            topic: /sensors/nodemcu-07/alarm/garage
            payload: "ON"
            retain: False
    pin:
      number: D2
      mode: INPUT_PULLUP
    name: "3 - Garage"
    filters:
      - delayed_on: 10ms
      - delayed_off: $sensor_off_interval

  - platform: gpio
    on_press:
      then:
        - mqtt.publish:
            topic: /sensors/nodemcu-07/alarm/lounge
            payload: "ON"
            retain: False
    pin:
      number: D5
      mode: INPUT_PULLUP
    name: "4 - Lounge"
    filters:
      - delayed_on: 10ms
      - delayed_off: $sensor_off_interval

  - platform: gpio
    on_press:
      then:
        - mqtt.publish:
            topic: /sensors/nodemcu-07/alarm/family
            payload: "ON"
            retain: False
    pin:
      number: D6
      mode: INPUT_PULLUP
    name: "5 - Family"
    filters:
      - delayed_on: 10ms
      - delayed_off: $sensor_off_interval

http_request:
  id: http_request_data
  useragent: esphome/device
  timeout: 10s
  verify_ssl: False

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