Mosquitto broker - Announcing/Advertising MQTT service via mDNS

Hello,

I recently installed Home Assistant Operating System on a Raspberry Pi 4 using the Balena Etcher method. I’ve been searching how to advertising the MQTT service via mDNS, so I don’t have to set up the MQTT host on all my Tasmota devices individually, as they have a function to discover MQTT services.

According to https://developers.home-assistant.io/docs/network_discovery/:

“Home Assistant uses the python-zeroconf package for mDNS support. As running multiple mDNS implementations on a single host is not recommended, Home Assistant provides internal helper APIs to access the running Zeroconf and AsyncZeroconf instances.”

As they mention, running another mDNS to advertise the MQTT service is not recommended. So the most feasible approach would be for the Mosquitto broker Add-on to advertise itself using the internal helper APIs mentioned above.

Thanks

Tasmota’s documentation appears to disagree with that statement:

Host = your MQTT broker address or IP (mDNS is not available in the official Tasmota builds, means no .local domain!)

From my reading you can enable mDNS in tasmota when you compile, but it is not recommended. https://github.com/arendst/Tasmota/discussions/11403#discussioncomment-509283

So, if you leave the host field Host blank, it will discover your Home Assistant MQTT broker IP automatically?

I already did that but still had to input the host IP. From what I’ve been reading, the MQTT service has to advertise itself, so other devices find it without entering even a name.

The most used mDNS solution is to use avahi, as described in the link below:
http://dagrende.blogspot.com/2017/02/find-mqtt-broker-without-hard-coded-ip.html

But we cannot have multiple mDNS implementations, and Home Assistant already has one; that is why I recommended a feature for the Mosquitto broker Add-on to advertise itself using it.

Thanks

I just used a Bonjour browser and I can confirm MQTT is not being advertised.

See the screenshot below.

If you read the thread I posted it says that this should NOT be done with tasmota. Take the advice why don’t you!

I’ve read the thread. The feature that I’m requesting has nothing to do directly with Tasmota. Even though I mentioned it in my 1st post, let’s forget about it.

Having the MQTT Broker advertised on your network is something that many devices can take advantage of, and since HA has the mDNS, and it advertises the HTTP service, I’m pretty sure it won’t be too difficult to add the MQTT.

No it won’t and I don’t know why you’re even asking that question because I never even hinted it was possible. Where did you get that idea from?

No one is going to “forget about it” because you clearly stated Tasmota has a “function to discover MQTT services” and used it to justify your Feature Request. However, the official builds do not support mDNS.

Feel free to make a Feature Request but don’t justify it based on a faulty comparison.

Ok, it is clear that you guys are not interested, and your comments are not constructive at all.

I’ve found three posts on the community asking for the same thing. It is useful! Whether you use it for Tasmota or not. As I said, many devices could benefit from the MQTT service being advertised.

Hey don’t think no-one supports this idea.

I expect you are running home assistant operating system and the mosquito addon.in that case I think you should post on the mosquitto addon github. There is a link in the addon, or just go here https://github.com/home-assistant/addons/tree/master/mosquitto

We identified a factual error in your first post. What’s not constructive is using that error to justify your Feature Request.

Instead of simply acknowledging you made a mistake, you told us to “forget about it” and then became defensive by claiming our comments are unconstructive.

The concept itself is interesting but don’t justify it by making a faulty comparison. Good luck convincing the development team to implement this feature.

I told to forget about it because if not we were focusing on a different issue. I don’t know why you call it a faulty comparison, and I didn’t want to have such a discussion with you because is not the main topic.

Yes, mDNS was dropped from Tasmota official builds, because it is big, resource-hungry, and has some issues with some hardware. And they decided to remove it from the officials. But it is still there for you to add it. I have all my Tasmota devices running a custom build with the mDNS, with no issues.

How is that github issue coming along? Please post a link when you have done so I can follow. Cheers.

I did not want to post it there because is not an issue. But I managed to do it myself.

Here is a simple python script that gives you access to the zeroconf instance of HA for anyone interested. To run it, you need HACS and Pyscript integration.

import socket
from homeassistant.components import zeroconf
from zeroconf.asyncio import AsyncServiceInfo


def register_service(type, name, ip, port):
    aiozc = zeroconf.async_get_async_instance(hass)
    type += "._tcp.local."
    info = AsyncServiceInfo(
        type_=type,
        name=name + "." + type,
        addresses=[socket.inet_aton(ip)],
        port=port,
        properties={}
    )
    aiozc.async_register_service(info)


# Registering the service
service_type = "_mqtt"
service_name = "MQTT Host"
service_ip = sensor.local_ip  # Requires Local IP Address Integration
service_port = 1883
register_service(service_type, service_name, service_ip, service_port)

This can be used to advertise any service.

I hope this helps.

1 Like

Hi everyone,

I built an Avahi-based addon that has the MQTT service descriptor included, and installs from the Add-on Store. You can configure the hostname and interface parameters from the configuration tab.

There seems to be an idea that you can’t run two Avahi daemons on the same system, but I haven’t had any problems - they are both broadcasting the same IP associated with the hostname and other common services, meanwhile the MQTT one is unique, so there is no conflict and it works perfectly. I have a very customized Tasmota-based firmware I’m running on a line of devices (switches, dimmers etc.) I’m building, and they auto-find the Home Assistant instance very well.

You can get it here:

Hope this is useful.