Reed Door Sensor (battery powered ESP32 with esphome(yaml))

hey there!

tinkered a bit with the config and added an “OTA Mode”. When switched on the esp won’t enter deep sleep.

Thanks to @scote for sharing his setup in this post. Just added a template switch for the ui package (see below).

esphome config (click to expand):
substitutions:
  devicename: esp32_1


esphome:
  name: $devicename
  platform: ESP32
  board: lolin32


wifi:
  ssid: !secret ssid_iot
  password: !secret password_iot
  fast_connect: true
  manual_ip:
    static_ip: 192.168.0.110
    gateway: 192.168.0.1
    subnet: 255.255.255.0

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_user
  password: !secret mqtt_pasword
  discovery: False
  discovery_retain: False
  birth_message:
    topic: $devicename/status
    payload: online
  will_message:
    topic: $devicename/status
    payload: offline
  on_message:
    - topic: $devicename/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: deep_sleep_1
        - mqtt.publish:
            topic: $devicename/ota_mode_status
            payload: "active"
    - topic: $devicename/sleep_mode
      payload: 'ON'
      then:
        - mqtt.publish:
            topic: $devicename/ota_mode_status
            payload: "disabled"
        - deep_sleep.enter: deep_sleep_1


logger:
  level: WARN

ota:
  password: !secret ota_password

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${devicename}_ip

deep_sleep:
  id: deep_sleep_1
  run_duration: 30s
  sleep_duration: 720min
  wakeup_pin: 14
  wakeup_pin_mode: INVERT_WAKEUP

switch:
  - platform: shutdown
    name: "${devicename}_shutdown"
    id: shutdown1
  - platform: restart
    name: "${devicename}_restart"

binary_sensor:
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLDOWN
      inverted: True
    name: "door"
    device_class: door




sensor:
#wifi signal
  - platform: wifi_signal
    name: ${devicename}_rssi
  - platform: adc
    pin: 34
    attenuation: 11db
    filters:
    name: "${devicename}_voltage"

Basically this template switch will send/remove a retained message to the MQTT Broker

  - platform: template
    switches:
      esp32_01_switch_ota:
        value_template: "{{ is_state('binary_sensor.esp32_01_ota_status', 'on') }}"
        turn_on:
          - service: mqtt.publish
            data:
              topic: "esp32_1/ota_mode"
              payload: "ON"
              retain: true
        turn_off:
          - service: mqtt.publish
            data:
              topic: "esp32_1/sleep_mode"
              payload: "ON"
          - service: mqtt.publish
            data:
              topic: "esp32_1/ota_mode"
              payload: ""
              retain: true

Full Package with switch and notification automation is here:
esp32_1_doorsensor_elw.yaml

Comments highly appreciated!