TL;DR A lengthy paragraph with discoveries, but you could jump right to the steps and get it over with.
I honestly was thinking the same and just couldn’t help but to dig deeper into how the publishing of mdns services are happening. For the record and at the time of writing, HassOS VM (or HassIO VM) in Oracle VB publishes three mdns services automatically on start for discovery:
- _ssh._tcp
- _sftp-ssh._tcp
- _home-assistant._tcp
They are linked to hassio.local mdns host (which has an IP defined automatically). The first two are published using the avahi-daemon of HassOS but the last one is registered by the home-assistant python container (container running in docker in HassOS).
Although you asked for advertising mqtt.local, but the right way is actually to register an _mqtt._tcp service linked to hassio.local host. The reason why is, technically, any mqtt enabled device would search for an _mqtt._tcp service, which has details like IP of a host and the port number, on the network (not search for mqtt.local host, as far as I know). That’s how service discovery is, by finding the host having the service, which is most probably the hassio.local of HassOS VM, and connect to it’s IP and the port defined by the service (MQTT port is 1883).
To do that, and the simplest way I see it, is nothing more than configuring avahi-daemon in HassOS to register _mqtt._tcp service.
At the time of writing (again), here’s what you need to do with HassOS running in Oracle VB (note: part of the steps include a custom docker image which I have open-sourced here and built myself, tested to work successfully on my setup) :
-
Start the HassOS VM, wait for it to boot and eventually for home-assistant to start, I’d say give it like 2~3 minutes till the screen stops writing new lines.
-
Press the Enter key and you should see the below:
Welcome to HassOS
hassio login:
-
Type root
and press the Enter key. You should then see the below:
_ _ _
| | | | (_)
| |__| | __ _ ___ ___ _ ___
| __ |/ _` / __/ __| | |/ _ \
| | | | (_| \__ \__ \_| | (_) |
|_| |_|\__,_|___/___(_)_|\___/
Welcome on Hass.io CLI.
For more details use 'help' and 'exit' to close.
If you need access to host system use 'login'.
-
Type login
and press Enter, you should see a #
symbol at the start of the line and now your in a shell terminal of HassOS (note: this is not the same as using the ssh with the ssh-addon of home-assistant).
-
Now type the below command which will start publishing _mqtt._tcp using avahi:
docker run -d -v /run/dbus:/var/run/dbus -v /run/avahi-daemon:/var/run/avahi-daemon --network host --restart always --name mqtt-mdns ahasbini/avahi-tools:latest avahi-publish-service -s $HOSTNAME _mqtt._tcp 1883
-
All done! The above command is persistent, meaning the publishing will be done automatically after restarts or in case of failures (can’t think of one right now but looking forward to knowing about them).
I have to say that docker was to the rescue after a lengthy digging
You might wonder why it wasn’t done without using docker, the reason is due to the file-system being used (SquashFS) by the HassOS VM. It is in read-only mode and we can’t create files for avahi to load on startup so the only other way to issue a command to the avahi-daemon to publish the service. Even making it persistent was difficult without docker as the entire /
directory is made read-only except for the directories belonging to docker and other unhelpful ones (tmp
and var
). This comes to reason why it’s better to install hassio on an Linux machine like Ubuntu instead of using the HassOS VM, however I still find it nice to use HassOS provided by Home Assistant team.