Categories: Home Automation

Getting Home Assistant, Mosquitto MQTT, and CloudMQTT To Work Together Using an MQTT Bridge

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.

  1. Follow Ben’s video to setup Mosquitto MQTT and CloudMQTT (in that order).
  2. You’ll end up with your configuration.yaml file using CloudMQTT as its broker (we will later change this below).
  3. On the command line on your server, kill mosquitto, and then edit the /etc/mosquitto/mosquitto.conf file so it looks like this:
  4. [crayon]

    # 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 # .cloudmqtt.com: # # # #Here’s a screen shot of CloudMQTT where you get the user and passwords for above:

  5. After editing start mosquitto. Note that I’ve commented out the log as that will force any debugging to output to the screen.
  6. [crayon] sudo -u mosquitto mosquitto -c /etc/mosquitto/mosquitto.conf -v
    [/crayon]

    Hopefully you’ll see something like this (rather than errors such as connection refuse, unauthorized, etc:

  7. 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:
  8. [crayon]

    mqtt:
    broker: [IP of Home Assistant] port: 1883
    client_id: [any name] username: [mosquitto username] password: [mosquitto password] [/crayon]

  9. Restart Home Assistant:
  10. 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.

  11. That’s it. Navigate to your Home Assistant control panel and test your local devices and your Owntracks tracking. It should all work.
Charlie

Recent Posts

Need to Move Your Router’s Existing DHCP IP Reservations to A New Router ? Try Uproot – a Static Lease Conversion Utility

I just released a new open source project on github called Uproot. What is Uproot…

3 months ago

Keyboard Browser Navigation Nirvana – Must Have Tools for Keyboard Ninjas

Keyboard Shortcuts Recently I've been coding quite a bit (working on a dart command line…

4 months ago

Using pfSense on VirtualBox for Windows using only One Virtual Machine

pfSense on VirtualBox I've been experimenting with pfSense (firewall software you can use for DIY…

5 months ago

Firefox – Where did my pinned tabs go ?

Firefox Pinned Tabs Firefox provides the ability to "pin" a tab, so it stays in…

5 months ago

Creating a Shortcut to Windows Terminal (Or Any Other App That Doesn’t Show Shortcut Option)

Weirdly, Windows Terminal does not allow you to create a shortcut - there's no obvious…

9 months ago

Simplest Wireguard Setup Ever

Wireguard Wireguard is the newest way to setup a VPN for your home servers. What…

10 months ago