# https://hackaday.io/project/192719-calling-for-hot-water

substitutions:
  node_name: hotbuttonrelay
  RELAY:  'D1'
  SCL:    'D5'
  SDA:    'D2'
  LED:    'D4'
  BUTTON: 'D7'
  log_level: 'DEBUG'

esphome:
  name: ${node_name}
  platform: ESP8266
  board: d1_mini

wifi:
  ssid:      !secret wifi_ssid
  id:        !secret wifi_ssid
  password:  !secret wifi_password
  power_save_mode: high
  fast_connect: on
  manual_ip:
    static_ip: !secret hotbuttonrelay_ip
    gateway:   !secret wifi_gateway
    subnet:    !secret wifi_subnet
    dns1:      !secret wifi_dns1
    dns2:      !secret wifi_dns2

logger:
   level: ${log_level}
api:
  encryption:
    key: !secret hotbuttonrelay_apikey
  reboot_timeout: 60min
ota:
  password: !secret ota_password

switch:
  - platform: restart
    name: "${node_name} Reboot"

  - platform: gpio
    id: i_relay
    name: '${node_name} relay'
    pin: '${RELAY}'
    restore_mode: ALWAYS_OFF
    icon: mdi:hot-tub
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: i_relay

  - platform: gpio
    id: i_led
    name: '${node_name} LED'
    pin: '${LED}'
    inverted: true
    restore_mode: ALWAYS_OFF
    icon: mdi:led-on

# Local test button. This goes through the relay logic, so it's not an analog press of the water heater button.
binary_sensor:
  - platform: gpio
    name: "${node_name} Button"
    id: i_button
    pin:
      number: '${BUTTON}'
      inverted: true
      mode:
        input: true
        pullup: true
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms

i2c:
  sda: ${SDA}
  scl: ${SCL}
  scan: false
  id: i_i2c

sensor:
  - platform: bme280
    id: i_bme280
    address: 0x76
    update_interval: 60s
    temperature:
      name: "${node_name} Temp"
      device_class: "temperature"
      oversampling: 16x
    pressure:
      name: "${node_name} AirPr"
      device_class: "pressure"
      oversampling: 16x
    humidity:
      name: "${node_name} RHumidity"
      device_class: "humidity"
      oversampling: 16x


# From the Arduino board definitions file
# #define PIN_WIRE_SDA (4)
# #define PIN_WIRE_SCL (5)

# static const uint8_t SDA = PIN_WIRE_SDA;
# static const uint8_t SCL = PIN_WIRE_SCL;

# #define LED_BUILTIN 2

# static const uint8_t D0   = 16;
# static const uint8_t D1   = 5;
# static const uint8_t D2   = 4;
# static const uint8_t D3   = 0;
# static const uint8_t D4   = 2;
# static const uint8_t D5   = 14;
# static const uint8_t D6   = 12;
# static const uint8_t D7   = 13;
# static const uint8_t D8   = 15;
# static const uint8_t RX   = 3;
# static const uint8_t TX   = 1;

