Why does HA depend on devices having static IP addresses?

This is a question about why HA appears to depend on some devices never changing their IP’s.

(N.B.: This is NOT a question about how-to make addresses static, as I’ve been doing IP networking for 35+ years, and generally avoid statically nailing down IP addresses wherever possible, as that’s what name-services like DNS and mDNS were designed for.)

So, all my devices (mostly ESPHome-based) get their IPs from the router’s DHCP (dnsmasq) service, and so each of their hostnames do always point to whatever address a device has.

But if I restart everything (e.g. power-cycle of the whole house), the devices might get IPs that are different from what they had prior. Their hostnames still resolve to their current IPs of course, but the IPs may differ from the past.

… And this seems to easily create problems for HA (observed with Shelly and ESPHome so far). This is the focus of my question.

HA will accuse devices of being unavailable (they’re online, and findable by name), or it will sometimes show two devices (the current and former holders of the given IP addr) when I search the integrations’ page for one by name.

Looking in .storage/core.* files, I see that HA is remembering devices names and their last-known IP’s.

Why? I’m guessing it’s for efficiency during runtime, perhaps. That makes sense. But when a surprise happens (e.g. device is ‘unavailable’) shouldn’t HA then fallback to just asking for it by name (and voila! there’s the device!) and recover the connection gracefully?

It’s clear to me that the designer(s) of HA and its major integrations are very wise and intelligent people, so questioning this design aspect is something I do humbly, expecting that there is a reasonable answer. But I haven’t been able to find it yet.
Searching docs and forum posts for the basis of this design choice has not been fruitful - I’ve certainly tried - probably due to the wide usage of the search terms involved.

Can anyone familiar with the core design philosophies tell me why it does this, and why it doesn’t fallback to a name lookup when something unexpected happens?

3 Likes

Most of my devices are Zigbee, but none of my WIFI devices have static IPs and they seem to work just fine. In fact, the only static addresses I have are the RPi running HomeAssistant and my NAS. I don’t have any ESPHome devices though.

Thanks for responding.
I’m beginning to notice that this syndrome has, so far, only affected my ESPHome devices. Maybe it’s exclusively an issue with that integration. I’m going to keep digging and may move this question to that subforum.

good luck!

edit: There are plenty of ESPHome users here that may be able to jump in though.

It is going to be integration specific. There are no requirements that integrations handle host names and/or ip addresses or rely on broadcast to discover - so your mileage will vary. That said, having host name resolution working consistently seems like a reasonable goal vs relying on IP addresses or auto discovery.

Open a bug on Esphome and work on a PR?

2 Likes

Agreed. But I’m not a pro dev, and have only a casual acquaintance with git and the proper ways to submit a code change the way it’s done nowadays. And this might be something that goes deeper than just one or two integrations.
So I could possibly submit it as a feature request.