Arcade style GPIO button with internal LED

Hi,

I am connecting some arcade style buttons to my esp32 to use them as GPIO switches. They have internal LEDs that make the buttons light up. I am searching for a way to control the LED within ESPHome.

The code I came up so far is this:

binary_sensor:
  - platform: gpio
    id: gpio25
    pin:
      number: 25
    name: "Button"
    internal: True
    filters:
      - delayed_on: 100ms
    on_state:
      then:
        - output.turn_on: light_output

light:
  - platform: binary
    name: "Desk Lamp"
    output: light_output
    id: led

output:
  - id: light_output
    platform: gpio
    inverted: true
    pin: GPIO26

This works as far as the button lights up when I push it the first time, but I can’t figure out a logic to make the LED toggle on every hit of the button.
Unfortunately output.toggle: light_output doesn’t work.
I know this should be quite simple for experienced people in ESPHome but I am just starting out, so any help is much appreciated.

Best,
Chris

… ignore me if somebody more experienced comes along…

on_press:
  then:
    - light.toggle: led

My GPIO turns on a switch which I call from HA using API so therefore I ALWAYS know whether the switch is on or off. In this case, the automation does not rely on the state of what every your GPIO switch is doing. You might want to use a switch or button platform or something like a global so you always know the state of the switch? I use a text_sensor to import the state of the switch back into ESP node.

text_sensor:
  - platform: homeassistant
    name: Pump Status
    internal: False
    entity_id: switch.shelly_watertankpump
    on_value:
      then:
        lambda: |-
          if(x == "on") {
            auto call = id(pumpled).turn_on();
            call.perform();
          } else {
            auto call = id(pumpled).turn_off();
            call.perform();
          }