What it MQTT?
MQTT is a kind of secure machine-to-machine message protocol that is made for the internet of things (IoT). For MQTT to work you need to have a computer running as an MQTT Broker and all other devices connect to that computer as an MQTT Client.
MQTT Clients can Subscribe to a Feed on the MQTT Broker and will receive an update if the content of the Feed it is Subscribed to changes. Publishing to a Feed is also allowed by the MQTT Client and the MQTT Broker will pass that published data along to any device that is Subscribed to that particular Feed. Any MQTT Client can Subscribe and Publish to a Feed, but they can also just Subscribe or Publish depending on what your device needs to do.
Adafruit.io hosts an MQTT server, as do many other companies, and they work very well for testing out devices or creating global networks of devices. However, these servers typically have Feed limits or subscription fees that may not always jell with what you want to do.
So why not run your own MQTT Broker using Mosquitto? It is not quite as powerful as Adafruit.io, but it works just as well for most non-industrial projects. Plus it is free and secure.
Install Mosquitto Broker
From the Menu, click Hass.io
Go to the ADD-ON STORE
From the ADD-ON STORE, click on Mosquitto broker.
Add the following text to the Config text box.
{ "logins": [ { "username": "yourMQTT", "password": "yourMQTTpass" } ], "anonymous": false, "customize": { "active": false, "folder": "mosquitto" }, "certfile": "fullchain.pem", "keyfile": "privkey.pem", "quiet_logs": true }
Change the username and password to whatever you want to use for connecting to the MQTT Broker.
Click on SAVE to save your new settings.
Now press START to start your new MQTT Broker.
Click on the Configuration menu.
Select Integrations from this menu.
You should see a list of devices waiting to be set up.
If you see MQTT in this list, click CONFIGURE. If MQTT is not in the list, go to Configuration -> General -> RESTART. Once reconnected, go back to Integrations and MQTT should be there.
Click SUBMIT
Click FINISH
You now have your own MQTT server linked to the Home Assistant server. From any MQTT client, you can interact with feeds using the Home Assistant IP address as the Host and the MQTT Username and Password that you set up.
This will only work within your local network unless you use Port forwarding using the MQTT port to point internet traffic to your Home Assistant IP address. I do not recommend this unless you have some experience with network administration as it could pose a security risk if not set up properly.
Text editor powered by tinymce.