Connect with OpenHAB
OpenHAB, also known as open Home Automation Bus, is an open-source home automation software written in Java. With the strengths of integrating various devices, providing a clear user interface, and supporting the most flexible tools, openHAB becomes one of the most outstanding platforms in the field of home automation.
With the high flexibility and ease of use, openHAB provides a particular binding for users to connect MQTT Broker. In this article, we will introduce you to the process of setting up the EMQX Cloud MQTT Broker with openHAB.
Prerequisites
Before connecting your OpenHAB application 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.
OpenHAB Initialization
If you are using MQTT for OpenHAB for the first time, please refer to the quick start.
Install OpenHAB
In this example, we use Docker to quickly install OpenHAB.
bashdocker run -d --name=openhab --restart=always --network=host \ -v /opt/openhab/conf:/openhab/conf \ -v /opt/openhab/userdata:/openhab/userdata \ -v /opt/openhab/addons:/openhab/addons \ openhab/openhabThen access the OpenHAB service via the local IP with the corresponding port, e.g., x.x.x.x:8080, to create an account.

Next, you can select language, region, time zone, location of your home. Once configuration is finished, you will be redirected to openHAB console.

Install Bindings
Go to
Settings--->Bingdings--->MQTT Bindingand install MQTT Binding:
Add
MQTT BrokertoThings
Then select
MQTT Brokerand fill in the information of the deployment we created before.
Connect over TCP Port
This section describes how to connect an openhab client to MQTT broker over TCP port.
- Fill in the broker address, port, username and password (if it exists).
- Select
TCPfor MQTT transport.

Connect over TLS/SSL Port
This section describes how to connect an openhab client to MQTT broker over TLS/SSL port.
- Fill in the broker address, port, username, and password (if they exist).
- Enable
Secure Connection. - Select
TCPfor MQTT transport.


Test Connection
Go to Settings ---> Things ---> MQTT Broker, when there is a little green label that says "online", you are successfully connecting openHAB with EMQX Cloud. Congrats!

You can also check the status from the EMQX Cloud's monitor page.
