Home Assistant MQTT Install and Setup - A Beginner's Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another tech tutorial tuesday the series where you guys ask questions and i do my best to answer them as quickly and efficiently as possible and today we are going to be talking about mqtt and mqtt may be something you've heard about if you've been into smart home products for a little while or this may be the first time you're hearing about it but mqtt is found in a wide range of applications you can find it in commercial products such as the shelly range of devices or even some security cameras have mqtt support or you can find it in open source projects such as esp home or tasmota or openhab or home assistant and you can also find it in more diy projects such as um my fingerprint sensor my diy fingerprint sensor i used mqtt and also my diy bed sensor uses mqtt as well so you can find mqtt in a wide range of places so today we're going to be talking about what exactly mqtt is how to install it and how to configure it so that is what is coming up in today's video but if you like this video make sure to drop a like and get subscribed if you aren't already and if you want your question answered in the next tutorial tuesday make sure to drop it in the comments box down below and you never know i might just answer it mqtt or message queueing telemetry transport is an extremely lightweight way of exchanging messages between devices making it extremely popular for smart home or other iot products where bandwidth is more limited mqtt uses a publish and subscribe model in order to transmit data and there are three main elements to mqtt you have an mqtt broker a client and a topic an mqtt broker receives all transmitted messages and it's responsible for routing those messages to the correct clients a client is usually an endpoint device and these publish or subscribe to topics that they are interested in in order to transmit but also receive data a topic is as mentioned what the client publishes or subscribe to and any message published to a topic is received by all other subscribers of that topic a topic can be split up into individual levels in order to better organize them and this is usually done by including a forward slash in the topic name for example we could have two devices one light sensor and one light bulb and our light bulb is subscribed to a topic called slash bedroom slash light meaning it's sitting there waiting to receive messages our light sensor is programmed that's when it falls below a certain light threshold it will publish an on message to the slash bedroom slash light topic where it is picked up by our light bulb and the light bulb will turn on clients can be subscribed to but also published to multiple topics simultaneously and the broker will handle all of the routing quality of service or qos is likely something you will come across when using mqtt and also something you will likely want to configure and there are three levels of qos a qos of level zero is also called fire and forget and this is where there is no guarantee that your message will actually be delivered a qos of level one is called at least once and this is where your message is guaranteed to be delivered at least once but also it could be received multiple times this generally isn't an issue for a lot of devices but it is something to be aware of finally a qos of level two is where your message is guaranteed to be delivered once and only once qos of level 0 is generally the fastest one and a qos of level 2 is the slowest method however this speed issue isn't generally a problem until you get into much larger networks where there are hundreds or even thousands of devices all talking at once this is a very oversimplified explanation of mqtt and how it works i didn't want to over complicate things at this point however if you're interested in more about how mqtt works and the inner workings then the hookup has done a much deeper dive into the inner workings of mqtt and you can find that linked up here now that we've briefly covered how mqtt works let's jump into home assistant and we're going to install the mosquito broker add-on from the supervisor store i know that some of you don't have access to the supervisor store so i'm going to leave a link in the description of a written guide that i did almost a year ago about how to install a mosquito broker um from the command line on linux and you can follow that i've done it for every almost every distro so if you follow the link in the description if you don't have access to supervisor store then you can find out how to install um a mosquito broker on your installation for everyone else let's jump into home assistant in home assistant head over into the supervisor store and add-ons and find the mosquito broker add-on and then hit the install button once installed you're going to want to make sure the watchdog option is ticked and the auto update is off this could be a critical component of your setup so you want to make sure it's always up and available then hit the start button and the mosquito broker will fire up now we need to set credentials that will be used to authenticate with the mqtt broker and there are a few ways of handling the credentials of the mosquito add-on within home assistant you can use the auto-generated credentials you can create a login within the add-on configuration or you can create a user within home assistant specifically for mqtt which is the one i will show you how to do you can use any of your home assistant users in order to authenticate with the broker but i would strongly recommend creating a specific user just for that purpose head over to configuration and then users and add a new user i'm calling mine mqtt user make sure to set a nice secure password here too this user does not need to be an administrator for this purpose once the user is created i would recommend restarting your home assistant so that the auto discovery kicks in once it comes back up you should have a notification saying that a new add-on was discovered click on the link and you should have the mqtt broker auto discovered for you if you don't have auto discovery enabled then simply add it from the list of integrations instead click on configure then submit to add the mqtt broker integration and then hit configure again and click reconfigure mqtt so that we can reset the credentials used for the broker change the username to the username we set earlier mqtt-user in my case and then set the password and hit submit on the next page you'll have some options for configuring the birth and last will messages these are essentially mqtt topics to configure for when the broker starts up and also shuts down you can just leave these as their defaults unless you need to configure them for something click on submit and then finish to save we can then give our broker a little test just to make sure everything is working back on the configure page you'll see these options for listen to a topic and publish this is the first sort of glimpse at that publish and subscribe model i mentioned earlier this page is very useful for debugging mqtt messages so make sure to remember it's there for the future but for now let's test the broker we can listen for any topic in the bottom box and then in the top box we can publish a message to that topic and you'll see it instantly appears in the bottom box i know this might seem like a very cheap trick because it's the same server that's publishing and also listening but you get the idea and this is how it works exactly the same for any of the sensors that you will configure you can also listen to wild card topics using the hash symbol if i change my topic like this and then i can listen to any events after my wild card symbol this is a great place to play around and test out topics so that you can get your head around that whole concept let's very quickly take a look at a real world example and how you can configure mqtt on a client device i'm using a shelley device for this purpose and for this test but you should be able to take this exact same principles and apply them to your mqtt device so over in my shelly settings in the advanced settings drop-down i have the option to enable and configure an mqtt server in the username box i enter the username of the user we created earlier in home assistant so mqtt dash user and set my password in the server box you'll want to type in the ip address or host name of your home assistant server followed by port 1883 you can also configure other options like retain and qos if you need them and hit the save button and now if we head back to home assistant and listen to all topics using the wildcard option i mentioned earlier we can trigger the shelley and watch the mqtt messages appear in home assistant and we can view the topic and the message this information here is all the information you need to go and create an mqtt switch or sensor in home assistant another excellent tool for discovering mqtt topics and also discovering all the information you need in order to use it in home assistant is called mqtt explorer and this can help you expand mqtt topics to find the exact information you need so yeah i definitely recommend mqtt explorer if you need help with mqtt topics and that is pretty much all you need to know for getting started with mqtt and an mqtt broker on home assistant so we went over exactly what mqtt is how to install the mosquito broker add-on on home assistant and how to configure a client for mqtt and also how to listen for topics but that is why all the time we have for this video hope you guys enjoyed it let me know in the comments down below what you thought of this video as well as your suggestions for the next tech tutorial tuesday if you want to support the channel you can do so by becoming a patron on patreon and your support allows me to keep on making these videos thank you to all my current patreon supporters your support is very much appreciated make sure to drop this video a like if you haven't already get subscribed and i will see you in the next one
Info
Channel: Everything Smart Home
Views: 238,374
Rating: undefined out of 5
Keywords: home assistant mqtt, home assistant mqtt broker, home assistant mqtt setup, home assistant mqtt install, home assistant mqtt integration, home assistant mqtt addon, home assistant mosquitto, mqtt, smart home mqtt, mqtt smart home, shelly mqtt, home assistant shelly, home assistant shelly mqtt, shelly home assistant, shelly home assistant mqtt, home assistant, home automation, home assistant mqtt publish, home assistant mqtt subscribe
Id: dqTn-Gk4Qeo
Channel Id: undefined
Length: 10min 43sec (643 seconds)
Published: Tue Mar 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.