What is in ESPHome the relationship between binary_switch, switch and output?

Following up on a question about switch vs light in a Sonoff running ESPHome, I ended up with the following configuration:

esphome:
  name: ${name}
  platform: ESP8266
  board: esp8285

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: ${name}
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    name: ${name}
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes

sensor:
  - platform: wifi_signal
    name: ${name}
    update_interval: 60s

output:
  - platform: gpio
    pin: GPIO12
    id: switch_status

light:
  - platform: binary
    name: ${name}
    output: switch_status

This is visible in HA as:

image

The last switch is the light one, the one before is the switch.

I am now trying to understand how from the ESPHome configuration I get the elements in the screenshot.

binary_sensor is the physical button on the Sonoff.
switch is the actual electrical relay
output is an internal status of GPIO13 ← I am not sure of this one
light is a component which is driven (and which drives) the output.

If the above is correct:

  • is switch only needed by binary_sensor to act upon a physical press?
  • since I can toggle via the light component, does output actually change the state of the GPIO? (I think so) → I am asking because output would suggest that this is just an indication of a state

A switch is a switch and a light is a light. A light does not need a switch. It can be turned on and off by HA or by an automation in esphome.

An output is the conduit between the light component and the real world. Like a gpio pin.

@nickrout

A light does not need a switch. It can be turned on and off by HA or by an automation in esphome

please consider the following setup (I omitted the general parts, not related to the “switching” or “light” part):

output:
  - platform: gpio
    pin: GPIO12
    id: switch_status

light:
  - platform: binary
    name: ${name}
    output: switch_status

There is no switch and the light component still switches the power on and off (through output).

An output is the conduit between the light component and the real world. Like a gpio pin

By that logic, a switch should also be connected to an output - it is not, it directly triggers the GPIO.

EDIT - I tried to have binary_sensor to use output to trigger the GPIO but the firmware would not compile.

A sensor or binary_sensor sense something, not switch it.

A switch can control an output, see https://esphome.io/components/switch/output.html