ESPHome sometimes not responding to button presses?

I have an issue where my ESPHome node is occasionally (eg one time out of nine maybe) not responding to button presses. The device is connected to the LAN and powered by ethernet rather than wifi and is connected to a Home Assistant instance via the API. Would really appreciate some tips on what might be causing this? I’d be surprised if it was the mechanical buttons themselves but open to any suggestions. Thank you!

I guess I’m wondering if it’s the code - or the API?

What’s super weird is that if I send an MQTT command while the device seemingly isn’t responding to the button presses, it responds.

esphome:
  name: craffid
  platform: ESP32
  board: esp32-poe

mqtt:
  broker: 192.168.2.30
  client_id: TL
  topic_prefix: T
  will_message:
    topic: craffid/avail
    payload: offline
  on_message:
    - topic: craffid/green/on
      then:
        - switch.turn_on: relay1
        - switch.turn_on: gindicator
    - topic: craffid/green/off
      then:
        - switch.turn_off: relay1
        - switch.turn_off: gindicator
    - topic: craffid/red/on
      then:
        - switch.turn_on: relay2
        - switch.turn_on: rindicator
    - topic: craffid/red/off
      then:
        - switch.turn_off: relay2
        - switch.turn_off: rindicator



#captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "x"

ota:
  password: "x"

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12

switch:
  - platform: gpio
    name: "Green Light"
    pin: 13
    id: relay1
    interlock: [relay2]
  - platform: gpio
    name: "Red Light"
    id: relay2
    pin: 15
    interlock: [relay1]
  - platform: gpio
    name: "Buzzer"
    id: buzzer
    pin: 14
  - platform: gpio
    name: "Green Indicator"
    pin: 3
    id: gindicator
    interlock: [rindicator]
  - platform: gpio
    name: "Red Indicator"
    pin: 2
    id: rindicator
    interlock: [gindicator]


binary_sensor:
  - platform: gpio
    pin:
      number: 39
      mode: INPUT_PULLUP
      inverted: True
    name: "Buzzer"
    on_press:
      then:
        - switch.turn_on: buzzer
    on_release:
      then:
        - switch.turn_off: buzzer
  - platform: gpio
    pin:
      number: 36
      mode: INPUT_PULLUP
      inverted: True
    name: "ALLOW "
    on_press:
      then:
        - switch.turn_on: relay1
        - switch.turn_on: gindicator
  - platform: gpio
    pin:
      number: 34
      mode: INPUT_PULLUP
      inverted: True
    name: "DENY "
    on_press:
        - switch.turn_on: relay2
        - switch.turn_on: rindicator