Moving to a cloud based MQTT service

I'm using home assistant for several years and it happens that I have multiple places I am running home assistant in. Each of them has different hardware and type of installation due to historic reasons but one thing in common is that they all have some degree of MQTT instance running on them, be it Frigate video or Node-red integration or simply hacking tools like GL.Inet BLE things or Mikrotik router statistics.

At some point I was happy to try out managing my own Mosquitto instance on Oracle Cloud (thanks for their always free btw), however, because this was the only thing on that server, Oracle started noticing that it's not too busy and they would shut it down until I start it again. I understand them but it was quite annoying. Then I learned about HiveMQ free cloud MQTT broker and I thought to give it a try.

Home assistant

For one of my HA instances it was very straight forward to just configure the MQTT server. All I needed was to indicate

  • the URL (xxx.hivemq.cloud)
  • the port (8883)
  • username/password (created in HiveMQ console)
  • give it a Client ID
  • leave the default 60s keep-alive
  • not use a client certificate
  • set Auto for Broker certificate validation
  • and leave the rest with default settings

How do you know that it works? If you don't have something like MQTT explorer, go to your home assistant MQTT integration settings and find the section Listen to a topic, enter # in Topic to subscribe to field and hit START LISTENING. If you have any sensors producing events, you will see them coming in.

Mikrotik

I have some stats going on to MQTT that is picked by home assistant. It was all great while having non-ssl mosquitto runing behind overlay network away from others. Now that I want to use HiveMQ, I need mqtts or simply speaking MQTT SSL.

Mikrotik offers a nice menu to configure everything, however, out of the box it doesn't work for HiveMQ. One essential element is the SSL certificate of Let's Encrypt that is probably missing on Mikrotik by default.

Firstly, you'll need to download the trusted certificate from Let's Encrypt and upload it to Mikrotik (I used Files on their app, you can use SCP or other tools). Once uploaded, head to the Certificates section and import it from your Files dropdown. That's it, Mikrotik HiveMQ integration is working.

Node-red

Node-red is not something I needed to use until I inherited a house with Loxone system. It is connected to my heating system and I simply have to use it as it is all wired together unless I want to replace it. That would be just too expensive. I'll write another article about Loxone and Home Assistant integration and its limitations.

Now I of course want node-red and HiveMQ work together so that I can move everything to one place.
Go to your node-red and add a new MQTT broker. Give the usual things like:

  • server (URL), port (8883)
  • check the box for Connect automatically and Use TLS
  • edit the TLS settings - upload the same Let's Encrypt trusted certificate in section CA Certificate, I also have Verify server certificate checked but that's not mandatory and hit Update button for TLS config
  • you're back to your MQTT broker node setup, give your client ID a name and navigate to Security tab to enter username/password that you created in HiveMQ console.
  • hit the Update button again

That's it, your node-red HiveMQ integration should be working.