It’s easy by just doing something like this:
binary_sensor:
- platform: gpio
# ...
on_state:
then:
- if:
condition:
api.connected:
then:
- logger.log: "We are going full detached now because the api is connected"
- homeassistant.event: esphome.button_pressed # action when api is connected
else:
- logger.log: "No api connection - let's solve things locally"
- light.toggle: younameit