MQTT problems - can't sub

Hi guys,

I’m fairly new to HA and i really need some help now. I’m trying to set up mosquitto. I have installed it via hass.io add-ons and it seems to be running fine, however when i try to subscribe to something via SSH, it says: “Error: Address not available”.

This is the Options in Mosquitto broker:

{
“plain”: true,
“ssl”: false,
“anonymous”: false,
“logins”: [
{
“username”: “my_username”,
“password”: “my_password”
}
],
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

This is what i have in my configuration.yaml:

mqtt:
broker: http://myurl.duckdns.org
port: 1883
username: my_username
password: my_password

I have also tried with my PI’s local ip.

And this is the command in send in SSH to sub:
mosquitto_sub -d -u root -P 250984 -t dev/test

I hope someone can see what i’m doing wrong :slight_smile:

Thanks
Morten

Just gonna point out a few things…

First, probably wouldn’t post your DDNS address publicly unless it’s just not something you wanna worry about.

Second, your broker is pointing to your DDNS address and you’ve given out your user/pass combo on the 1883 port. This is usually the open non-TLS port used without certs. If you’re going to use mqtt outside of your home consider using certs please

Third. your mqtt config is pointing to your DDNS address on the 1883 port. If you’re running a local broker on the SAME machine just use 127.0.0.1. HA is probably having issues resolving the address, or maybe it isn’t. Who knows.

Fourth, run a ‘ps -A | grep mosquitto’ to see if the service is actually running. if you run ‘ps -A | grep mosquitto’ and it doesn’t return anything then mosquitto isn’t running and you won’t be able to connect.

But most importantly. Fix the gaping security hole you have now!

1 Like

You’re right. Thanks for pointing that out. Guess i was just trying a bunch of things, while troubleshooting :slight_smile: I have changed it back to the local ip now. Both hass.io and the broker are running on the same Raspberry pi

the “ps -A | grep mosquitto” returns: 1504 root 0:00 grep mosquitto

If i add “-h 192.168.0.5” to the command, it works! Don’t quite understand why

The reason is because your local device can’t resolve the DDNS address from the lan on itself. Easy explanation would be … pick up your phone and dial your number. You can’t answer it because you’re on it.

also, if you’re hosting your mqtt broker and HA on the same machine use

-h 127.0.0.1

just incase your IP ever changes LANside.

I have also installed Mosquitto via the add-on option on Hassio. I am probably trying to follow along the Bruh video that the original poster was and I got to the point where I used SSH/Putty to get command line access on the raspberry pi running Hassio. I needed to enter the command

mosquitto_sub -d -u -P -t dev/test

I got the same “Error: Address not available” message. Adding the -h <hassio_ip_address> option worked for me as well. I never would have figured that out, not even sure where you got it from since I don’t see it on the home assistant documentation.

My question is on yaml file entries. Following the home assistant docs I have this:

mqtt:
  broker: core-mosquitto
  username: !secret mqtt_user
  password: !secret mqtt_pw

Should this point to my duckdns address instead? Will my duckdns address be my MQTT host? Ultimately I want to try Zanzito, but that has been a total failure, so I figured I would see if I could get OwnTracks running with MQTT first. That has led me to here.

I got the same “Error: Address not available” message. Adding the -h <hassio_ip_address> option worked for me as well. I never would have figured that out, not even sure where you got it from since I don’t see it on the home assistant documentation.

You probably wouldn’t see this anywhere in the HA documentation because it’s just generic. You’d see it via man mosquitto_sub or mosquitto_sub --help or googling manpage mosquitto_sub

as for your questoin

There’s no need to point to your DuckDNS address unless you’re hosting your MQTT broker externally at that address. Most of the time it’s on the same system as your HA installation so you can either use your HA ip or just the localhost ip 127.0.0.1 or whatever the ip is on your lan. Owntracks is dead simple to set up.

This works for me:

mosquitto_sub -d -u <MyUserName> -P <MyPassword> -t dev/test -h <hassio_ip_address>

This does not work for me (Error: Connection Refused)

mosquitto_sub -d -u <MyUserName> -P <MyPassword> -t dev/test -h 127.0.0.1

I am using putty on my windows machine to SSH into the raspberry pi running Hassio. I like the idea of using the local host ip address in case the ip address of my raspberry pi changes. Any idea why that wouldn’t work?

try

mosquitto_sub -d -u <MyUserName> -P <MyPassword> -t dev/test -h localhost -v

Also, you really should be using static IP’s anytime you’re doing home automation/networking/admining. It makes it easier to fix problems, find problems, trace problems.

1 Like

That gave a different error.
Error: Address not available

If none of those work then you’ll need to use the IP of your home assistant instance. I’m not sure why it wouldn’t work, it’s what I use when debugging, but it may have something to do with hass.io. I’m running a debian distro with MQTT, HA, and a few other things so there could be some differences.

If you’re worried about IP changing just set it up statically in your router. In the long run it’s a smarter move.

On hassion use:
mosquitto_sub -u User_Name -P Password -v -t # -h hassio_ip_address