Esp8266 newbie

Just a very newbie question.
So I finally got my ESP8266 to be discovered as a device in home assistant.
My question : Why do we need to upload a yaml binary file in the ESP home web ui interface and also upload a sketch via the Arduino IDE ? How does this mechanism work? My goal to create a switch and use MQTT to talk to other devices on my HomeAssistant.

You do not need to upload a sketch using the Arduino IDE.

ESPHome will compile a binary from your yaml configuration file. This binary is then uploaded to the ESP using ESPHome or the ESPHome flash tool.

Is there an example of how to create a topic to publish to in the ESP yaml configuration file?