HASS.IO Mosquitto: can’t connect HA

Dear forum

Today I installed the Mosquitto broker on Hass.io. Only starts working after disable port 1883 in the Hass.io set-up. In Portainer I see that the container is running and using port 1884:1884 plus some other ports (not 1883).

After that tried to set-up MQTT integration in HA using configuration/Integrations (not configuration.yaml), but not able to connect to the broker on servers IP address (hass.io server) and port 1884. Port 1883 it connects to without delay, but that is not what I configured.

With the container up and running, using top command on the Linux server I see Mosquitto active. schutting down the container and its not visible in top anymore.

Am I missing a step in the configuration of Mosquitto here, or is there another problem?

Thanks for your help!

Regards
OWK

Talking to my self here :wink:
After removing the manually configured MQTT integration and rebooting the (NUC) server, HA offered a detected MQTT instance. This does not require configuration, just one mouse click.
In the MQTT log of Hass.io a connection shows:

1577118238: New client connected from 172.30.32.1 as auto-E7F8C019-9E16-C5EE-E017-xxxxxxxxx (p2, c1, k60, u’homeassistant’)

Now the main question: this is not according to the installation description in HAss.io. But is this correct or not?

And secondly: does the serving application that sends the messages to Mosquitto require a username/password or not?

Regards
OWK

Follow the directions in the mqtt integration. Setup a new user and password. Use this username and password for your devices.

IMHO this ist correct. There ist no need und you must not install manually MQTT broker when using the MQTT add-on.

See documentation for MQTT add-on.

Regards
Horst

Hi Honikos

That’s what I’ve done: click ‘configure’. But i’m only presented one option here, and that is ‘Enable discovery’, no other fields to fill. Those are only available if you click the + and select MQTT from the list of integrations. And with those fields filled I can’t configure port 1884 (no connection possible) 1883 is connecting, but that is not configured in Mosquitto.

Regards
OWK

The port 1883 is configured in the BROKER… not the integration. Port 1884 can also be used for MQTT SSL connections…
Install the broker and set active: false in the broker; Don’t configure a user… either create or use a regular home Assistant user for MQTT in your devices. You DON’T need to setup a user in the broker.

If you can’t make it work, post your broker config.

If you use MQTT discovery, you need to make sure you have enabled discovery in your devices but you haven’t said what devices you are using.

Hi David
The broker has default configuration:

Port 1883 has to be disabled otherwise the broker will not start (address already in use). I did not find other programs on my server using port 1883.

Mqtt will be used to receive power usage details from an external device, a smart meter.

Regards
OWK

You must have another MQTT addon or broker using 1883. Are you sure you didn’t install the MQTT community addon as well as the Core MQTT addon? How did you install hassio?

I downloaded the HA NUC image and used that to build on top of Ubuntu 19.10

On the NUC: netstat - tulpn results in (amongst other lines not relevant):
tcp 0 0.0.0.0:1883
tcp6 :::1883
tcp6 :::1884

My conclusion: 1884 is missing in the list of tcp protocols

In portainer I don’t see any 1883 ports in use, just 1884 by Mosquitto

To be sure I did: sudo apt purge mosquitto, but as expected the result is ‘ Package ‘mosquitto’ is not installed, so not removed.’

Further investigating revealed that despite disabling port 1883 in config, a listener be started by Mosquitto anyway. As others have concluded in post Hass.io mosquitto GUI ignores disabling of port 1883.

I see that in my hass.io Mosquitto log:

1577111527: Opening ipv4 listen socket on port 1883.
1577111527: Opening ipv6 listen socket on port 1883.
1577111527: Opening websockets listen socket on port 1884.

I also see in the same log:

1577118238: New connection from 172.30.32.1 on port 1883. [INFO] found homeassistant on local database
1577118238: New client connected from 172.30.32.1 as auto-E7F8C019-9E16-C5EE-E017-xxxxxxxxx (p2, c1, k60, u’homeassistant’).
1577118730: Saving in-memory database to /data/mosquitto.db.
1577120531: Saving in-memory database to /data/mosquitto.db.

