I don't understand MQTT

I am doing the $15 DIY multi sensor thing ( https://www.youtube.com/watch?v=jpjfVc-9IrQ ) but I am stuck in the MQTT config part.

The confusion is related to the server/client part. I do not understand which device is server and which is client.

I the video, I can see that in the Arduino code there are several mqtt parameters:

#define mqtt_server “your.mqtt.server.ip”
#define mqtt_user “yourMQTTusername”
#define mqtt_password “yourMQTTpassword”
#define mqtt_port 1883

Then, in Home Assistant, I have this options in configuration.yaml:

mqtt:
broker: your.mqtt.ip.address
port: 1883
client_id: home-assistant-1
username: YOURUSERNAME
password: YOURPASSWORD

I already flashed the Arduino board, and it connects to wifi without any issue, but then I get an error that it can not connect to MQTT.

When I start HomeAssistant I get this error in the home page:

The following components and platforms could not be set up:
mqtt

In my LAN, the Arduino board has 192.168.1.20 and HomeAssistant is 192.168.1.111

How should I configure both configs? I don’t know if I have to put the IP of Home Assistant in the Arduino config, or vice-versa.

Thanks very much.

1 Like

Assuming you have the MQTT server on the PI then put the IP address of the PI as the broker address in HA and the same address as the server IP in the Ardruino, so in your case that would be 192.168.1.111 for both :), since both talk to the broker/server.

Thanks keithh666!

I have done that and I still getting this error en Home Asistant home:

Invalid config

I get this en the log file:

2017-07-20 15:27:28 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)
ConnectionRefusedError: [Errno 111] Connection refused

Since you have followed BRUHs video, you should also follow his video on setting up Mosquitto as that’s what he uses as the broker/server. It looks to me like you are trying to use the internal MQTT broker but you can’t do that with the settings you have put in HA.

What MQTT broker are you using?
The one that’s been easiest for me is emqttd, since it has webUI to check if most things work.

It needs erlang tho, but that’s pretty easy to build from sources anyway.

sudo apt-get update
sudo apt-get install wget
sudo apt-get install libssl-dev
sudo apt-get install ncurses-dev
wget http://www.erlang.org/download/otp_src_20.0.tar.gz
tar -xzvf otp_src_20.0.tar.gz
cd otp_src_20.0/
./configure
make -j 2
sudo make install
cd ..
rm otp_src_20.0.tar.gz
sudo rm -R otp_src_20.0/

And then build emqttd:

git clone https://github.com/emqtt/emq-relx.git
cd emq-relx && make