Can we allow hyphens (-) in device names?

Currently it seems as if a hyphen / dash is not allowed in the name of a device. I’m not sure if this is for HA reasons or ESPHome reasons but I thought I’d ask if it could be made to be allowed.

When migrating from Tasmota to ESPHome, all of my devices were named “sonoff-####” and now the have to be renamed “sonoff_####”

No big deal just one of my quirks.

I guess it’s related to the fact that the device name is the hostname and the mdns name and their you have this limitation!

I’m pretty sure it’s the other way round. Hostname/DNS would allow hyphen but no underscore. HA does not allow hyphen in its entity names.

1 Like

Important: DNS is not mDNS :warning:

Isn’t hyphen a YAML restriction?

not that I’m aware of…

But I think in all (and to answer @dison4linux question finally) esphome tries to avoid any regressions which could be caused by any involved technologies. So it’s something to make the user happy :blush:

Is this true? I’m trying to find documentation somewhere on the limitations of mDNS and I can’t find where it says that underscores are okay but dashes/hyphens are not.

From the DNS Wiki:

Although no technical limitation exists to use any character in domain name labels which are representable by an octet, hostnames use a preferred format and character set. The characters allowed in labels are a subset of the ASCII character set, consisting of characters a through z , A through Z , digits 0 through 9 , and hyphen. This rule is known as the LDH rule (letters, digits, hyphen). Domain names are interpreted in case-independent manner.[26] Labels may not start or end with a hyphen.[27] An additional rule requires that top-level domain names should not be all-numeric.[27]

I couldn’t find anywhere in the Multicast DNS Wiki that says anything explicitly about the naming convention. Please share details because I had the same question: “Why can’t ESPHome.io use the DNS naming convention?” I want to line up my DNS names with my device names but I cannot unless I avoid using underscores and hyphens.

“[…] I know it’s a bit against DNS but it’s also not really possible to change it now (there was some things that required no hyphens, but I can’t recall what exactly again).”
Hyphen should be allowed in names. · Issue #723 · esphome/issues · GitHub