Mosquitto "Error: adress already in use"

A while ago I installed mosquitto with the hassbian script

sudo ./hassbian-scripts/install_mosquitto.sh

The installation went fine and the integration with HASS and owntracks works like a charm. So far so good.
Because I want to play with the android tasker app and the mqtt plugin I tried to start mosquitto. I then get the following error:

pi@hassbian:~ $ mosquitto
1529048526: mosquitto version 1.4.15 (build date Sat, 07 Apr 2018 11:13:41 +0100) starting
1529048526: Using default config.
1529048526: Opening ipv4 listen socket on port 1883.
1529048526: Error: Address already in use

I figured out that I should edit etc/systemd/system/ [email protected]. However when I change it and reboot the pi, I can start mosquitto but Hass give me an mqqt installation error. When I restart Hass the mqtt errors are gone but I then the ā€œadress already in useā€ error is back again :frowning:

Does anyone know how to solve this problem?

My configs look like:

configuration.yaml

mqtt:
  broker: 192.168.1.120
  port: 1883
  client_id: home-assistant
  username: mosquitto
  password: !secret mosquito_password

/etc/systemd/system/[email protected]

[Unit]
Description=Home Assistant for %i
After=network.target mosquitto.service influxdb.service

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

/etc/mosquitto/mosquitto,conf

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

/etc/mosquitto/conf.d/local.conf

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_file mosquitto.db
persistence_location /var/lib/mosquitto/
user mosquitto
password_file /etc/mosquitto/pwfile

allow_anonymous false
connection_messages true

log_dest topic
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
log_timestamp true

The error normally indicates two brokers trying to open the same port. Did you stop the version of mosquitto started by systemd before you ran on the command line?

sudo systemctl stop mosquitto.service
1 Like

Thanks that worked! But do I have to stop this service each time after a reboot or can I disable it permanently? Do I need that broker in the first place?

The hassbian configuration script configures mosquitto to start automatically on reboot. If you do not want this you can disable it by

sudo systemctl disable mosquitto.service

and to re-enable it

sudo systemctl enable mosquitto.service

Ok, but which mosquitto does hassbian configures; the internal broker or the one I installed with the script??

However I got the following messageā€¦

pi@hassbian:~ $ sudo systemctl disable mosquitto.service
mosquitto.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable mosquitto

This configures HA to use an external broker at this address. If you do not define an address, the embedded broker is used. See

Okay thats clear

But what i dont understand is that Hass gives me config errors after I stopped and disabled mosquitto.service. After I turned the service on the errors are gone. So it seems that hass uses mosquitto.service. And if this is the internal broker why isnt hass uses the external broker I installed. My config looks like

mqtt:
  broker: 192.168.1.103
  port: 1883
  client_id: home-assistant
  username: mosquitto
  password: !secret mosquito_password

So it shouldnt use my internal broker :confused:

Letā€™s get the terminology straight, because I think that is where you are getting confused.

HomeAssistant has an embedded broker, that is included within the code of HA. To use this, you do not need to install anything, and need to specify just mqtt: in your configuration file to enable it. Everything else is regarded as an external broker. Thus there is no such thing as an internal broker.

The mosquitto program you have installed is an external broker, and presumably is running at the location 192.168.1.103, as you get error messages only when it is not running.

Hi,
i know this is an old post but iā€™ve this error and i donā€™t know how to figure out.
Iā€™ve tried to start this service without success :frowning:
Iā€™ve also tried to del all mosquitto folders but iā€™ve had permission problems.
Is there anyone help me?
Iā€™ve Hassio installation on docker.
Regards,

Alessandro

Sorry, I know nothing about hassio.