XIAO ESP32-C3 Deepsleep and wakeup pins

Hi Arno, a while ago I wrote some notes on using deep-sleep after getting it working with my ESP32-S3 based greenhouse. A series of posts as my knowledge developed.

I use the ESP32-S3 which has dual processors - if the ESP32-C3 doesn’t have the secondary processor you may find it needs more work to get it to wake up.

Re “OTA Mode” … I note you have both a switch and a binary_sensor for this, where I have only the switch.
I suggest you do the maintenance check in the switch … which is automatically executed after wi-fi and API are connected. I found that ESPHome is multi-threaded and so things didn’t always happen in the order I was assuming.

switch:
  - platform: homeassistant
    name: "OTA Mode"
    id: ota_mode
    entity_id: input_boolean.shed_ota_mode
    # Maintenance check
    on_turn_on:
      - logger.log: "OTA Mode is ON: Disabling Deep Sleep"
      - deep_sleep.prevent: gotosleep
    on_turn_off:
      - logger.log: "OTA Mode is OFF: Proceeding to sensors"
      - deep_sleep.allow: gotosleep

… though one user reported that on_turn_on: didn’t work on their ESP32-C3.

My own greenhouse uses a rain sensor attached to GPIO17 to wake the ESP32 … though it took a lot of fiddling around to get it working correctly :frowning_face: If I remember correctly it was essential to get all the pin options exactly the same in the deep_sleep and sensor sections.

In case it helps (mainly to show you’re on the right track), this is my code which is working …

sensor:
  # rain gauge hardware sends pulses as the bucket tips.
  # the pulse_counter component returns the number of pulses in the preceding period (1 minute)
  - platform: pulse_counter
    name: Rain Gauge
    id:   rain_gauge
    pin: 
      # Reed switch between GPIO 17 and GND
      number: GPIO17
      inverted: true
      mode:                     # prevent lots of ON/OFF events
        input: true
        pullup: true
      allow_other_uses: true
    # check the rain_gauge every minute while awake
    update_interval: 60s

deep_sleep: 
  id: deep_sleep_1
  # wake up if it starts raining while asleep 
  wakeup_pin: 
    number: GPIO17              # wake up if a rain gauge pulse is detected
    mode:
      input: true
      pullup: true
    inverted: true              # the pin is inverted in rain_gauge, so same here 
    allow_other_uses: true