Need help setting up MQTT broker on HASS.io

Hi All,

I’m completely new to HA and just started using Get Started article, and I’m currently stuck…

Basically, I have an SONOFF RF bridge (flashed with Espurna), some SONOFF PIR2 and SONOFF DW1 sensors, and a Raspberry Pi 3.
My goal is to build a burglar alarm system.

My HA is up and running on RPi and I can ssh into it from my MacBook Pro (OS X 10.11.6).
I added empty mqtt section to configuration.yaml to enable internal MQTT broker, but apparently it’s not working because when I run mosquitto_sub -v -V mqttv311 -t "#"it says Error: Address not available
I tried to install a mosquito server manually (tutorial), but have no luck here as well because it says -bash: command not found for either sudo and apt-key.

What am I doing wrong?
Thanks for your help.

So let’s get this out of the way:

You cannot install things in hassio unless it is in an Add-on. hassio is not ubuntu, it’s not debian. It is not a general OS to do things in.

Secondly,
Have you tried installing the MQTT add-on?

Yes, Mosquitto broker add-on is installed, but in the system log I see
ERROR (SyncWorker_18) [hassio.docker] Can’t start addon_core_mosquitto: 500 Server Error: Internal Server Error (“driver failed programming external connectivity on endpoint addon_core_mosquitto (3836f23d34feeb12bfbfb35c6adfcc075b97f7ff5ddbdbebec9de3fea648bb23): Error starting userland proxy: listen tcp 0.0.0.0:1883: bind: address already in use”)

mosquitto is already running. it appears your home assistant built in broker is working fine.

2 choices:

turn off the built in broker and use the mqtt addon
or
use the built in broker

could you tell me how to test that the broker is working?

by the way, I was able to access http://hassio.local:3218 via configurator add-on, but recently it started showing Policy not fulfilled and I cannot change anything.

Check your configuration.yaml.

If you’ve configured

mqtt:

the internal MQTT broker will be started.

If you added broker like

mqtt:
  broker: THE_BROKER_IP_ADDRESS

an external broker will be used.

As you already installed the Mosquitto Add-On you should keep it and set the broker accordingly.

1 Like

well, initially I added an empty mqtt section to configuration.yaml hoping to be able to test everything in the minimal configuration, but commands like mosquito_sub failed with error messages and I decided to install the Mosquitto add-on.
las time I was able to access and edit my config it was like broker: core-mosquitto
as I saw somewhere in the documentation.
Will try to gain access to the configurator (as it’s currently “Policy not fulfilled”).
And still, how can I make sure a broker is working properly?

Edit: installed and configured Samba add-on, edited config so it has mqtt: broker: 192.168.0.34
Restarted, same error in logs, mosquitto add-on not started.
Was able to access Configurator once, then again “Policy not fulfilled”. Don’t like it… :\

If you added Mosquitto addons to Hassio… then you have to add user and password and start it… then in configuration.yaml add a new section…

mqtt:
  broker: 192.168.1.X
  port: 1883
  username: user
  password: password

where the IP is the IP of your home assistant, and user and password is the same of Mosquitto

1 Like

specified broker’s ip, port, username and password, did “configuration -> Check config, then Reload core” - no difference.

eventually clicked Hass.io -> System -> Reboot and… bingo, the add-on is green, no error messages in the log.

However, when I run mosquitto_sub -h 127.0.0.1 -v -t "homeassistant/#" -u testuser -P mypw it says Error: Connection refused

What’s wrong with it?

From mosquitto’s log:
1520282247: Warning: Mosquitto should not be run as root/administrator.
1520282297: New connection from 192.168.0.34 on port 1883.
1520282297: New client connected from 192.168.0.34 as 4ccc9e7c-2669-4c06-9d39-f5c085a0769b (c1, k60, u’testuser’).

Update: got the result by changing host ip from 127.0.0.1 to the real one:
core-ssh:~# mosquitto_sub -h 192.168.0.34 -v -V mqttv311 -t "#" -u testuser -P mypw home-assistant/switch/1/on Switch is ON

Looks like it’s working now, isn’t it?

Honestly, I’m not sure that using ip addresses in config and commands is a good idea as they are dynamic and everything would break if they are changed.
What is the best practice?

Enter in your router config page and associate a IP address to your raspberry. You need a stable IP.

So the Pi’s ip should be static? Ok, it’s doable :wink:

SSH isn’t running on localhost. You are using containers.

looks like it.

A server’s IP address should never be dynamic.

Static IP addresses on devices that your network relies on. Your router has a static IP…