ESP32C3 (Xiao) : Problem implementing deep sleep

Hi All,

My setup:
I am integrating seeed-studio xiao esp32c3 with door sensor in esphome.
The esp32c3 should wake up whenever there is change in state, else go to sleep.
That is, if door opens, wakeup, report to hassio, sleep. Same goes for door close.

Current Status:

Without deep sleep, I am able to observe the door sensor status is updated successfully based on door open and close.

After implementing deep sleep, the sensor shows unavailable, and is not waking up on door close or open.

Here is my yaml file:

esphome:
  name: door-sensor
  friendly_name: Door_Sensor

esp32:
  board: seeed_xiao_esp32c3
  variant: esp32c3
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "api key"

ota:
  password: "ota password"

wifi:
  ssid: Potato
  password: Password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Door-Sensor Fallback Hotspot"
    password: "dnKbTZUUHNwj"

captive_portal:

# Define your door sensor pin and setup
binary_sensor:
  - platform: gpio
    name: "Main Door"
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
      allow_other_uses: true
    device_class: door

# Configure deep sleep
deep_sleep:
  id: deep_sleep_1
  run_duration: 5s  # Adjust as needed
  wakeup_pin: 
    number: GPIO2  # Replace with the actual GPIO pin where your door sensor is connected
    allow_other_uses: true
  wakeup_pin_mode: IGNORE

What I wish I could get?

1st: To make the deep sleep work, so that I can run it over battery for months,

2nd: If I am able to make the 1st work out, I would like to have my door sensor show the last state of the door rather than showing unavailable.

Any inputs or suggestions will be really helpful.

Thanks & Regards,
A noob in hassio

1 Like

You could try extending run duration to say 20sec and adding an uptime sensor just to make its not waking and sleeping before it connects to the api etc?

I will make those changes and update you, could not get access of my hardware.

esphome:
  name: door-sensor
  friendly_name: Door_Sensor

esp32:
  board: seeed_xiao_esp32c3
  variant: esp32c3
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "pass"

ota:
  password: "pass"

wifi:
  ssid: Potato
  password: pass

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Door-Sensor Fallback Hotspot"
    password: "pass"

mqtt:
  broker: '192.168.29.159'
  username: 'mqtt-user'
  password: 'pass'

captive_portal:

# Define your door sensor pin and setup
binary_sensor:
  - platform: gpio
    name: "Home Door"
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      allow_other_uses: true
    device_class: door
    on_press:
      then:
        - mqtt.publish:
            topic: "home/door-sensor/home-door"
            payload: "OPEN"
    on_release:
      then:
        - mqtt.publish:
            topic: "home/door-sensor/home-door"
            payload: "CLOSED"

#Configure deep sleep
deep_sleep:
  id: deep_sleep_1
  run_duration: 30s  # Adjust as needed
  wakeup_pin: 
    number: GPIO3  # Replace with the actual GPIO pin where your door sensor is connected
    allow_other_uses: true
  wakeup_pin_mode: IGNORE

The door sensor, still shows unavailable, any help? (I made the change to 30 s).

I implemented MQTT this time (so that if this does not work , I can go on for independent code for ESP32, rather than using ESPHome).

In esphome logs, I could see it entered the deep sleep and serial port closed.

God help me with this simple thing.