MQTT - config problems for one ESP sensor

Hope someone can help me out with this problem I cannot solve during the past two days. I am new to MQTT.
I try to run a WiFi Sensor ESP8266 via MQTT. While the sensor was running fine before via Thingspeak in HA, I decided to setup the sensor for HA via MQTT.
I do not think the sensor is the problem, it has something to do that HA cannot connect with the MQTT broker.
I have a separate laptop with HA OS on IP 192.168.178.37
I setup a new user in HA with the name: mqtt-user
I added MQTT client to addons
I added the integration MQTT
The last one gives the error: Not Loaded
I have mqtt explorer installed on my desktop Windows computer and it connects, I think, but I am unsure what to do here.
In the file editor, under configuration, I added the following:

mqtt:
broker: 192.168.178.37 # Use the correct Mosquitto hostname if it’s running locally (spaces at the beginning are lost in editor)
port: 1883
username: mqtt-user
password: Mqtt5tgb

sensor:

  • platform: mqtt
    name: “Temperature Sensor”
    state_topic: “home/sensor/temperature”
    unit_of_measurement: “°C”
    value_template: “{{ value | float }}”
  • platform: mqtt
    name: “CO2 Sensor”
    state_topic: “home/sensor/co2”
    unit_of_measurement: “ppm”
    value_template: “{{ value | int }}”
    The LOG gave me the following:Logger: homeassistant.config
    Source: config.py:940
    First occurred: 16:03:32 (1 occurrences)
    Last logged: 16:03:32

Invalid config for ‘mqtt’ at configuration.yaml, line 1: ‘broker’ is an invalid option for ‘mqtt’, check: mqtt->0->broker, please check the docs at MQTT - Home Assistant

Setup failed for ‘mqtt’: Invalid config.

The mqtt platform for the sensor integration does not support platform setup. Please remove it from your config.

Thanks in advance,
James

Configuring MQTT through configuration.yaml is deprectaed since awhile.
Add the MQTT integration through the UI.

Thanks Koying, I removed all from Configuration and it looks already a lot better. No error messages in the integration mqtt. However, any sensor declaration gives a fault.
Do I need to declare any sensor in configuration?
When I add the following, he complians about using “platform”
mqtt:
sensor:

  • platform: mqtt
    name: “CO2 Sensor”
    state_topic: “home/sensors/co2”
    unit_of_measurement: “ppm”
    sensor:
  • platform: mqtt
    name: “Temperature Sensor”
    state_topic: “home/sensors/temperature”
    unit_of_measurement: “°C”
    MESSAGE
    It’s not possible to configure mqtt sensor by adding platform: mqtt to the sensor configuration. To resolve this: Remove platform: mqtt occurences from the sensor: configuration in your YAML configuration file.

I tried some other config syntax but these return other errors.

Maybe you have an example, so I can mod it to my applcation?
Thanks

Please read the current documentation first, before trying some outdated examples.

The MQTT sensor is also deprecated since awhile.

Alright, true… I thought I do a quick go with help of chatgpt. Better to start reading. The problem however that there aren’t much examples. Did not expect this kind of time investment. Anyway. Thanks.

Edit: It works now with the following in configurations.yaml

my:
script: !include scripts.yaml
automation: !include automations.yaml
scene: !include scenes.yaml
history:

mqtt:
sensor:
- name: My temperature
state_topic: “home/sensors/temperature”
unit_of_measurement: “C”
- name: My CO2 level
unit_of_measurement: “ppm”
state_topic: “home/sensors/co2”

Note with copy paste: Be sure you make a 2 space indent with “sensor”: and then also 2 spaces indent to “-”. state is directly under name.