Home Assistant - Install MQTT (Part 2)

Home Assistant - Install MQTT (Part 2)
Photo by Alexander Sinn / Unsplash

Okay, assuming you've got Home Assistant installed and working, lets install the MQTT message broker. This is the heart of the system used for communicating messages and data between the IoT devices and the Home Assistant system.

First open the "Settings" from the bottom left and select "Add-ons".

Here we can see the add-ons that installed, at the minute we've not installed anything so lets get started by opening the "Add-On Store" which is at the bottom right of the page.

We want to install the MQTT broker, this is the service that will be responsible for recieving and sending all the messages between devices. Use the search and look for MQTT which should then give you the option to select "Mosquitto broker", which is very simple to get working out of the box.

If you click on it, on the next page there is an option to "INSTALL", click it and give it a few minutes to download and install the service.

Once complete, a few more options will appear along the top naviation bar, the one we are going to is "Configuration"

We're going to add a user here for the IoT devices to connect to the MQTT broker with. This isnt strictly required as you can use a Home Assistant user, but I feel an account dedicated for MQTT gives better isolation.

I'm adding a user here called 'mqtt_user' with a password of 'Password1234!'.

This is yaml formatted text, the indentation and number of spaces used is very specific and will not work if not correctly done.

- username: mqtt_user
  password: Password1234!
  

Then hit the save button at the bottom and switch back to the "Info" menu tab at the top. We can now start the MQTT service by clicking on "START". It should refresh and the circular status indicator top right is green to indicate the service is running.

Now lets test we can connect and monitor what is happening inside the Mosquitto broker. For this we're going to install MQTT Explorer http://mqtt-explorer.com/.

Once downloaded and installed you will be asked to setup a connection when you open the application.

Fill out the information for the host, username and password - I assigned my Home Assistant a static IP of 192.168.10.41 earlier, so I will use this, replace with your IP and change any other details from the example as you configured earlier.

Name: 192.168.10.41
Host: 192.168.10.41
Username: mqtt_user
Password: Password1234!

Save the settings and then connect to the MQTT broker running on Home Assistant.

We should see the server IP and then the topics that have had messages published to them, we can expand the $SYS topic to see some basic stats.

Good, we've got a connection and the broker is working, with this prerequisite we can move on.

For the IoT devices, we're going to use some ESP based devices, described by Wikipedia as :

The ESP8266 is a low-cost Wi-Fi microchip, with built-in TCP/IP networking software, and microcontroller capability, produced by Espressif Systems.
ESP32 is a series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth.

To get things up and running quickly we're going to use Tasmota https://tasmota.github.io/docs/.

Tasmota is an open source firmware for Espressif ESP8266, ESP32, ESP32-S or ESP32-C3 chipset based devices created and maintained by Theo Arends.

We also need to configure Home Assistant MQTT client, this is how Home Assistant picks up and sends the messages from/to the MQTT broker service we've just setup.

In 'Settings', open 'Devices and Services' and MQTT should be listed as 'Discovered'. Click on 'Configure'. It should automatically configure itself.

Check out part 3 and we'll get Tasmota working on an ESP and Home Assistant with communication and the ability to control devices and send and receive sensor data.