MQTT Not Working Help (Latest Isuues related) (SOLVED)

Hey,

I have read over issues:
Embedded MQTT Broker failing on 0.48.0 #8315
MQTT Client initialized incorrectly with paho-mqtt to 1.3.0

and I’m not quite sure how to fix these issues.

With no mqtt in my config it works happily, I can connect to the broker with a 3rd part app and all works fine.

With this is my config it breaks the whole broker and nothing will connect to the broker

mqtt:
broker: 192.168.X.XXX
port: 1883
client_id: HomeAssistant
keepalive: 60
username: X
password: X

And get the errors

2017-07-06 10:45:33 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 187, in _async_setup_component
    result = yield from component.async_setup(hass, processed_config)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 381, in async_setup
    success = yield from hass.data[DATA_MQTT].async_connect()
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 491, in async_connect
    self._mqttc.connect, self.broker, self.port, self.keepalive)

I change my config to

mqtt:
  broker: 192.168.X.XX
  port: 1883
  client_id: HomeAssistant
  keepalive: 60
  username: X
  password: X
  protocol: 3.1
  tls_insecure: True
  tls_version: auto

and get the errors

2017-07-06 11:07:48 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 187, in _async_setup_component
    result = yield from component.async_setup(hass, processed_config)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 368, in async_setup
    will_message, birth_message, tls_version)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 460, in __init__
    self._mqttc.tls_insecure_set(tls_insecure)
  File "/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py", line 727, in tls_insecure_set
    raise ValueError('Must configure SSL context before using tls_insecure_set.')
ValueError: Must configure SSL context before using tls_insecure_set.

This issue killed my mqtt about to weeks ago and has made Home Assistant useless to me as everything I control is via MQTT :frowning:

Can anyone offer any sort of help?

You can try to downgrade it to see if the problem goes away.

If you using all-in-one raspberry

sudo su -s /bin/bash hass
source /srv/hass/hass_venv/bin/activate
hass --script check_config
pip3 install homeassistant==0.47.1

Downgraded and still the issue is there.

2017-07-06 12:06:39 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 187, in _async_setup_component
    result = yield from component.async_setup(hass, processed_config)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 377, in async_setup
    success = yield from hass.data[DATA_MQTT].async_connect()
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/__init__.py", line 487, in async_connect
    self._mqttc.connect, self.broker, self.port, self.keepalive)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py", line 700, in connect
    return self.reconnect()
  File "/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py", line 822, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)

Ill also note this is a fresh install last night with Hassbian (48.1) installed via script samba and mosquito, then copied my config files in.

I am using the Mosquito running on my server.
My configuration as follow:

broker: 192.168.x.x
port: 1883
client_id: hass
keepalive: 60
username: hass
password: !secret mqtt_password
protocol: 3.1.1

It’s running fine on version 48.1.
When you run config check, did it give you error?

sudo su -s /bin/bash hass
source /srv/hass/hass_venv/bin/activate
hass --script check_config

Running

pi@hassbian:~ $ sudo su -s /bin/bash homeassistant
homeassistant@hassbian:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $ hass --script check_config
INFO:homeassistant.util.package:Attempting install of colorlog>2.1,<3
Testing configuration at /home/homeassistant/.homeassistant

Gives nil errors

2017-07-06 14:12:04 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2017-07-06 14:12:04 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds.

I did a search based on your partial output, and found this MQTT setup error in 43.2

Would that be a problem connecting to your MQTT server?
From your HASS server, can you run telnet to the MQTT server on port 1883?

i.e. telnet 192.168.X.XXX 1883

Also try changing the protocol and don’t configure tls parameter.

As far as I can see, all the MQTT problems with 0.48 were related to the internal broker implementation. If you specify the broker address, you have configured to use an external broker, so you don’t need to worry about tls_insecure

Are you sure the external broker is running. You don’t say, but if you are using mosquitto, and start it up with systemd you can do

$ systemctl status mosquitto.service

to check that it is running.

If you have done an apt-get upgrade recently, the latest mosquitto package seems to disable start on boot so you may need to do

$ sudo systemctl enable mosquitto.service

to enable it to start on boot, and

$ sudo systemctl start mosquitto.service

to start the service.

2 Likes
pi@hassbian:~ $ systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; disabled)
   Active: inactive (dead)
     Docs: man:mosquitto(8)
           https://mosquitto.org/

We have a winner, I could kiss you gpbenton lol

What was weird, I run MQTT Box (OSX) as a client to monitor and test MQTT stuff, and with mqtt removed from my config, it was saying it was connecting fine, but seemed to not pass any messages obviously.

I also assumed mosquito was the built in broker for HASS as well, seems as there was a script written for it an all.

Everything is now back up and running, and yes it was an apt-get which killed it :frowning:

Now to get to working on ffmpeg with a access denied back door lol, but thats one for another thead if i cant work it out by next week lol

Also thanks zajnic for you assistance as well, hopefully this helps others.

Many thanks - solved my issues with mqtt as well !