Problem starting embedded MQTT broker

From https://home-assistant.io/docs/mqtt/broker/ this should be as simple as adding mqtt: to configuration.yaml. Have done this but getting the errors:

17-04-22 05:44:10 ERROR (MainThread) [homeassistant.components.mqtt] Unable to start MQTT broker.
17-04-22 05:44:10 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Component failed to initialize.

Note that my HASS instance runs fine with a declared broker on another machine.
Any advice appreciated, cheers!

Hassbian 0.42.4 on an RPI3

can you check whether broker service running?
sudo /etc/init.d/mosquitto status

Use this link to help diagnose.

Setting the log level to DEBUG might give you more information.

OK I updated to 43.0, restarted my pi and again with just mqtt: in the config.yaml I get:

● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Sun 2017-04-23 05:18:17 UTC; 1min 41s ago
  Process: 495 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─522 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Apr 23 05:18:17 hassbian systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
Apr 23 05:18:17 hassbian mosquitto[495]: Starting network daemon:: mosquitto.
Apr 23 05:18:17 hassbian systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.

All good, however in the front end I get an error and in the log I get:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/server.py", line 48, in async_start
    yield from broker.start()
  File "/home/homeassistant/.homeassistant/deps/hbmqtt/broker.py", line 291, in start
    raise BrokerException("Broker instance can't be started: %s" % e)
hbmqtt.broker.BrokerException: Broker instance can't be started: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use
17-04-23 05:18:30 ERROR (MainThread) [homeassistant.components.mqtt] Unable to start MQTT broker.
17-04-23 05:18:30 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Component failed to initialize.
17-04-23 05:18:31 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
17-04-23 05:18:31 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
17-04-23 05:18:31 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
17-04-23 05:18:31 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.

Setting log level to DEBUG I get:

17-04-23 05:25:56 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugins for namespace hbmqtt.broker.plugins
17-04-23 05:25:56 DEBUG (MainThread) [hbmqtt.broker] Broker starting
17-04-23 05:25:56 ERROR (MainThread) [hbmqtt.broker] Broker startup failed: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use
17-04-23 05:25:56 ERROR (MainThread) [homeassistant.components.mqtt.server] Error initializing MQTT server
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/base_events.py", line 757, in create_server
    sock.bind(sa)
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/hbmqtt/broker.py", line 270, in start
    loop=self._loop)
  File "/usr/lib/python3.4/asyncio/streams.py", line 101, in start_server
    return (yield from loop.create_server(factory, host, port, **kwds))
  File "/usr/lib/python3.4/asyncio/base_events.py", line 761, in create_server
    % (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/server.py", line 48, in async_start
    yield from broker.start()
  File "/home/homeassistant/.homeassistant/deps/hbmqtt/broker.py", line 291, in start
    raise BrokerException("Broker instance can't be started: %s" % e)
hbmqtt.broker.BrokerException: Broker instance can't be started: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use
17-04-23 05:25:56 ERROR (MainThread) [homeassistant.components.mqtt] Unable to start MQTT broker.
17-04-23 05:25:56 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Component failed to initialize.
17-04-23 05:25:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1980352304-1, service=create, domain=persistent_notification, service_data=title=Invalid config, message=The following components and platforms could not be set up:
* [mqtt](https://home-assistant.io/components/mqtt/)
Please check your config, notification_id=invalid_config>
17-04-23 05:25:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* [mqtt](https://home-assistant.io/components/mqtt/)
Please check your config; title=Invalid config @ 2017-04-23T06:25:56.669959+01:00>, entity_id=persistent_notification.invalid_config>

As per Tutorial: IOT / Installing and Testing Mosquitto MQTT on the Raspberry Pi for Buster - SwitchDoc Labs Blog when I attempt to subscribe to a topic on the running mqtt server I get:

pi@hassbian:~ $ mosquitto_sub -d -u homeassistant -P My_Pass  -t hello/world

Client mosqsub/1506-hassbian sending CONNECT
Client mosqsub/1506-hassbian received CONNACK
Connection Refused: not authorised.

doesn’t user=user?

Same error with -u user

I believe the user should be homeassistant as per https://home-assistant.io/docs/mqtt/broker/#embedded-broker

If you have mosquito running and try to start the internal broker, they both use the same port, and so this error occurs. You normally only need one broker for your network.

Yes this is the problem, however I have not started a mosquitto broker independently.
To be sure I run:

pi@hassbian:~ $ sudo /etc/init.d/mosquitto stop
[ ok ] Stopping mosquitto (via systemctl): mosquitto.service.

Now restart pi to restart HASSBIAN. Get in log the same info:

17-04-23 06:35:25 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugins for namespace hbmqtt.broker.plugins
17-04-23 06:35:26 DEBUG (MainThread) [hbmqtt.broker] Broker starting
17-04-23 06:35:26 ERROR (MainThread) [hbmqtt.broker] Broker startup failed: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use
17-04-23 06:35:26 ERROR (MainThread) [homeassistant.components.mqtt.server] Error initializing MQTT server
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/base_events.py", line 757, in create_server
    sock.bind(sa)
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/deps/hbmqtt/broker.py", line 270, in start
    loop=self._loop)
  File "/usr/lib/python3.4/asyncio/streams.py", line 101, in start_server
    return (yield from loop.create_server(factory, host, port, **kwds))
  File "/usr/lib/python3.4/asyncio/base_events.py", line 761, in create_server
    % (sa, err.strerror.lower()))
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 1883): address already in use

So my question is what is starting the conflicting broker, since I am not doing it…?

Solution:

OK so I ran the HASSBIAN script https://github.com/home-assistant/hassbian-scripts#install-mosquitto-install_mosquitto

And in configuration.yaml added the mqtt broker as per https://home-assistant.io/docs/mqtt/broker/#run-your-own pointing to the IP of my HASSBIAN pi, and everything runs fine. I am unsure why this script is necessary if there is an embedded mqtt broker however…?

The internal broker is limited in its capabilities.

How can I tell if the embedded MQTT is running? I have 0.43.1 installed on a server running Ubuntu 16.04 and I installed via Virtual Environment.

When I run “sudo /etc/init.d/mosquitto status” I get:

sudo /etc/init.d/mosquitto status
sudo: /etc/init.d/mosquitto: command not found

And when I navigate to /etc/init.d there is no “mosquitto”

Do I need to install it? I thought embedded meant it was already there.

I am trying to run:

Mosquito is a stand alone, popular MQTT server. It is not the same as the embedded HASS broker. It needs to be installed.

Okay, thanks. I guess I misunderstood this thread.

I recall it not being the most straight forward thing when I was starting out either :slight_smile:

Mosquitto is worth your time vs the HASS broker though, IMHO.

I went back to cloud (had it for something way back) but still having issues. I can’t remember if I ever had it working. On a side note, I did get WallPanel installed on a Kindle Fire Tablet. So once I get mqtt figured out I’ll be in business.

1 Like

ahhh I think have this problem, how to stop mosquitto from running in boot?

I think if yoiu add
mqtt:
broker:

it will use mqtt, if you take out broker: it will use the embedded (but mosquitto also running on same port).

my goal is to use ssl/tls for a mqtt (mosquitto or embedded) how to do?

Disable it in whatever startup system your platform is using. For example, if you’re using systemd, then systemctl disable mosquitto

I have no idea which one I have. I installed a clean hassbian 1.1 image