I’ve been experimenting with Home Assistant (a home automation server) running the Raspberry Pi and have found the videos from Ben at BRUHautomation to be a big help. One thing I was having trouble with was getting MQTT to control both my sonoff outlets and track my devices. Home Assistant can apparently only use one MQTT Broker at a time. Ben uses Mosquitto when setting up the Sonoff outlets, but CloudMQTT when using Owntracks to track devices.
To get them both working at the same time with Home Assistant you have to join the two using a bridge. This thread helped but the steps I needed weren’t very clearly posted and summarized. Here is what I did that seems to work.
- Follow Ben’s video to setup Mosquitto MQTT and CloudMQTT (in that order).
- You’ll end up with your configuration.yaml file using CloudMQTT as its broker (we will later change this below).
- On the command line on your server, kill mosquitto, and then edit the /etc/mosquitto/mosquitto.conf file so it looks like this:
- Here’s a screen shot of CloudMQTT where you get the user and passwords for above:
- After editing start mosquitto. Note that I’ve commented out the log as that will force any debugging to output to the screen.
- Now, edit Home Assistant’s configuration.yaml and delete or comment out the the CloudMQTT broker under the mqtt section. Add Mosquitto as the mqtt broker:
- Restart Home Assistant:
- That’s it. Navigate to your Home Assistant control panel and test your local devices and your Owntracks tracking. It should all work.
# Place your local configuration in /etc/mosquitto/conf.d/
# A full description of the configuration file is at
#log_dest file /var/log/mosquitto/mosquitto.log # <--- commented out for debugging purposes only, uncomment once you get bridge set up
address <mqtt subdomain>.cloudmqtt.com:<SSL Port No> #<---1 and 2 (See screenshot below corresponding to numbers)
topic # in
remote_username <CloudMQTT_Instance_User_Name> #<-----3 (See screenshot below corresponding to numbers)
remote_password <CloudMQTT_Instance_Password> #<---- 4 (See screenshot below corresponding to numbers)
remote_clientid <User of Instance That has Read Access> #<----- 5 (See screenshot below corresponding to numbers)
local_clientid [Use Same as Cloud MQT ClientId] #<------ 5 (See screenshot below corresponding to numbers)
sudo -u mosquitto mosquitto -c /etc/mosquitto/mosquitto.conf -v
Hopefully you’ll see something like this (rather than errors such as connection refuse, unauthorized, etc:
broker: [IP of Home Assistant]
client_id: [any name]
username: [mosquitto username]
password: [mosquitto password]
If you don’t restart, some of your devices may work but not all. Also, if you are still having issues of inconsistent response (e.g., I had one light respond well, but the other one wouldn’t go off), go to the command line make sure you are not running more than one instance of Home Assistant (pps aux | grep hass) – and if you are kill all of them and start only one instance.