Deepsleep with wakeup pin

Hi All,

I have setup an ESP32 with a switch to notify me that mail has been delivered. The configuration works well and i get notified with the switch is closed. The problem is i would like this to be battery powered and i have setup the deepsleep mode using MQTT, which again works fine BUT when i configure it with the wake up pin in never sleeps, it says setting up deepsleep then wakes up straight away.

esphome:
  name: letter-box
  platform: ESP32
  board: esp32dev

# Enable logging
logger:
substitutions:
  devicename: letter_box
# Enable Home Assistant API
#api:
#  password: !secret api_password

ota:
  password: !secret ota_password
  
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Letter-Box Fallback Hotspot"
    password: "xWQLqBBFswGd"

binary_sensor:
  - platform: status
    name: "${devicename} Node Status"
    id: system_status
  - platform: gpio
    pin:
      number: 14
      mode: INPUT_PULLDOWN
      inverted: True
    name: "letter box flap"
    device_class: door

mqtt:
  broker: 172.16.254.25
  discovery: True
  discovery_retain: True
  username: mqtt-user
  password: !secret mqtt_password
  birth_message:
  will_message:


deep_sleep:
  run_duration: 60s
  sleep_duration: 60s
  wakeup_pin: 14
  wakeup_pin_mode: INVERT_WAKEUP


sensor:

  - platform: adc
    pin: GPIO34
    name: "$devicename Battery"
    update_interval: 10s
    #attenuation: 11db
    #filters:
    #  - multiply: 3.35
      
switch:

  - platform: restart
    name: "$devicename Restart"

This is the log output, It does not matter with the switch is open or closed at the time the outcome is the same

[10:28:56][I][deep_sleep:072]: Beginning Deep Sleep
[10:29:01][I][mqtt:214]: MQTT Connected!
[10:29:01][C][deep_sleep:017]: Setting up Deep Sleep...
[10:29:01][I][app:060]: setup() finished successfully!
[10:29:01][D][binary_sensor:036]: 'letter_box Node Status': Sending state ON
[10:29:01][I][app:099]: ESPHome version 2021.10.2 compiled on Oct 25 2021, 10:22:59

So it looks like the issue is caused by the line “wakeup_pin_mode: INVERT_WAKEUP”

If i comment that out it works as expected, any advice on how to resolve?

Thanks

Now the unit does not wake from sleep ?

If i remove the wakeup_pin_mode command it works as expected and the deep sleep cycles works, BUT will keep the ESP32 awake if the switch is depressed(i.e. a letter is holding the mail flap open), this will drain the battery very quickly. The function i am looking for and that is supposed to be provided by wake_pin_mode is that if the switch remain depressed the ESP32 will go back to sleep.

Any help is appreciated, tbh it feels like a bug in the current version tbh, I still have an old docker image i might try going back to that and see if any luck

Sorry to say I never got INVERT_WAKEUP to function correctly.

Have a look here:

Functionally identical to yours ?

Yep that was the source project i used but not having any luck hence the question. Even using the Lolin D32 board. Hence my thoughts that it might be a bug in the current version.

I was using it (invert wake up) about a year and a half ago.

When my remote gate was left open the ESP32 should have gone to sleep. Just like it did when it was closed. Except it did not. It bounced from sleep to wake continuously while the gate was open. I never got to the bottom of it as I replaced it with a zigbee door/window sensor.

There are no issues open for this. You should open one:

Yep that is the exact behavior i am seeing, I will open an issue on it

Just did a quick test and went back to v1.19.4 and it seems to work on that version of code so i am guessing something has gone wrong since then.