Run Your own LOCAL MQTT broker to control your IoT devices in Home Assistant

Тәжірибелік нұсқаулар және стиль

In this video I cover setting up an eclipse-mosquitto broker Docker container on a local virtual machine using portainer to do all the heavy lifting. I then integrate it into Home Assistant.
Links:
▶️Dockerhub: hub.docker.com
▶️ Portainer: docs.portainer.io/v/ce-2.9/st...
▶️ MQTT Explorer: mqtt-explorer.com/
Join the channel:
/ @mostlychris
Discord: / discord
If you would like to support me:
Buy me a beverage: ko-fi.com/mostlychris
Become a patron: / mostlychris
Products I reference in my videos (Contains affiliate links)
www.mostlychris.com/my-smart-...
www.xsplit.com?ref=chriswest&discount=mostlychri&pp=stripe_affiliate
DISCLAIMER: Some of the links above take you to affiliate sites that may or may not pay a small commission to me. It doesn't increase the cost to you, but it does help support me in making these videos.
Snail Mail to Send Stuff:
Mostlychris
24165 IH-10 West
STE 217 #164
San Antonio, TX 78257
00:00 Intro
01:12 Why MQTT?
02:30 You Need Portainer
02:55 Create Volumes
04:36 Create the Container
05:41 Container Settings
07:38 Local Only Connections
08:33 Configuration File
09:30 Anonymous Access From any IP
13:03 Restrict Access via Credentials
15:50 Set Device for New Broker
17:17 Configure Home Assistant
18:50 Final Thoughts

