ESPHome Architecture question: hierarchy of integrations,domains, platforms, components, entities, etc

Hi,
I’m trying to configure things in ESPhome in HomeAssistant but I can’t get my head around the architecture. Thanks to advanced copy-and-paste from examples on the internet, things are working, but I’s like to understand why
I have been Googling for about 1hr, but didn’t find what I need
Time to call in the cavalry, the experts on this forum… you

Can somebody point me to a documentation page that describes the hierarchy of :
“integrations domains platforms components entities”

e.g.
I have the below configuration (in ESPhome).
It works, but I don’t understand it

output:
  - platform: gpio
    id: LivingData1
    pin: D1
    inverted: yes
light:
  - platform: binary
    name: "LivingLamp1"
    output: LivingData1

How does “output” relate to “light” ? And why do I need both? (or… don’t I ?)

thank you so much in advance,
chrisV

My apologies if this sounds like a broken record, but for me, this feels like an important thing to understand.
To make the “light” work in home-assistant, apparently we need 2 separate entries. (or is my understanding wrong?)
Entry1 is output
Entry2 is light

output:
  - platform: gpio
    id: Data1
    pin: D1
    inverted: yes
light:
  - platform: binary
    name: "LivingRoomLight1"
    output: Data1

Can somebody please elaborate on why we need 2 separate entries here?

As a reference, the switch component does not need a separate “output” entry

switch:
  - platform: gpio
    id: d6
    pin: D6
    inverted: no
    name: "${hostname}_relay1"

Any input, even the “obvious” is greatly appreciated
thanks,
chrisV

I guess it is the general idea of abstraction:

  • The light dev can develop without bothering the output-code
  • The output-code might be different on different platforms
  • The output component can be used by different higher-tier components and doesn’t have to be reimplemented over and over.
  • Maybe there is a use in having multiple components referencing the same output-component.

Why this isn’t done for the switch - no idea. Maybe it is a very old component or just an alias for an output.

This is speculation from me.

I think the switch was a very early implementation of usage of gpio and are there because of simplicity and has been there for a long time.

There are the similar construction for switch as for the light which is called

So the api is not pure and more constructed organic and fixed over time when they needed to implement more complex things when the functionality grew.

/Mattias

ah, cool, indeed, I had not seen this Generic Output Switch documentation.
So, this 2-stage approach seems like the more “generic” and “pure” way to go.
Also, I noticed that the first part (the output), is restricted to the ESP board itself, while the second part (the switch) is what will be send to Home-assistant.
thank you for your input @birchman
things are slowly coming together in my mind :slight_smile:
chrisV

1 Like