What You'll Learn

What You'll Need

What You'll Build

Watch this video to follow along at each step:

Home Assistant is a popular open-source home automation platform that provides a unified interface to control and monitor different smart devices. Instead of juggling separate apps for different brands, you can manage everything through a single Home Assistant web dashboard on a local server like Raspberry Pi.

We've previously explored Home Assistant's WebSocket API using Postman. Now let's delve into Home Assistant's MQTT integration, used by 44% of all active installations, to access smart devices across your connected home.

REST, WebSockets, and MQTT for connected home

When it comes to transmitting data in a connected home environment, REST, WebSockets, and MQTT are commonly used protocols, but for different use cases.

In the next section, let's try using MQTT with Home Assistant for home automation.

  1. Create a new user: In the Home Assistant dashboard, under Settings > People, create a new user (or Person) to log in and access Home Assistant. Make a note of the username and password for the new user, since we will use those credentials to configure our MQTT devices and authorize our MQTT messages. create new user
  2. Choose an MQTT broker: In this tutorial, we will set up the Mosquitto MQTT broker add-on. Under Settings > Add-ons > Add-on store, find, install, and start "Mosquitto broker". This might take a few minutes. Once the add-on is started, make a note of the Hostname for the next step. mosquitto broker
  3. Add the MQTT integration: On the Integrations page of your Home Assistance dashboard, you might already see an MQTT integration under "Discovery" that you can add. Otherwise, find and add the "MQTT" integration or using this link. You will need Hostname of the broker from Step 2, and username and password from the user created in Step 1. MQTT configuration modal

Fork the Postman collection

  1. Find the sample collection in Postman, Home Assistant MQTT, and fork the collection to your own Postman workspace. fork icon
  2. Enter a label for your fork and select the workspace to fork the collection: fork label

Authorize API requests

  1. Add variables: Select the collection you just forked into your own Postman workspace, and add your new Home Assistant user credentials under the Variables tab, and Save your updates. save variables
  2. Review authorization details: Notice the variables are used under the Authorization tab of each request in the collection. authorization method

Connect to the broker

  1. Establish a connection: Connect to mqtt://homeassistant.local and observe the connection details reflected on the bottom. This is also where you will see inbound and outbound messages displayed. establish connection
  2. Send a message: Under the Message tab, publish data to a specified topic. For example, try inputting text like "Hello" to the topic everything/smart/home and hit Send. You can also save messages to re-use later on. send message
  3. Subscribe to a topic: Under the Topics tab, subscribe to a topic such as everything/smart/home by switching the toggle on. This means the Postman client is subscribed to receive any data published to that topic. subscribe to topic
  4. Send a second message: Now try sending a different message to the same topic everything/smart/home to see what happens. Postman can send messages, and also receive messages published to the topic that it is subscribed to. This messaging pattern is called publish-subscribe. Notice outbound messages are displayed next to an up arrow, and inbound messages are displayed next to a down arrow. pubsub

If you have a device that communicates over MQTT, you may need to configure the device to enable Home Assistant discovery. Every device and manufacturer is likely to follow a different process, so the following steps are just one example.

  1. Configure Tasmota device: MQTT is the main protocol for controlling Tasmota devices. After you have a working MQTT broker you need to configure Tasmota to communicate with it. tasmota
  2. Control Tasmota device: The Tasmota documentation provides examples of commands we can send over MQTT to control our Tasmota device. We can also save messages to re-use later on. commands

Depending on the response format, you can also select the Visualization tab of the response to show a message stream in a graphical format, a more comprehensible way to view telemetry data. Learn more about the MQTT response.


Watch this video to recap the steps:

What we've covered

For more hands-on tutorials, check out these resources.

Additional resources for Home Assistant

Additional Postman resources