ESPHome devices & odd mDNS behaviour

So I have a few ESPHome devices, couple of smart plugs by localbytes and a smart wall switch by Sonoff. All flashed with the latest ESPHome and all work flawlessly with Home Assistant.

However even when these devices are working and accessible from HA, I cannot get ESPHome to see them unless I power cycle them and even then ESPHome can only find them for a short period of time < 3mins following the reboot.

My unqualified suspicion is that this is an mDNS issue somewhere but the problem is exclusive to ESPHome i.e. my Denon AV Receiver and HP printer both resolve consistently. Additionally I enabled the web_server on the devices and like HA this always works but only via the IP address of the device and never the mdns hostname.

Working examples…

# avahi-resolve -a 192.168.1.8
192.168.1.8     Denon-AVC-X3700H.local
# avahi-resolve -a 192.168.5.2
192.168.5.2     HP846993D1A8C4.local
# avahi-resolve -n Denon-AVC-X3700H.local
Denon-AVC-X3700H.local  192.168.1.8
# avahi-resolve -n HP846993D1A8C4.local
HP846993D1A8C4.local    192.168.5.2

Now a ESPHome smart plug…

# avahi-resolve -a 192.168.5.235
192.168.5.235   localbytes-plug-pm-8ca2b3
# avahi-resolve -n localbytes-plug-pm-8ca2b3
Failed to create host name resolver: Invalid host name
# avahi-resolve -n localbytes-plug-pm-8ca2b3.local
Failed to resolve host name 'localbytes-plug-pm-8ca2b3.local': Timeout reached

And then if I power cycle the same smart plug…

# avahi-resolve -n localbytes-plug-pm-8ca2b3.local
localbytes-plug-pm-8ca2b3.local 192.168.5.235

How is it the ESPHome devices don’t have the .local suffix appended like my other devices?

My router is a Unifi Dream Machine SE, I’ve enabled mDNS on both networks I’ve configured. Network functions like Chromecast work fine between subnets so I’m not drawn to this being a router issue but happy to eat my words!

The avahi-resolve commands were run from my unraid server, both home assistant and esphome run as docker containers on this and both are in the same subnet.

This is nagging me though I admit with everything working I could just leave this alone but honestly it twitches my ocd so any help would be appreciated.

You could use normal DNS by specifying your local domain:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: .local_domain.mine

Then your device should be accessible by
localbytes-plug-pm-8ca2b3.local_domain.mine
(provided you configured local_domain.mine in your router (or any domain name you specify) :wink: )

1 Like

I always have my router assign a fix IP address to each of my IOT devices. This then allows you to access the device via the IP address if mDNS or DNS isn’t working. I believe assigning fix address is also falls under best practices from a security perspective. It makes it easier to control the flow of traffic from your IOT devices to the outside world.

Thanks, agreed I could move this away from mDNS for sure, I just would have prefered to avoid this given the added admin overhead. However at this point that might be optimal given the time invested so far in tshooting this issue :laughing:

My config for EdgeRouterX:
image

Given that you have 192.168.1.x and 192.168.5.x IP addresses, what subnet mask are you using on the devices and does this match on all hosts?

Let’s try to guess something with no device YAML attached.
Answer: have no clue.

if not specified differently in YAML or overrided by DHCP, domain is .local:

  • domain (Optional, string): Set the domain of the node hostname used for uploading. For example, if it’s set to .local, all uploads will be sent to <HOSTNAME>.local. Defaults to .local.

For me it working for all 40+ devices with no exceptions.

Exactly what is working?

domain: .local_domain.mine

Or

domain: .local

(which wouldn’t be needed if mDNS would work properly :thinking: )

I use the same domain as my certificate, meaning I don’t have to use internal/external address; for me it is all the same :stuck_out_tongue:

DHCP not supplying domain, devices YAML files does not contain domain too.
All devices discoverable and reachable as <device_name>.local.

I think there is a limit on 16 chars for the name in front of .local
Some devices seems to have this limit at least.

Meaning, your mDNS is working…
However, the OP’s mDNS isn’t working properly (and neither is mine) :thinking:

Install method?

Mulicast DNS is not something that is ‘installled’ …

Of course. I’m asking how HA and esphome are installed? It makes a difference.

HAOS installed on Raspberry Pi 4.
ESPHome installed twice: as add-on for HAOS and as standalone installation on Windows 10 PC.
So, have 2x ESPHome dashboards - on HAOS & Windows PC.

ESPHome devices images compiled & installed partly from HAOS, partly from Windows PC.
DNS domain/suffix not specified not in DHCP, nor in YAML’s, nor in PC/HAOS settings.

ESPHome mDNS issues had once: when used ESP-IDF framework on device.
Reverting back to Arduino solved the issue.

ESP32 devices show offline, mDNS not working correctly · Issue #6311 · esphome/issues · GitHub - open issue reg. mDNS