Am I correct to conclude that the link to Homeassistant should be working?

Unfortunately things go bad: Homeassistant disconnects immediately.

1577203214: New connection from 172.30.32.1 on port 1883.
1577203214: New client connected from 172.30.32.1 as auto-31CAF3B4-DCAE-0BFA-E66E-5A3D0F8D89F3 (p2, c1, k60, u’homeassistant’).
1577203214: Client auto-31CAF3B4-DCAE-0BFA-E66E-5A3D0F8D89F3 disconnected.

So I see several issues:
1: it is not clear which port number is used by Mosquitto: 1883 seems standard but can’t be configured. Maybe solved in the newer version of Mosquitto.
Port 1884 is shown in the container set-up, but not seen using Linux command netstat -tulpn. Is firewall configuration required here?
2: the way of configuring HA can be done in 2 ways (using the discovered MQT that has no fields to fill or the manual one using the + and does include fields to fill. It’s not clear which of the 2 methods is correct
3: documentation of HA needs updating. This should point to the correct configuration method with a warning not to use the other one, and a description on how to configure the account the publishing system (in my case the smart meter appliance) has to use
4: there is a newer version of Mosquitto, so an update of the Hass.io addon is welcome, to rule out bugs in the current version

This doesn’t make sense. You are either using the NUC IMAGE or you are using Ubuntu.

1883 is standard, but mosquitto will run on whatever port you tell it to.

Only if you have ENABLED the firewall, which isn’t enabled by default AFAIK

Whichever one you prefer. There is no “correct” method of running a broker.

So update it.

But you can use whichever configuration you want.

Still having problems with the HassIO 5.1 version of Mosquitto, let me update to show where i’m stuck

1: In HassIO developers tools MQTT tab I enable listen to all topics using #
2: Using the publishing tool on the same page I can send a message that is shown in the listening part

So this look promising, but using the Mosquitto provided way of sending a test message is not received in HassIO. This is what I sent from the command line on the HassIO server (not in the Mosquitto container) and what is shown as debug response:

mosquitto_pub -h 192.168.178.21 -m “test” -p 1883 -t house/bulb1 -u mqtt -d

Client mosq-4ASxJAwc3D5w2dWPB5 sending CONNECT
Client mosq-4ASxJAwc3D5w2dWPB5 received CONNACK (0)
Client mosq-4ASxJAwc3D5w2dWPB5 sending PUBLISH (d0, q0, r0, m1, ‘house/bulb1’, … (4 bytes))
Client mosq-4ASxJAwc3D5w2dWPB5 sending DISCONNECT

So it looks like it is sending a message correctly, but it is not shown in the listen windows in HassIO.

Any ideas?

Regards
OWK

Ok, talking to myself… Issue is solved now!

That port 1883 could not be configured in Mosquitto config was still bothering me. Together with the fact that messages where received somewhere as shown by MQTT-explorer (great tool!), got me reviewing the steps already followed.

As written earlier, while suspecting Mosquitto was already installed I used the apt command to purge Mosquitto. That resulted in a message that Mosquitto was not installed.
After uninstalling the HassIO Mosquitto and restarting HA, messages where still processed, so there was an instance of a mqtt application processing the messages…
After finding the PID and using a command to see what application belonged to it, I saw that it was a snap installed application.
Using ‘snap list —all’ (2 dashes) I saw that Mosquitto was installed.
Using the command ‘snap remove mosquitto’ removed all appearances and from there on I could reinstall the HassIO version and initiate the integration. Mqtt is now working flawlessly

Conclusion I now have is that in Ubuntu 19.10 Mosquitto is installed by default, because I did not do that manually.

Regards
OWK

Running Ubuntu 19.10 on my desktop and this is not true, but during the OS installation process you are given options to install snaps. If you told it that it was going to act as an MQTT broker (one of the options) then it installed Mosquitto. It is not, however, installed by default.

apt is not aware of applications installed with snap and vv. This made troubleshooting difficult in the last weeks ;-(

Did I miss something that would have made this journey easier?