ESP WakeUp after deep sleep and action same pin

Hi:

I have a simple question:

Does anyone have code to create an automation that will do:

  • Use the button to control waking up from deep sleep and at the same time the same button reports a change of state to the template switch?
deep_sleep:
  id: deep_sleep_component
  sleep_duration: 30s
  run_duration: 30s
  esp32_ext1_wakeup:
    mode: ANY_HIGH 
    pins:
      - 32

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO32
      inverted: true
    name: "Wake Up Button"
    id: "wake_up"
    filters:
      - invert:
      - delayed_on: 10ms
    on_press:
      then:
        - switch.template.publish:
            id: buttonleft
            state: !lambda |-
              if (id(buttonleft).state) {
                return false;
              } else {
                return true;
              }

switch:
#BUTTON TEMPLATE SENSOR
  - platform: template
    name: "${friendly_name} Button Left"
    id: buttonleft
    optimistic: true

At the time you press the button, the esp32 is asleep. It then boots. I guess it all depends whether the button is still pressed when the boot is completed.

Unfortunately, it’s a button, not a switch.
Can the esp32 find out which button it woke up with

This question has been asked previously on the forum, and I am pretty sure the answer is that there is no way to distinguish which gpio triggered a wakeup.

The only option that came to my mind is to hold the push button longer for approx. 2-3 seconds when the esp is already running enough to distinguish which gpio is held (high/low) and thus it is already possible to distinguish which GPIO is pressed.

You could “complicate” things a bit: create flip-flop (bistable circuit) so that when you push the button output of flip-flop stays active until esp boots and it’s (another) output sets this tflip-flop back to standby.
You can create flip-flop in many ways, one of them are good old 40xx series CMOS chips.

1 Like