MQTT Server With SSL

To start this post I want to say that I have searched the forum and found loads of posts. I’ve also done a lot of Googling. I can’t find the answer to my question(s) and worryingly the posts I have found that come close either don’t have an answer or finish with the OP saying words to the effect of “I couldn’t get it to work”.

I have built a Mosquitto MQTT server on a Digital Ocean droplet. The SSL is provided by a Let’s Encrypt certificate. That is, it’s not self signed. My reason for this is long and involved but it involves data collection from sensors outside my home network.

To this server I have successfully connected

  • OwnTracks on my phone
  • ESP32 clients located in a field
  • A RPi on my home network running Zigbee2MQTT

And some other bits. Point is, I have

mosquitto_sub -h localhost -t '#'

running on the server and I can see a steady stream of these devices connecting and publishing without a problem.

But I can’t get HA to connect to this server. If I try and do it through the integration I get “Connection failed” and

[paho.mqtt.client] failed to receive on socket: [Errno 104] Connection reset by peer

In the log. If I go back to basics and configure it in the YAML, the log fills up with

[homeassistant.components.mqtt] The 'broker' option near /config/configuration.yaml:13 is deprecated, please remove it from your configuration

And it doesn’t connect. I remember in the days when we had to do everything with YAML you could specify keys like certificate: auto or specify paths to certificates but any of those options just cause the “deprecated” warning above and, since I’m using a LE certificate should theoretically not be needed.

Is there something else I need to do to get HA to connect to MQTT with SSL? This is Home Assistant OS 2022.5.4 by the way.

Thanks

Steve

You need to do yaml “manual” setup.
SSL is considered advanced and cannot be done in UI

As I said - if I do that the log fills up with

[homeassistant.components.mqtt] The 'broker' option near /config/configuration.yaml:13 is deprecated, please remove it from your configuration

And MQTT isn’t set up.

Looks like you do the ui setup but also add the cert in your config

Well, that’s not clear at all. I added
mqtt:
certificate: auto

And nothing else and now it’s working. Thanks for pointing that out.

1 Like

Many thx, @stetho ! I experiences exactly the same and thx to you thread, I found the solution.

Hi,

have you still successfully integrated your external mqtt broker today?

I’m running HA 2023.6 where the yaml config is invalid and I can’t figure out how to connect to an MQTT server with TLS enabled via the UI.
Everything I tried so far unfortunately results in the generic error message ‘Connection failed’ and I have absolutely no idea what else I should do. Other apps can talk to the mqtt broker just fine. It’s just HA that somehow refuses to connect.

Did you ever get this working? I also have an MQTT broker set up on Digital Ocean for my Personal Weather Station - it publishes data every 2s to my weather station website, and works very well. I want to bring that same data into my HA set up - but am a HA newbie. Any help you can give on what I have to put in my YAML file would be much appreciated, as I can’t see much detail on the HA MQTT documentation. Many Thanks. David.

What detail were you looking for?

Also did you read the thread? he says he fixed in the 4 or so post

Hi - thanks for your reply. Yes, I saw all the posts. I guess by detail, I mean what exactly do I need to put in the YAML file and where do I set the server name etc. Sorry, am probably just being dumb, as not used MQTT in WA before, and am new to HA anyway. I use my MQTT broker as part of a “weewx” implementation on a RPi for my personal weather station. The config file for weewx has the following code for the MQTT implementation:

server_url = XXXXX
        topic = weather
        unit_system = METRICWX
        aggregation = aggregate
        binding = archive, loop
        log_success = False
        log_failure = True
        [[[tls]]]
            tls_version = tlsv1
            ca_certs = /etc/ssl/certs/ca-certificates.crt

Any help you can give would be much appreciated.

Many Thanks.

Sorry, I should add that the implementation for my weather station website also has the following in another config file:

 mqtt_websockets_enabled = 1
          mqtt_websockets_host = <<domain name for my MQTT broker>>
          mqtt_websockets_port = 9001
          mqtt_websockets_ssl = 1
          mqtt_websockets_topic = "weather/loop"
          disconnect_live_website_visitor = 1800000