Connect with Home Assistant
In recent years, as people's demand for home security, convenience, comfort and artistry has increased, home automation has become more and more popular. Home Assistant, a popular open-source home automation platform, provides a secure and convenient central control system. In this article, we will introduce you how to use EMQX Cloud MQTT Broker to connect with Home Assistant.
Prerequisites
Before connecting your Home Assistant to the EMQX Cloud, ensure you have deployed an MQTT broker.
Deploy MQTT Broker
To connect your application to the EMQX Cloud, you need to create and configure a deployment.
Serverless Deployment
Create a Serverless deployment in the EMQX Cloud Console.
Once the deployment is created and running, go to the deployment Overview page to find the MQTT connection information, including:
Broker address
Port number (only TLS ports are supported in Serverless)
Serverless deployments require TLS connections. Make sure to download the CA certificate from the Overview page and use port
8883for TLS.Configure the default authentication (username/password) under Access Control -> Client Authentication in the deployment.
For more details, refer to the Serverless Port Guide.
Dedicated Flex or BYOC Deployment
- You can create a Dedicated Flex or BYOC deployment in the EMQX Cloud Console.
- After creation, go to the deployment Overview page to retrieve MQTT connection information, including:
- Broker address
- TCP and TLS port numbers for MQTT and WebSocket (Both TCP and TLS connections are supported).
- Configure the default authentication (username/password) under Access Control -> Client Authentication in the deployment.
For detailed port configurations, see the Dedicated & BYOC Port Guide.
Home Assistant Initialization
If you are using MQTT for Home Assistant for the first time, please refer to the quick start.
Install Home Assistant
In this example, we use Docker to quickly install Home Assistant.
bashdocker run -d --name="home-assistant" -v /opt/homeassistant/config:/config -p 8123:8123 homeassistant/home-assistantThen access the Home Assistant service via the local IP with the corresponding port, e.g., x.x.x.x:8123, to create an account.

Enable advanced mode (optional)
Advanced broker options are accessible only when advanced mode is enabled, such as MQTT features, Websocket, and TLS/SSL verification.

Add Integration
Go to Home Assistant's settings, choose
Devices & Services.
Click
+ Add Integrationand fill in MQTT.
Then you could enter the
Connection informationfor the broker.
Connect over TCP Port
This section describes how to connect a homeassistant client to MQTT broker over TCP port.
MQTT connection
- Fill in the broker address, port, username and password (if it exists).
- Select
TCPfor MQTT transport.

WebSocket connection
- Fill in the broker address, port, username, and password (if they exist).
- Select
WebSocketfor MQTT transport and fill in the WebSocket path as/mqtt.

Connect over TLS/SSL Port
This section describes how to connect a homeassistant client to MQTT broker over TLS/SSL port.
MQTT over TLS/SSL connection
- Fill in the broker address, port, username, and password (if they exist).
- Select
Autofor broker certificate verification. - Select
TCPfor MQTT transport.

WebSocket over TLS/SSL connection
- Fill in the broker address, port, username, and password (if they exist).
- Select
Autofor broker certificate verification. - Select
WebSocketfor MQTT transport and fill in the WebSocket path as/mqtt.

Test Connection
After filling in the connection information, click the Submit button. Your EMQX Cloud deployment is now integrating with Home Assistant. Congratulations!

Click Configure to complete the publish or subscribe topic.
