MQTT silently failing

Ehlo,
I installed mosquitto on an Ubuntu 16.04 variant (elementary OS) and set it up with the following configuration :

allow_anonymous false
password_file /etc/mosquitto/passwd

listener 1883

listener 8883
certfile /etc/letsencrypt/live/example.com/cert.pem
cafile /etc/letsencrypt/live/example.com/chain.pem
keyfile /etc/letsencrypt/live/example.com/privkey.pem

My MQTT configuration in HA is :

broker: example.com
port: 8883
username: hass
password: !secret password
protocol: 3.1.1

I use owntracks and several Sonoff Tasmota Wifi switches with that broker. Using an MQTT client everything works flawlessly.

The problem is that MQTT doesn’t work in HA but no errors are shown in the logs. Publishing from HA to MQTT doesn’t work. Here is all I have in the logs :

cat /var/log/home-assistant.log | grep mqtt
2018-05-17 15:36:05 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt
2018-05-17 15:36:06 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2018-05-17 15:36:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=mqtt, service=publish>
2018-05-17 15:36:06 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.1 seconds.
2018-05-17 15:36:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=mqtt>
2018-05-17 15:36:06 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:36:07 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:36:08 INFO (MainThread) [homeassistant.loader] Loaded sensor.mqtt from homeassistant.components.sensor.mqtt
2018-05-17 15:36:08 INFO (MainThread) [homeassistant.loader] Loaded switch.mqtt from homeassistant.components.switch.mqtt
2018-05-17 15:36:09 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.switch] Setting up switch.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.switch] Setting up switch.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.switch] Setting up switch.mqtt
2018-05-17 15:36:09 INFO (MainThread) [homeassistant.components.switch] Setting up switch.mqtt
2018-05-17 15:36:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:36:21 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:36:37 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:37:09 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:38:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:40:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:41:46 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=sonoff/living_room/cmnd/POWER, payload_template=ON, service_call_id=139633990703648-61>
2018-05-17 15:41:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=sonoff/living_room/cmnd/POWER, payload_template=ON, service_call_id=139633990703648-62>
2018-05-17 15:41:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=topic=sonoff/living_room/cmnd/POWER, payload_template=ON, service_call_id=139633990703648-63>
2018-05-17 15:42:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:44:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:46:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:48:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:50:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:52:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2018-05-17 15:54:13 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

Does anyone have an idea to help me debug this ? Thanks in advance for the awesome software and community.

check your Pub/Sub topics and commands first.

1 Like

The log shows that HA thinks it has successfully connected to the broker and sent a message. Try the instructions on

1 Like

Thanks for the post. I re did all the steps and found out that the command mosquitto_passwd -c /etc/mosquitto/passwd homeassistant did reset the password file. Since I have multiple users that was a reason why HA wasn’t connecting.

Also I found out that TLS seems broken in HA with MQTT so I am just using the insecure version since it is on localhost anyway. I can publish now.

For anyone wanting to add several users to the password file, fill it with lines like user:passwd and then use the command mosquitto_passwd -U /etc/mosquitto/passwd

Thanks for the help !

1 Like