Skip to main content
Smart Home

Setting Up MQTT Broker for Home Assistant

Guide to installing and configuring MQTT Broker to connect IoT devices with Home Assistant

SmileX

SmileX

Founder & CEO

1 min read
Setting Up MQTT Broker for Home Assistant

Why Use MQTT?

MQTT (Message Queuing Telemetry Transport) is a lightweight and efficient protocol for communication between IoT devices, especially in the smart home.

Installing the Mosquitto MQTT Broker

Terminal window
docker run -d \
--name mosquitto \
-p 1883:1883 \
-p 9001:9001 \
-v /path/to/config:/mosquitto/config \
-v /path/to/data:/mosquitto/data \
-v /path/to/log:/mosquitto/log \
eclipse-mosquitto

Configuration File

mosquitto.conf
listener 1883
allow_anonymous false
password_file /mosquitto/config/passwd
# WebSocket support
listener 9001
protocol websockets

Connecting to Home Assistant

Configuration in configuration.yaml

mqtt:
broker: 192.168.1.100
port: 1883
username: homeassistant
password: your_password

Creating an MQTT Sensor

sensor:
- platform: mqtt
name: "Living Room Temperature"
state_topic: "home/livingroom/temperature"
unit_of_measurement: "°C"
device_class: temperature

Creating an MQTT Switch

switch:
- platform: mqtt
name: "Garden Light"
command_topic: "home/garden/light/set"
state_topic: "home/garden/light/state"
payload_on: "ON"
payload_off: "OFF"

Conclusion

MQTT is at the heart of a modern smart home system. Proper configuration helps the system run reliably and securely.

Share:
SmileX

About the Author

SmileX

Founder & CEO

Founder of RACKSYNC with 14+ years of experience in IoT, Cloud Infrastructure, and Smart Home solutions.