Help my Yaml file

I cannot get my MQTT-Switch file to work.:

/# Example configuration.yaml entry
mqtt:
broker: 192.168.1.51
port: 1883
username: XXXXXXX
password: XXXXXXX
client_id: homeassistant

-switch:
unique_id: bedroom_switch
name: Bedroom Switch
state_topic: home/bedroom/switch1
command_topic: home/bedroom/switch1/set
availability:
- topic: home/bedroom/switch1/available
payload_on: ‘ON’
payload_off: ‘OFF’
state_on: ‘ON’
state_off: ‘OFF’
optimistic: false
qos: 0
retain: true

It give me warning signs:

/Configuratiewaarschuwingen
Invalid config for ‘mqtt’ at configuration.yaml, line 18: ‘broker’ is an invalid option for ‘mqtt’, check: mqtt->0->broker
Invalid config for ‘mqtt’ at configuration.yaml, line 18: ‘client_id’ is an invalid option for ‘mqtt’, check: mqtt->0->client_id
Invalid config for ‘mqtt’ at configuration.yaml, line 18: ‘password’ is an invalid option for ‘mqtt’, check: mqtt->0->password
Invalid config for ‘mqtt’ at configuration.yaml, line 18: ‘port’ is an invalid option for ‘mqtt’, check: mqtt->0->port
Invalid config for ‘mqtt’ at configuration.yaml, line 18: ‘username’ is an invalid option for ‘mqtt’, check: mqtt->0->username
Integration error: -switch - Integration ‘-switch’ not found.

Can someone get me directions please?

Thanks.

Check out this link to format your code. #11

It helps expedite resolutions.

At first sight, you’re using the YAML way to configure your broker, which is deprecated since awhile.

Use the UI to add the integration, as described in the documentation

Hello,

My mqtt switch is added to the configuratiom yaml but it does not show in my mosquito mqtt integration,
Also not in MQTT Explorer.
Can someone give me some tips,

Thankx in advance

# Example configuration.yaml entry
mqtt:
  - switch:
      unique_id: bedroom_switch
      name: "Bedroom Switch"
      state_topic: "home/bedroom/switch1"
      command_topic: "home/bedroom/switch1/set"
      availability:
        - topic: "home/bedroom/switch1/available"
      payload_on: "ON"
      payload_off: "OFF"
      state_on: "ON"
      state_off: "OFF"
      optimistic: false
      qos: 0
      retain: true

After modifying configuration.yaml, did you restart Home Assistant (or execute Developer Tools → YAML → Reload Manually Configured MQTT Entities)?

If you did, check Logs for warning/errors.

I see at the top of your code it says example. If you just copied it off the documentation page its unlikely to work as its connecting to a real device.

Thank Y Spiro. Iam working on my ESP32 code to build a real device. Will take a few days.