Пікірлер: 103

  • @timffoster
    @timffoster6 ай бұрын

    SUBSCRIBED!!! This video is exactly what I needed. (and I especially appreciated that it was no-nonsense, yet chock full of solid explanations, clear speech, large screens and the whole 9 yards)

  • @stevecarlisle3323
    @stevecarlisle3323 Жыл бұрын

    Chris, thanks for your videos, this one helped me get MQTT up and running, where a few other vids did not, looking forward to learning from your other videos.

  • @florianf4818
    @florianf4818 Жыл бұрын

    You are my Hero, thank you! The first path, to select Volumes in Portainer was a great idea!

  • @magnusgreel275
    @magnusgreel275 Жыл бұрын

    Your tutorial helped me finally install MQTT and integrate it with Home Assistant :D Subscribed!

  • @wbtlevi
    @wbtlevi Жыл бұрын

    Fantastic! Thank you. I was able to move my MQTT from inside Home assistant to my portainer setup.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Good job! Thanks for watching!

  • @camerontgore
    @camerontgore2 жыл бұрын

    Hi and great video! Did you ever do the follow up video to build the mqtt entries?

  • @isosahir
    @isosahir2 ай бұрын

    Awsome video, helped a lot. Thanks man!

  • @TheBendixSA
    @TheBendixSA8 ай бұрын

    This was brilliant

  • @lildarker4044
    @lildarker4044 Жыл бұрын

    absolute legend, you made me want to subscribe

  • @jt_simon
    @jt_simon8 ай бұрын

    Hey @mostlychris, another VIM shortcut: If your cursor is at the top of the file in VIM, you can do "d G" (capital G) and it will delete from where the cursor is all the way to the bottom of the file. Conversely, if you're at the bottom of the file you can do "d gg" (2 lowercase g's) and it will delete from the cursor to the top of the file.

  • @mineapple8612
    @mineapple8612 Жыл бұрын

    tysm for this very straight forward and thorough explainantion!

  • @mostlychris

    @mostlychris

    Жыл бұрын

    YW. Thanks for watching.

  • @eric88798
    @eric88798 Жыл бұрын

    Thank you, the video helped me a lot, thumbs up.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Thanks for watching!

  • @shaunwhiteley3544
    @shaunwhiteley35442 жыл бұрын

    I have a pi setup with pihole and mqtt with battery backup. Makes it so much better standalone, no issues with rebooting pc's or dockers etc. Every couple of months (cough) when I remember pihole & pi get updated. Also really good if you want a couple of different home assistant builds etc production & test to connect to.Cheers

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Thanks for the comments.

  • @RailyardProductions

    @RailyardProductions

    Жыл бұрын

    Hi Shaun, Are you running Portainer on that? How is it working out?

  • @shaunwhiteley3544

    @shaunwhiteley3544

    Жыл бұрын

    @@RailyardProductions I have a main pc running unraid for docker,vm's etc and a separate pi running pihole and Mqtt server, works better for me that way

  • @kopparsulfat
    @kopparsulfat Жыл бұрын

    damn good video. explaines everyting i was looking for. 👌

  • @andymok7945
    @andymok7945 Жыл бұрын

    Hi Chris. You have lots of great videos. I am looking at revamping my Home automation setup. Currently running HA in a proxmox VM and will be moving it HA blue device soon. I am also looking at setting up a separate MQTT broker rather then the add-on as I have now. I have so many hobbies and so many projects that keep me quite busy. Is there any reason that I should run MQTT broker in a container rather than in just a VM? Not looking forward at another learning hurdle for portainer/docker stuff if I do not need to at this time. Thanks. Yes I would like to see you make a video in regards what you need to do in HA when using an external MQTT broker as you mentioned in this video.

  • @revealingfacts4all
    @revealingfacts4all Жыл бұрын

    This tutorial was great! I know this video is about a year old as I watch it and am wondering about something. I have MQTT and Tasmota in home assistant and they both can see my new Tasmota/MQTT light switch. The home assistant forums seem to suggest that MQTT is "hard to maintain" and might be going away. Any truth to this? Which should I focus on to continue my integration journey?

  • @sonoff2253
    @sonoff22532 жыл бұрын

    Fantastic video, I expected the integration with Home Assistant at the end. How to activate the mqtt topics in Home Assistant. Can you make another video on this?

  • @user-td6ju5fw4d
    @user-td6ju5fw4d Жыл бұрын

    Hi Chris, i want to know if in ignition from inductive automation, i can configure the mqtt server to enable remote connections, great video thank you!

  • @manologitech
    @manologitech Жыл бұрын

    Very helpful, thank You.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Glad it was helpful!

  • @nigelholland24
    @nigelholland242 жыл бұрын

    Great video thank you

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    You're welcome!

  • @scottb721
    @scottb721Ай бұрын

    I've just done this Portainer process on my Synology NAS. For the MQTT settings in HA do I use my NAS' IP as the broker hostname/IP address ? Thanks

  • @RailyardProductions
    @RailyardProductions Жыл бұрын

    This is awesome, one question though. I'm building an app in MIT App Inventor2 and there is an MQTT extension urspahomqttclient. Are you familiar with that? I have been trying to get the MQTT working and having no luck. I searched around and found an app in which they say you have options of connecting using HIVE/emqt or some other cloud brokers. My app only has to run while I'm at home and on my local network. Do you think this could be the solution?

  • @antshurdley2914
    @antshurdley2914 Жыл бұрын

    Hi Chris - love your videos I have only had HA a week and am loving it, although I admit it is a bit of a steep learning curve. I have now got MQTT going and have also got an esp32 sending data to it in Json format. I can see the data coming in perfectly. Have you made a video on getting the data into home Automation from MQTT as that is the bit I am now struggling with. Any help with this would be much appreciated. (I have also added File Manager, MQTT Explorer, Studio Code Server, and Terminal) I gather i have to add the sensor info in a yaml file some where... Cheers Ants (New Zealand)

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Glad you found HA. It's a great platform! Your MQTT devices should show up as entities. Once you have them as entities, you can act on them via automations. If they are not discovered automatically, you would create them as entities in yaml. www.home-assistant.io/integrations/sensor.mqtt/#new_format

  • @DanyKhalife
    @DanyKhalifeАй бұрын

    +9000 to previous comments about clarity. Subscribed as well :) are there any special considerations for setting up the broker with only SSL? I used the openssl tag for the image, and am able to connect to the broker using MQTT explorer as well as things like frigate. For some reason though HA doesn't like it and I think I tried every combo of the advanced setting. Thoughts?

  • @MrSupersidewinder
    @MrSupersidewinder2 жыл бұрын

    Thank you loads, I beat on mosquitto for two days in docker compose, gave up hashed it out and did it your way. My normal docker directory is /opt but portainer built this in /var/lib/docker... Can portainer be pointed to my /opt dir by default, I'm assuming it could see my other running volumes. Also the console won't log on... THANKS AGAIN!!!

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    I'm not sure if portainer can be changed. However, I ran into that same volume issue and had to back out the first time. I would think you could created the mosquitto volumes wherever you wanted them, such as in opt. As an example, I installed Frigate using the docker compose method from the CLI and portainer just picked it up, with all volumes.

  • @TheDoppelPoint
    @TheDoppelPoint Жыл бұрын

    where do i get the config file, in your video for my MQTT?

  • @yourpalfranc
    @yourpalfranc2 жыл бұрын

    Hi, Chris. Good video! I'm curious about your Zwave/MQTT setup. What's the advantage to running Zwave devices that way? I went with zwaveJS2MQTT when I made the switch away from the original zwave integration recently, but I have the broker turned off as I haven't implemented anything MQTT just yet. I do have a Sonoff S31 that I haven't setup yet, so maybe MQTT is a good way to go for that? Is the zwaveJS2mqtt broker sufficient for running a few simple devices?? Thanks. ~Frank

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    It really depends on preference. One of the things I can do is have other devices interact with my zwave devices, such as my test raspberry pi. This gives additional flexibility but isn't required if you are doing everything on one machine. You would just disable the mqtt part of zwaveJS2mqtt. I like it also for the interface so I'll use it regardless.

  • @hamadalmarri2141
    @hamadalmarri21412 жыл бұрын

    Great video . I have one request for future videos , I cannot find any video about flowmeter integrated in Home Assistant , so would you please make a video about that

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Can you give me an example of a flow meter that you are using?

  • @asopok
    @asopok2 ай бұрын

    After installing how can I connect to Zigbee2mqtt to run in Home Assistant?

  • @Qosmio1955
    @Qosmio19552 ай бұрын

    I started from scratch, installing docker in a Proxmox LXC and then portainer. I then installed mosquitto s per the description in the vid. I couldn't get past the point where I have to get into the container's console. Turns out that the latest release of docker won't play nice with the current release of portainer and no containers within portainer (including the portainer container itself) have working console access. I'm to old and too impatient to try and nut this out, so I'm going to have to find another way to run mosquitto in a LXC container....

  • @Qosmio1955

    @Qosmio1955

    22 күн бұрын

    Turns out the solution was really easy. I just installed a bog-standard Linux installation and installed mosquitto (broker and clients) on that. Nothing else. No Docker container, no Portainer. You just don't need them!

  • @techdad6135
    @techdad61352 жыл бұрын

    Hi Chris! Great video! Any chance you could do a video on setting up mqtt to use tls?

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Thanks. It's super easy but some devices don't support it. I'll add that to my list.

  • @techdad6135

    @techdad6135

    2 жыл бұрын

    @@mostlychris Awesome thank you! I want to eventually connect some sensors remotely (ideally without the use of a VPN) but want to make sure the information is sent securely since I do use a un/pw.

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    If those devices can do TLS, you can do this now by enabling TLS on the broker side. There are also cloud TLS capable mqtt providers that you *might* be able use as in intermediary but I haven't tried that. Hive is one I know of.

  • @NicolaCaldo
    @NicolaCaldo Жыл бұрын

    Great video! You have set up the MQTT broker to use the host network but, what if I want to use the bridge network and assign it a static IP which is not the localhost of my host machine?

  • @mostlychris

    @mostlychris

    Жыл бұрын

    You can adjust your settings to fit your network environment.

  • @wwolfram33
    @wwolfram332 жыл бұрын

    I would like to see how to create a HA Lovelace button that sends a command to a device. Thanks for the video.

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Do you have a specific example?

  • @SBinVancouver
    @SBinVancouver Жыл бұрын

    I'm good with the broker, I'd like more on interacting with device through HA - both acting on state changes in the MQTT topics, and controlling devices through MQTT.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Noted. I'll add that to my video list.

  • @gundross
    @gundross10 ай бұрын

    Hi, I'm unable to save my config berceuse ESC button does nothing:/ 11:14

  • @litsieww
    @litsieww5 ай бұрын

    Hi Chris! It's a great video and learnt a lot. But when I wanted to add a password to my MQTT broker, after keying in my password, docker shell just says "Killed". I had to revert the config file to allow non-password connection. I was also unable to find any good answers searching on the web. Many thanks!

  • @awardblvr
    @awardblvr2 жыл бұрын

    Hi Chris... I followed your steps almost exactly and everything works... BUT... You kinda promised to show HOW now to set up steps in Home Assistant to integrate with this LAN-based MQTT broker. I'm not seeing it.. What should I look for? (I can send MQTT topics successfully via HA MQTT interface.. But, now we need to take the next step. THANKS!)

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    You can add the MQTT integration from the integrations page and then specify the IP address of your MQTT server in the configuration. Then it should talk to the MQTT server you installed.

  • @M4biz-g3d
    @M4biz-g3d Жыл бұрын

    Hi. Chris. Good video. Anyway I haven't well understood why you've installad Mosquitto on a docker container rather than directly on Home Assistant.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Thanks for watching. This is an example of another option for those that want to run it separately. Using the HA installed version is still an option if you want to go that route.

  • @hynekdlouhy8121
    @hynekdlouhy812122 күн бұрын

    Cant open the console through portainer. "Unable to retrieve image details"

  • @ronnydidit
    @ronnydidit Жыл бұрын

    Could you figure out how to install a MQTT broker on a RP pi Pico W and make a tutorial of it? I'm tired of burned SSD cards. It should be possible since some guys installed it even on a ESP32.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    I'll look into it. Thanks for the suggestion.

  • @HobTechTV
    @HobTechTV Жыл бұрын

    i have followed the video, the 1883 port is running as shown at 12:29, tried to connect with mqtt eplorer but unsuccessfull, could you please help ?

  • @MrDVTO

    @MrDVTO

    Жыл бұрын

    I'm in the same situation. MQTT Explorer is unable to connect to the box running the image. I doubt that it's network configuration for me because the box is also running HA which I'm able to access and is able to see multiple devices.

  • @kodigaraz7062

    @kodigaraz7062

    Жыл бұрын

    before deploying the container, when choosing a network, you need to select the bridge and not the host, everything worked for me

  • @prattleon

    @prattleon

    5 ай бұрын

    I'm having the same problem. Switching to bridge i get error "request failed with status code 500"@@kodigaraz7062

  • @Melsrobloxxx
    @Melsrobloxxx Жыл бұрын

    Hi Thanks for the videos. May I ask how can I get the ip address of the host? I tried a lot of ip address, all didn't work

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Which host? The MQTT host? The way I set it up, it is the same IP as the host device.

  • @bburcuymn
    @bburcuymn6 ай бұрын

    Is there any limit on the number of devices to be connected in fiware 3.7.0? Can we connect as many devices as we want? I searched through the documentation and in many sources, but I couldn't find any information on this subject

  • @mostlychris

    @mostlychris

    5 ай бұрын

    Probably limited to network throughput and processor capability.

  • @bburcuymn

    @bburcuymn

    5 ай бұрын

    Thanks @@mostlychris

  • @Dvalin21
    @Dvalin212 жыл бұрын

    I've been trying to install this, but I keep getting the error that the address is in use. That's what I get from the logs. Any advice?

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    The address or the port? Are you running something else on your server that uses that same port?

  • @omkardumbre3421
    @omkardumbre34212 жыл бұрын

    How much client mosquitto broker can handle at a single time by default?

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    I think that is based on the hardware you use. I won't be maxing it out anytime soon with what I have running.

  • @zyghom
    @zyghom2 жыл бұрын

    and I thought I have many MQTT devices - until you opened your zwave ;-) However I am using autodiscovery for all my devices - all sensors, switches etc. are created automatically and Home Assistant sees them automatically - you can use all advantages of HA and 2 way communication between device and HA. I tried first manually in yaml file but it was too much of manual work - autodiscovery is the answer to MQTT and Home Assistant

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Autodiscovery is awesome for sure. Many of the devices that feed into the broker can be autodiscovered by HA if they are supported and the MQTT integration is installed on the HA device.

  • @markusr.4628
    @markusr.46289 ай бұрын

    I messed up the config file. But deleting the container and adding it again won't let me connect to the console. I get the message that I have to wait till the container is running. I still get the same error message in the log as if deleting the container doesn't remove the corrupted config file. Can you help me out?

  • @markusr.4628

    @markusr.4628

    9 ай бұрын

    Answer to myself: Delete the config volume also, then the mosquitto.config file is gone

  • @2fastduck72
    @2fastduck72 Жыл бұрын

    hi, followed the instructions but after the :wg it stuck and get the message 'mosquitto/config' is a directory :-( Any idea how to fix?

  • @mostlychris

    @mostlychris

    Жыл бұрын

    You are trying to save a directory rather than a file.

  • @2fastduck72

    @2fastduck72

    Жыл бұрын

    @@mostlychris hi Chris, thanks for reply! What should I to do there you’re instructions are ok till the :wg

  • @mostlychris

    @mostlychris

    Жыл бұрын

    @@2fastduck72 Can you point on the min:sec in the video which you are getting stuck?

  • @Tntdruid
    @Tntdruid2 жыл бұрын

    When i hit deploy i get: invalid volume specification: 'mqtt_config:mosquitto/config': invalid mount config for type "volume": invalid mount path: 'mosquitto/config' mount path must be absolute I made the volume like you did.

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    What are you running Docker on?

  • @Tntdruid

    @Tntdruid

    2 жыл бұрын

    @@mostlychris raspberry pi 4 8 GB ram.

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    @@Tntdruid It's hard to tell without seeing your exact config. You should have 3 volumes and three mappings under the container's volumes tab.

  • @Tntdruid

    @Tntdruid

    2 жыл бұрын

    @@mostlychris I'm going to reinstall Portainer, looks like I did something wrong.

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    @@Tntdruid Good luck!

  • @l0gic23
    @l0gic232 жыл бұрын

    Hey you! yeah you! How dare you beat me to the first thumbs up!

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    oh?

  • @KennethLavrsen
    @KennethLavrsen2 жыл бұрын

    If you have a Linux box which is not the one that runs Home Assistant I fail to see any advantage of installing Mosquitto in Docker. It is a standard package in major distributions. Raspberry Pi OS, any Ubuntu flavoir, Debian all have it as a standard thing in their repos. It is mainly written in C with only standard dependencies. Docker only complicates the installation, any updating, and configs. In any of the apt based distros simply 'apt install mosquitto'. And the configs needed is simple. And when you do the normal apt update and apt upgrade mosquitto gets updates with security fixes as well. People have gone Docker crazy and forgotten the simple and much more resource friendly way through the good old package management systems. And it is started and stopped as a normal systemd daemon like everything else on a modern Linux box. Docker makes sense for software that depends on a lot of python or nodejs stuff of specific versions. It is overhead and added complexity for nothing for a simple c/c++ program without graphics UI like Mosquitto

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    Noted. There is a lot of containerization these days. It's an option for those who like to play in that world. Thanks for the thoughts.

  • @jeffrowe6004
    @jeffrowe60042 ай бұрын

    sure wish you had showed how to install nano instead of using that POS VI. Btw, your tip about deleting the lines is wrong, you have to put in a number

  • @George-bb9yi
    @George-bb9yi Жыл бұрын

    You lost me at the less command (not hard as I am an utter noob) - it looks like you typed 'mos' but that does not get me into the file. I was able to open the config in vi, but I want to understand what you did.

  • @mostlychris

    @mostlychris

    Жыл бұрын

    Hey George. What was the timestamp where I did that in the video?

  • @George-bb9yi

    @George-bb9yi

    Жыл бұрын

    @@mostlychris ~9:15...

  • @benwilkinson7849
    @benwilkinson78492 жыл бұрын

    one t for mosquito in real life :)

  • @mostlychris

    @mostlychris

    2 жыл бұрын

    😂

  • @NenadNaukovic
    @NenadNaukovic Жыл бұрын

    Hi Chris. Thank you for this video. I am running an local MQTT broker and switching from Openhab to Home Assitant. MQTT Broker and HA are separate Docker containers on a Synology NAS (no Supervisor / no Add-Ons). Through the YAML config, I was able to add some sensors values to HA. Through their corresponding state_topic that values are updated within HA which is fine, but I only have the values as entities, and the sensors are not listed as devices. So I am looking into MQTT device discovery with Home Assistant and using the devices with their topics. Have you every dug into MQTT device discovery/publishing discovery messages or similar topics? Would be interesting to see how you got along with it. Adding my request anlong with @froman2461 and @SBinVancouver :) A follow up would be very appreciate. Thank you lots!

Келесі