Trying to understand a configuration file

I’m working on a project I’ve seen for controlling a vent fan through PWM. I’ve gone over the wiring and schematics and I’m trying to understand the configuration in ESPHome. Here’s the part of the file I need to add to my current configuration on my ESP32:

output:
  - platform: ledc
    pin: GPIO5
    id: intake_fan_op
    inverted: true
    frequency: 1000
    
fan:
  - platform: speed
    output: intake_fan_op
    name: "Tent intake fan"
    speed_count: 10
    id: intake_fan

I have a few questions:

  1. These 2 sections seem to be describing the info for controlling 1 fan. What is it that says, “This fan works with this output?”
  2. I’ve read about people using ESPHome to control 2, or even 4, of these vent fans using PWM. How would I set up multiple instances to control more than one fan, all of the same type?
  3. I’m still learning the IO on the ESP32. Will any GPIO pin work for PWM fan control or only certain ones?

I think the id: intake_fan_op in the output section links that output to the fan section, since the fan has output: intake_fan_op and that seems obvious, but I really want to know what I’m doing before I start hooking hardware together! (And I get that if I’m right, I can define multiple fans and multiple outputs by just linking the output field in each fan section with the id field in each separate output section.)

And, last question:

  1. If I’m using multiple fans, is there a way to use inheritance to define all the items that would be the same on each fan, and reference that definition from each fan class or section?

Yes, the output: field refers to the id of the output.

Any output capable GPIO pin will work for PWM. Extender pins and input only pins won’t.

You can use YAML anchors to copy and repeat configuration for similar items. Google “yaml anchors and aliases”

Okay, got it - and looked up yaml anchors. Thanks!

One last question - does order matter? In other words, if I put the fan definition first, then the output, is there a problem in compiling if the fan is referring to an output section that is defined later?

No, YAML validation is done in multiple passes so forward uses are ok.