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

Поделиться
HTML-код
  • Опубликовано: 21 июл 2024
  • 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
    @timffoster 6 месяцев назад +1

    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 Год назад +1

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

  • @camerontgore
    @camerontgore Год назад +3

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

  • @jt_simon
    @jt_simon 7 месяцев назад

    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.

  • @shaunwhiteley3544
    @shaunwhiteley3544 2 года назад

    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

  • @lildarker4044
    @lildarker4044 Год назад

    absolute legend, you made me want to subscribe

  • @isosahir
    @isosahir 2 месяца назад

    Awsome video, helped a lot. Thanks man!

  • @mineapple8612
    @mineapple8612 Год назад

    tysm for this very straight forward and thorough explainantion!

  • @TheBendixSA
    @TheBendixSA 8 месяцев назад

    This was brilliant

  • @sonoff2253
    @sonoff2253 Год назад

    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?

  • @eric88798
    @eric88798 Год назад +1

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

  • @kopparsulfat
    @kopparsulfat Год назад

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

  • @user-td6ju5fw4d
    @user-td6ju5fw4d 11 месяцев назад

    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!

  • @andymok7945
    @andymok7945 Год назад +4

    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.

  • @manologitech
    @manologitech Год назад

    Very helpful, thank You.

  • @revealingfacts4all
    @revealingfacts4all 11 месяцев назад

    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?

  • @nigelholland24
    @nigelholland24 2 года назад +1

    Great video thank you

  • @antshurdley2914
    @antshurdley2914 Год назад +1

    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

  • @techdad6135
    @techdad6135 2 года назад +3

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

    • @mostlychris
      @mostlychris  2 года назад +1

      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.

  • @hamadalmarri2141
    @hamadalmarri2141 2 года назад

    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?

  • @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
    @MrSupersidewinder 2 года назад

    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.

  • @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  Год назад +1

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

  • @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?

  • @TheDoppelPoint
    @TheDoppelPoint Год назад

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

  • @scottb721
    @scottb721 22 дня назад

    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

  • @wwolfram33
    @wwolfram33 2 года назад +1

    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?

  • @Qosmio1955
    @Qosmio1955 2 месяца назад +1

    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 12 дней назад

      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!

  • @yourpalfranc
    @yourpalfranc 2 года назад

    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 года назад +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.

  • @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.

  • @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.

  • @litsieww
    @litsieww 5 месяцев назад

    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
    @awardblvr 2 года назад +1

    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.

  • @asopok
    @asopok 2 месяца назад

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

  • @gundross
    @gundross 9 месяцев назад

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

  • @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  Год назад +1

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

  • @zyghom
    @zyghom 2 года назад

    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.

  • @bburcuymn
    @bburcuymn 5 месяцев назад

    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

  • @hynekdlouhy8121
    @hynekdlouhy8121 13 дней назад

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

  • @Dvalin21
    @Dvalin21 2 года назад

    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?

  • @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.

  • @omkardumbre3421
    @omkardumbre3421 2 года назад

    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.

  • @markusr.4628
    @markusr.4628 8 месяцев назад

    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 8 месяцев назад

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

  • @HobTechTV
    @HobTechTV Год назад +2

    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

  • @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?

  • @l0gic23
    @l0gic23 2 года назад

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

  • @Tntdruid
    @Tntdruid 2 года назад

    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 года назад +1

      @@Tntdruid Good luck!

  • @jeffrowe6004
    @jeffrowe6004 2 месяца назад

    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

  • @KennethLavrsen
    @KennethLavrsen 2 года назад +3

    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 года назад +1

      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.

  • @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
    @benwilkinson7849 2 года назад

    one t for mosquito in real life :)

  • @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!