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.
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
#log_dest file /var/log/mosquitto/mosquitto.log # <--- commented out for debugging purposes only, uncomment once you get bridge set up allow_anonymous false password_file /etc/mosquitto/pwfile listener 1883 listener 8883 connection cloudmqtt address .cloudmqtt.com: #<---1 and 2 (See screenshot below corresponding to numbers) topic # in start_type automatic remote_username #<-----3 (See screenshot below corresponding to numbers) remote_password #<---- 4 (See screenshot below corresponding to numbers) remote_clientid #<----- 5 (See screenshot below corresponding to numbers) local_clientid [Use Same as Cloud MQT ClientId] #<------ 5 (See screenshot below corresponding to numbers) keepalive_interval 300 cleansession true bridge_protocol_version mqttv311 bridge_cafile /etc/ssl/certs/ca-certificates.crt bridge_insecure false [/crayon]
Hopefully you’ll see something like this (rather than errors such as connection refuse, unauthorized, etc:
mqtt:
broker: [IP of Home Assistant]
port: 1883
client_id: [any name]
username: [mosquitto username]
password: [mosquitto password]
[/crayon]
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.
Avoiding Browser Plugins with KeePassXC KeePassXC is a popular free open source password manager. As…
If you've had a Gmail account for years, like I have, at some point you…
Here's a little trick I use to back up my Raspberry Pi without having to…
I try to keep my email inbox fairly clean but I do subscribe to some…
I was recently faced with the dreaded prospect of re-installing Windows 10. While the standard…
Pi-Hole and Upstream DNS Providers Pi-hole is an excellent whole-home, self-hosted ad blocker and DNS…