MQTT client not connected

Hi,

I set up MQTT in HA. If I try to send a message (in the configuration of MQTT) I receive the errormessage: “Faild to call service mqtt/publish. Error talking to MQTT: The client is currently not connected”
If I send messages with MQTT-Explorer it seems to me that everything is ok.

Actually I just want to receive messages, but it’s not working; my sensors show up like “unavailable”, thats why I was playing with the configuration and figured out the problem with the client connection, maybe its a depending problem.

My config:

mqtt:
broker: 192.178.168.36 mqtt nas54
port: 1883
certificate: auto

sensor:

  • platform: mqtt
    state_topic: ontopic
    name: “OnTopic”
  • platform: mqtt
    state_topic: Schlafzimmer/Luftfeuchtigkeit
    name: “Schlafzimmer-Luftfeuchtigkeit”
    icon: mdi:water-percent
    unit_of_measurement: “%”
  • platform: mqtt
    state_topic: Schlafzimmer/Temperatur
    name: “Schlafzimmer-Temperatur”
    unit_of_measurement: “°C”
  • platform: mqtt
    state_topic: Schlafzimmer/Fenster
    name: “Schlafzimmrt-Fenster”
    icon: mdi:window-open
  • platform: mqtt
    state_topic: “Schlafzimmer/Batteriespannung”
    name: Schlafzimmer-Batteriespannung
    icon: mid:power-plug
    unit_of_measurement: “V”

What do I miss?

Did you setup a user and password dont use homeassistant as a user name

did you install the addon

and it configation is

logins:
  - username: mqttuser
    password: *********
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

you can check the logs

you shoud see something like

Hi, thx for your reply.
Yes, I installed the Mosquitto broker. When I tested it with MQTT-Explorer I can send messages and it seems that the broker is working.

Here my configuration.yaml:

#
mqtt:
  broker: 192.178.168.36   #mqtt nas54
  port: 1883
  certificate: auto
  username: "MQTTUser"
  password: 123456


sensor:
  - platform: mqtt
    state_topic: ontopic
    name: "OnTopic"
  - platform: mqtt
    state_topic: Schlafzimmer/Luftfeuchtigkeit
    name: "Schlafzimmer-Luftfeuchtigkeit"
    icon: mdi:water-percent
    unit_of_measurement: "%"
  - platform: mqtt
    state_topic: Schlafzimmer/Temperatur
    name: "Schlafzimmer-Temperatur"
    unit_of_measurement: "°C"
  - platform: mqtt
    state_topic: Schlafzimmer/Fenster
    name: "Schlafzimmrt-Fenster"
    icon: mdi:window-open
  - platform: mqtt
    state_topic: "Schlafzimmer/Batteriespannung"
    name: Schlafzimmer-Batteriespannung
    icon: mid:power-plug
    unit_of_measurement: "V"

In the protocoll I can find the following error:

“2022-01-04 10:13:14 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect to MQTT server due to exception: [Errno 104] Connection reset by peer”