--- layout: page title: "MQTT Brokers" description: "Instructions on how to setup MQTT brokers for Home Assistant." date: 2015-08-07 18:00 sidebar: true comments: false sharing: true footer: true logo: mqtt.png --- The MQTT component needs you to run an MQTT broker for Home Assistant to connect to. There are four options, each with various degrees of ease of setup and privacy. ### {% linkable_title Embedded broker %} Home Assistant contains an embedded MQTT broker. If no broker configuration is given, the [HBMQTT broker](https://pypi.python.org/pypi/hbmqtt) is started and Home Assistant connects to it. Embedded broker default configuration: | Setting | Value | | -------------- | ----- | | Host | localhost | | Port | 1883 | | Protocol | 3.1.1 | | User | homeassistant | | Password | Your API [password](/components/http/) | | Websocket port | 8080 | ```yaml # Example configuration.yaml entry mqtt: ```
There is an issue with the HBMQTT broker that can cause a memory leak (slowly increasing used memory). This causes an unstable system after the memory is full. You could measure/monitor this with a system monitor. The issue is from 2016 and could already be resolved with newer versions. Use another broker when you experience this issue, for example, Mosquitto.
Issue with the HBMQTT broker: https://github.com/beerfactory/hbmqtt/issues/62
System monitor: https://www.home-assistant.io/components/sensor.systemmonitor/
There is an issue with the Mosquitto package included in Ubuntu 14.04 LTS. Specify `protocol: 3.1` in your MQTT configuration to work around this issue. If you get this error `AttributeError: module 'ssl' has no attribute 'PROTOCOL_TLS'` then you need to set `tls_version: '1.2'`.
If you are running a Mosquitto instance on the same server as Home Assistant then you must ensure that the Mosquitto service starts before Home Assistant. For a Linux instance running Systemd (Raspberry Pi, Debian, Ubuntu and others) then you should edit the file /etc/systemd/system/home-assistant@homeassistant.service as root (e.g., sudo nano /etc/systemd/system/home-assistant@homeassistant.service) and add the mosquitto service: ``` [Unit] Description=Home Assistant After=network.target mosquitto.service ```
If you are running a Mosquitto instance on a different server with proper SSL encryption using a service like Let's Encrypt you may have to set the certificate to the operating systems own `.crt` certificates file. In the instance of Ubuntu this would be `certificate: /etc/ssl/certs/ca-certificates.crt`
### {% linkable_title Public broker %} The Mosquitto project runs a [public broker](http://test.mosquitto.org). This is the easiest to set up, but there is no privacy as all messages are public. Use this only for testing purposes and not for real tracking of your devices or controlling your home. ```yaml mqtt: broker: test.mosquitto.org port: 1883 or 8883 # Optional, replace port 1883 with following if you want encryption # (doesn't really matter because broker is public) port: 8883 # Download certificate from http://test.mosquitto.org/ssl/mosquitto.org.crt certificate: /home/paulus/downloads/mosquitto.org.crt ``` ### {% linkable_title CloudMQTT %} [CloudMQTT](https://www.cloudmqtt.com) is a hosted private MQTT instance that is free for up to 10 connected devices. This is enough to get started with for example [OwnTracks](/components/device_tracker.owntracks/) and give you a taste of what is possible.Home Assistant is not affiliated with CloudMQTT nor will receive any kickbacks.
1. [Create an account](https://customer.cloudmqtt.com/login) (no payment details needed) 2. [Create a new CloudMQTT instance](https://customer.cloudmqtt.com/subscription/create) (Cute Cat is the free plan) 3. From the control panel, click on the _Details_ button. 4. Create unique users for Home Assistant and each phone to connectHome Assistant will automatically load the correct certificate if you connect to an encrypted channel of CloudMQTT (port range 20000-30000).