How To Choose an MQTT Broker
One of the core components of a home automation system is the MQTT broker. MQTT is a messaging protocol that allows devices to communicate with each other. It is a lightweight protocol that is designed to be used on low-powered devices. It is also designed to be used in environments where there is a lot of network traffic, such as a home automation system.
There are many MQTT brokers available. You can install any MQTT broker that you want, and all of your MQTT compatible devices will work just fine.
The only real difference in MQTT brokers comes down to the features that they offer. Some brokers offer more features than others, and some brokers are easier to use than others.
Three of the most popular MQTT brokers are: Mosquitto, HiveMQ, and Home Assistant.
Mosquitto MQTT Broker
Mosquitto is, by far, the most popular MQTT broker. It is a lightweight, open-source, and easy to use MQTT broker. Mosquitto is written in C and is available for Linux, Windows, and Mac OS X. It is also available in almost every package manager, as well as a Docker container.
Installing Mosquitto on your Home Automation network is very easy. If you run Unraid, then you can simply install it from the Community Applications.
Mosquitto is probably the best choice for an MQTT broker on your home automation network. Once you get it running, it's pretty much self-maintaining. You can use the Mosquitto command line tools to monitor the broker and to publish and subscribe to topics.
If you are running a NAS, then you can install Mosquitto using the built-in package manager for your NAS. For example, on a Synology NAS, you can install Mosquitto using the Synology Package Center.
It is also available in the Docker Hub, so you can install Mosquitto using the Docker CLI or docker-compose.
HiveMQ-CE
HiveMQ is a big company with a big website. They seem to be interested in big business to business interaction more than small, community-based hackers.
With that said, they do offer a free version of their product called HiveMQ-CE. HiveMQ-CE is available in a docker container that you can run on any Linux machine. It's easy to get running, but it seems to be lacking in customization options.
Our suggestion for home users is that HiveMQ-CE is probably not the right choice. Unless you are planning on rolling out an enterprise grade MQTT solution, you are probably better off with Mosquitto.
The biggest problem with HiveMQ-CE is that it doesn't seem to offer many customization options. While you can change the port that it runs on via the docker command, you can't change the default username and password, and you can't enable encryption. There also doesn't appear to be any sort of bridging options. It's a very basic broker that is easy to get running, but it doesn't seem to offer much in the way of customization.
Home Assistant Add-On: Mosquitto Broker
Home Assistant has deep MQTT integration, and most Home Assistant users end up running some form of MQTT broker. As a result, there is an integrated Home Assistant MQTT broker.
If you are using Home Assistant, then you might be tempted to use the Home Assistant Add-on called Mosquitto. This will set up a running Mosquitto instance configured in your standard Home Assistant config files.
While this does install Mosquitto on your Home Assistant server, it comes with a couple of downsides.
To start with, the configuration for Mosquitto inside Home Assistant has a bit of a split personality, with some configuration settings existing in your Home Assistant configuration files, and some configuration being in the Mosquitto configuration files, that are referenced in the Home Assistant configuration files.
It very quickly gets challenging to maintain your MQTT broker inside Home Assistant. Especially if you attempt to add any form of access control and authentication to your MQTT server.
If you want Mosquitto, then you are probably better off installing Mosquitto in a docker or simply as an operating system service. This will give you much more control over your MQTT broker, and you will be able to configure it in a way that is much more standard.
In addition, when you use the Home Assistant add-on, every time you restart Home Assistant, your MQTT broker will be restarted. This can cause some issues with your MQTT clients. It's better to have your MQTT broker and Home Assistant instance de-coupled.
How to Set Up an MQTT Broker
Choosing an MQTT broker is one of the early decisions you will make when you start your Home Automation journey. It's a decision that will have a big impact on your home automation network's reliability and performance.
Of the options I have looked at, I recommend Mosquitto. It's easy to install, easy to configure, and easy to maintain. It's also the most popular MQTT broker, so you will have the most support available if you run into any issues.
Now that you have an idea of the different MQTT brokers available, it's time to set up your own MQTT broker.