Mqtt switch is always unavailable

After editing and inserting the mqtt switch code as per as the website even I have enter the broker home assistant is showing me switch is unavailable please tell me a solution.

mqtt:
broker : 127.0.0.1

switch:

  • platform: mqtt
    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”
    optimistic: false
    qos: 0
    retain: true

as in it doesn’t exist? Are you sure your topic is correct? Do you have a user/password for your broker? If so you need to add that. Is your device publishing?

Start with those and I’m sure you’ll figure it out.

I have the same issue. Did you ever determine the cause?