How to Set Up a Mosquitto MQTT Bridge to EMQX Cloud with Home Assistant
If you’re integrating Home Assistant with EMQX Cloud using the Mosquitto MQTT broker and facing difficulties, this guide is for you. We’ll walk through the process step-by-step to establish a secure and reliable connection using MQTT version 5.0.
Prerequisites
- A running instance of Home Assistant with Mosquitto broker add-on installed.
- An account with EMQX Cloud and a deployed MQTT service.
Step 1: Preparation
First, ensure your Mosquitto broker is up and running in Home Assistant. You’ll also need to access your EMQX Cloud console to obtain your MQTT service details, including the address, username, and password.
Step 2: Download the EMQX CA Certificate
For a secure TLS connection, download the CA certificate from your EMQX Cloud console. This certificate is crucial for verifying the identity of the EMQX server.
Step 3: Create Configuration File
On your server running Home Assistant, navigate to the /share/mosquitto/
directory. Here, create a new file named emqx.conf
. This file will contain the bridge configuration.
Step 4: Configure the Bridge
Open the emqx.conf
file and insert the following configuration, replacing placeholders with your actual data:
plaintextCopy code# Bridge to EMQX configuration
connection homeass903
address <yoursecret>.emqxsl.com:8883
remote_username <Your_EMQX_Username>
remote_password <Your_EMQX_Password>
bridge_cafile /ssl/emqxsl-ca.crt
bridge_insecure false
bridge_protocol_version mqttv50
bridge_tls_version tlsv1.2
topic esp32cloud/# in 0
Make sure to replace <yoursecret>
, <Your_EMQX_Username>
, and <Your_EMQX_Password>
with your actual EMQX Cloud MQTT service address, username, and password, respectively.
Step 5: Place the CA Certificate
Move the downloaded CA certificate to the /ssl/
directory on your server and rename it to emqxsl-ca.crt
. This path must match the bridge_cafile
in your configuration.
Step 6: Restart Mosquitto Broker
After saving your configuration, restart the Mosquitto broker to apply the changes. You can do this from the Home Assistant interface or by using the command line, depending on your setup.
Step 7: Verify the Connection
Once the Mosquitto broker restarts, check the logs to confirm a successful connection to EMQX Cloud. If you encounter any issues, verify your configuration for any typos or incorrect settings.
Conclusion
By following these steps, you’ve bridged your Home Assistant’s Mosquitto MQTT broker to EMQX Cloud using MQTT version 5.0, allowing secure and reliable communication between your devices and services.
This setup enhances your smart home’s capabilities by leveraging the power of EMQX Cloud, ensuring a scalable and robust MQTT service for your IoT projects.