Wake on GPIO reports wrong GPIO number

Hi,

I’m building a battery powered remote with five buttons attached to GPIO, using a ESP32 Huzzah32 board. I’ve managed to get the ESP to wake correctly when buttons are pushed, but the GPIO number is reported correctly for some GPIO and very wrong for others, and I can’t seem to find a system for why.

If I wake the unit by pushing the button for GPIO26, the reported value from log(esp_sleep_get_ext1_wakeup_status())/log(2) is 26. If I wake by pushing GPIO34 (have also tested a few other GPIO, among other 25) it reports:

9223372036854775808 when formatted as uint64_t
-2147483648 when formatted as int

The first is 2^63 and the latter is -2^32.

Does anyone have any idea why esp_sleep_get_ext1_wakeup_status() could report correct GPIO for GPIO26, and wrong for 25 and 34 and some other that I don’t recall right now? I would believe that if GPIO26 (A0) works then GPIOS25 (A1) should behave the same…

Below is my YAML code, with some inline comments.

Last minute note: Describing this gives me a couple of ideas. I will try to write the int-values outside the mqtt.publish method. I will also remove the wifi fast_connect (just to remove unneccessary stuff).

esphome:
  name: musikkfjernkontroll
  platform: ESP32
  board: featheresp32
  on_boot:
    priority: 900
    then:
      - mqtt.publish:
          topic: musikkfjernkontroll/wake_up_reason
          payload: !lambda |-
            id(wake_up_reason_int) = log(esp_sleep_get_ext1_wakeup_status())/log(2);
            id(wake_up_reason_uint64) = log(esp_sleep_get_ext1_wakeup_status())/log(2);
            return to_string(id(wake_up_reason_int));

# Doing two things above; storing the ext1 wakeups status to both an int and an uint64_t for testing, and sending an mqtt message containing the wakeup reason.

# Creation of the two globals
globals:
   - id: wake_up_reason_int
     type: int
     restore_value: no
     initial_value: '0'
   - id: wake_up_reason_uint64
     type: uint64_t
     restore_value: no
     initial_value: '0'

wifi:
  ssid: ####
  password: ####
  fast_connect: true
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.86.26
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.86.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

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

captive_portal:

# Enable logging
logger:

# MQTT
mqtt:
  broker: 192.168.86.31
  id: mqtt_client
  username: ####
  password: ####


ota:
  password: ####

# Deep sleep should wake on any high. I have external pulldown of both GPIO.
deep_sleep:
  run_duration: 20s
  sleep_duration: 60s
  esp32_ext1_wakeup:
    mode: ANY_HIGH
    pins:
     - GPIO26
     - GPIO34


# Sensors for the two wake reasons, so they are easily visible in HA
sensor:
  - platform: template
    name: "musikkfjernkontroll_wake_reason_int"
    accuracy_decimals: 0
    lambda: |-
      return (id(wake_up_reason_int));
  - platform: template
    name: "musikkfjernkontroll_wake_reason_uint64"
    accuracy_decimals: 0
    lambda: |-
      return (id(wake_up_reason_uint64));


# Creation of both binary sensors for both GPIO. This helps me read their status live while the ESP is awake.
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO26
    name: "fjernkontroll0"
  - platform: gpio
    pin:
      number: GPIO34
    name: "fjernkontroll1"