Mosquitto installation


I have installed mosquitto on my HA build using this instruction “”. After the installation it worked, but as soon as I rebooted my system, the mosquitto.service did not start anymore

  • mosquitto.service - Mosquitto MQTT Broker daemon
    Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled; vendor preset
    Active: inactive (dead) since Tue 2018-12-11 09:56:29 CET; 13s ago
    Process: 2651 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -
    Main PID: 2651 (code=exited, status=0/SUCCESS)

Dec 11 09:56:29 vlappsrv001 systemd[1]: Started Mosquitto MQTT Broker daemon.

and from the HA log: 2018-12-11 09:52:31 ERROR (MainThread) [homeassistant.components.mqtt] Failed to connect due to exception: [Errno 111] Connection refused.

hope someone can help me getting this to work on my HA installation.

The normal way of install mosquitto is

sudo apt install mosquitto

Does this not work for you?

Yes, that worked form me, but in the instruction they mentioned that mosquito must start before homeassistant. I have configured that as they mentioned in the film. Than the first time the service started. But after a reboot it does not anymore.

Nobody has time to look through a video of some hackers idea about what you should do. Paste what you have done here, so we can see what the actual problem is.

I have followed the next procedure.

cd /etc
sudo systemctl stop hass.service 
sudo apt-get install mosquitto
cd /etc/mosquitto
ls -la
sudo mosquitto_passwd -c users.passwd mqtt_user
(input the password)
cd conf.d
ls -la
sudo nano user.conf

allow_anonymous false
password_file /etc/mosquitto/users.passwd

sudo nano /etc/systemd/system/mosquitto.service

Description=Mosquitto MQTT Broker daemon

ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d
ExecReload=/bin/kill -HUP $MAINPID


sudo update-rc.d mosquitto disable
sudo rm /etc/init.d/mosquitto
sudo systemctl enable mosquitto.service
sudo nano /etc/systemd/system/hass.service

# Service file for systems with systemd to run Home Assistant as the homeassistant user.

Description=Home Assistant for %i



sudo systemctl daemon-reload
sudo systemctl start mosquitto.service
ps -Alf | grep mosquitto
systemctl status mosquitto.service

cd /home/adminlocal/.homeassistant
sudo nano configuration.yaml

  broker: localhost
  username: mqtt_user
  password: !secret mqtt_password

sudo nano secrets.yaml

mqtt_password: your_password

sudo systemctl start hass.service

Messing around with an installed packages start up routine is not to be done lightly, even when you know what you are doing. Blindly copying some nice man off the internet is just foolhardy.

However I think if you remove the -d from the end of this line it might just work

ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d

and then do

sudo systemctl daemon-reload

to get it noticed.

@gpbenton, thanks, that worked. I understand that I should not mess around. But I had searched the forum and did not find a install procedure. So I expanded my search on google. If you would advise another way I would like to here it.

Although in theory, mosquitto needs to be started before HA, in practice HA starts so much slower these days that mosquitto is up and running before HA is ready to use it, unless something else is happening - such as network problems. So I haven’t done anything at all with my current setup.

Previously, I had done something like this, but I had just added the wants= line to the homeassistant.service file. Changing the mosquitto startup wasn’t necessary, and I don’t think it is now.

Having said that, I was told by someone else on the forum that adding the Wants= line doesn’t ensure that mosquitto is ready when HA starts, only that it has been started, so that its no guarantee everything will work anyway.

But maybe I am not the best person to ask about restarts :wink:

$ uptime
 11:02:41 up 250 days, 18:13,  1 user,  load average: 0.52, 0.45, 0.44

humble brag spotted