Use a binary sensor to wake up from deep sleep

Hi Community,
i am currently struggeling with the following problem in ESPHome:

I want to wake up a ESP32 when a Binary Sensor is set.
Then i want to go into deep sleep again.

This is my setup:

deep_sleep:
  run_duration: 60s
  sleep_duration: 60s
  wakeup_pin: 2

binary_sensor:
  - platform: gpio
    #pin: GPIO02
    name: "Testbinary"
    pin:
      number: 2
      #allow_other_uses: true

When i try to upload i am getting an error, that pin 2 is used in multiple places, even when option allow_other_uses is set to true.

Thank you for your help
Mario

Use the pin schema for the wakeup pin as well:

deep_sleep:
  run_duration: 60s
  sleep_duration: 60s
  wakeup_pin: 
      number: 2
      allow_other_uses: true

binary_sensor:
  - platform: gpio
    #pin: GPIO02
    name: "Testbinary"
    pin:
      number: 2
      allow_other_uses: true

Works great!
Thank you very much!

this brings me to a follow up question.

So the ESP is going into deep sleep as expected and wakes up when i press the button - so far so good.

i did set up a Automation where i increment a Counter for every press of the button. Works fine when ESP is awake, but desn’t recognize the press that woke up the ESP.

Any ideas here?

Mario

If it’s an ESP32, you can use wakeup_cause to determine if the button push did the wake. You would then increment your counter. If it’s an ESP8266 then I don’t know of a way.

If the ESP is in deep sleep, it will not be connected to HA, and nothing you do in HA will wake it. You either have to wake it with a physical thing connected to the ESP (i.e. the thing you have on GPIO2) or via a schedule that is set on the ESP in the deep sleep config.