MQTT Broker


The MQTT integration needs you to run an MQTT broker for Home Assistant to connect to.

Run your own

The most private option is running your own MQTT broker.

The recommended setup method is to use the Mosquitto MQTT broker add-on.

There is an issue with the RabbitMQ MQTT Plugin which break MQTT message retention. Don’t use the RabbitMQ MQTT plugin, instead use another broker like Mosquitto.

Configuration

# Example configuration.yaml entry
mqtt:
  broker: 192.168.1.100

Configuration Variables

brokerstring(Optional)

The IP address or hostname of your MQTT broker, e.g., 192.168.1.32.

portinteger(Optional)

The network port to connect to. Default is 1883.

client_idstring(Optional)

The client ID that Home Assistant will use. Has to be unique on the server. Default is a randomly generated one.

keepaliveinteger(Optional)

The time in seconds between sending keep alive messages for this client. Default is 60.

usernamestring(Optional)

The username to use with your MQTT broker.

passwordstring(Optional)

The corresponding password for the username to use with your MQTT broker.

protocolstring(Optional)

Protocol to use: 3.1 or 3.1.1. By default it connects with 3.1.1 and falls back to 3.1 if server does not support 3.1.1.

certificatestring(Optional)

Path to the certificate file, e.g., /ssl/server.crt.

tls_insecureboolean(Optional, default: false)

Set the verification of the server hostname in the server certificate.

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

Public broker

The Mosquitto project runs a public broker. 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.

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

CloudMQTT

CloudMQTT 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 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 (no payment details needed)
  2. Create a new CloudMQTT instance (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 connect
    (CloudMQTT does not allow two connections from the same user)
    1. Under manage users, fill in username, password and click add
    2. Under ACLs, select user, topic #, check ‘read access’ and ‘write access’
  5. Copy the instance info to your configuration.yaml:
mqtt:
  broker: CLOUDMQTT_SERVER
  port: CLOUDMQTT_PORT
  username: CLOUDMQTT_USER
  password: CLOUDMQTT_PASSWORD
Home Assistant will automatically load the correct certificate if you connect to an encrypted channel of CloudMQTT (port range 20000-30000).

If you experience an error message like Failed to connect due to exception: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed, then add certificate: auto to your broker configuration and restart Home Assistant.