esphome:
  name: bedroom_tkm1
  platform: ESP32
  board: wemos_d1_mini32 #esp-wrover-kit
  on_boot:
    - priority: 900 #900 tried down to 500
      then:
        - lambda: |-
            id(wake_up_reason) = esp_sleep_get_ext1_wakeup_status();
  
  #   - priority: 901 #900 tried down to 500
  #     then:
  #       - lambda: |-
  #               esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  #               gpio_pullup_dis(GPIO_NUM_33);
  #               gpio_pulldown_en(GPIO_NUM_33);
  #               gpio_pullup_dis(GPIO_NUM_34);
  #               gpio_pulldown_en(GPIO_NUM_34);
  #               gpio_pullup_dis(GPIO_NUM_35);
  #               gpio_pulldown_en(GPIO_NUM_35);

wifi:
  ssid: "Meneely"
  password: "punxsutawney1"
  manual_ip:
    static_ip: 192.168.87.36
    gateway: 192.168.86.1
    subnet: 255.255.254.0
  fast_connect: True

# captive_portal:

logger:
    level: INFO
api:
ota:

mqtt:
  broker: 192.168.86.99
  discovery: True
  username: ha
  password: lorrie
  # keepalive: 2s
  birth_message:
          topic: bedroom_tkm1/status
          payload: coming_online_birth
  will_message:
          topic: bedroom_tkm1/status
          payload: going_offline_will
  on_message:
    topic: bedroom_tkm1/ota_mode
    payload: 'ON'
    then:
      - deep_sleep.prevent: deep_sleep_1

deep_sleep:
        run_duration: 20s
        sleep_duration: 40s #24h
        esp32_ext1_wakeup: 
                pins: 
                  - 33 #yellow
                  - 34 #orange
                  - 35 #white
                mode: ANY_HIGH
        id: deep_sleep_1

globals:
        - id: wake_up_reason
          type: int
          restore_value: no
          initial_value: '0'
sensor:
  - platform: template
    name: "Remote Control Wake Reason"
    accuracy_decimals: 0
    lambda: |-
            return id(wake_up_reason);

binary_sensor:
  - platform: gpio
    pin: 
        number: GPIO33
        mode: INPUT_PULLUP
    # filters:
      # - delayed_on: 10ms ### <---- debounce time, was 100ms
      # - delayed_off: 10s ### <---- delay to capture state change on wake up         
    name: "TKM Test 33 (yellow)"
    id: tkm_test_33
  - platform: gpio
    pin: 
        number: GPIO34
        mode: INPUT_PULLUP
    name: "TKM Test 34 (orange)"
    id: tkm_test_34
  - platform: gpio
    pin: 
        number: GPIO35
        mode: INPUT_PULLUP
    name: "TKM Test 35 (white)"
    id: tkm_test_35
