Home Assistant confusing two different ESPs after some time

Hi,

I’ve got a bunch of ESP32 running various ESPHome configs. But recently Home Assistant started confusing one of them for another. By that I mean it works for a few hours after adding the integration, but then it suddenly starts trying to connect to the wrong IP for some reason, and complains the name has changed.

Say I have board A and board B, which I add using their static IPs to HA. When I download the diagnostics right after adding them, they both show the correct IPs as I added them.

I then wait a few hours and suddenly B goes offline in HA, and the logs complain that B is now named A. When I download the diagnostics for B, it does indeed show the IP of A now, it changed without explanations. Since the HA integration doesn’t have a config menu I have to delete it and re-add it with B’s IP to make it work again, multiple times a day.

The two device names and IPs are of course different, and the ESPHome web UI doesn’t have any such issues, it connects to both boards as expected. Only HA does that weird confusion.
It’s always B changing to A’s IP, never the opposite, never another IP and other ESPs (C, D …) aren’t affected.

Anyone knows what could cause HA to suddenly change the IP it’s connecting to for the ESPHome integration, even though there’s not even a menu to configure it after adding ?

mdns:
  disabled: true

I have mdsn disabled in all the configs and I use only static IPs, so I really don’t understand how HA is changing it.

Thanks

The only entry in the logs coming from ESPHome that I can see is this one, every time :

Can't connect to ESPHome API for B @ 172.29.10.3: Server sent a different name 'A'
Can't connect to ESPHome API for A @ 172.29.10.3: Timeout while connecting to ('172.29.10.3', 6053)
Can't connect to ESPHome API for B @ 172.29.10.4: Error connecting to ('172.29.10.4', 6053): [Errno 111] Connect call failed ('172.29.10.4', 6053)
Can't connect to ESPHome API for A @ 172.29.10.3: Timeout during handshake

The timeouts are caused by be messing with the network settings (I’m having a separate issue with hidden network so I un-hid it this morning), that’s not normally there. Usually it’s just that first line about the server sending a different hostname, I’d show another more usual occurence but my logs just rotated this morning so I don’t have any.

I can’t use mdsn because the ESPs and HA aren’t on the same network, it wouldn’t see the announces even if it was enabled.
Could this be caused by connectivity issues though ? That hidden network problem has made some of my ESPs blink on / off quite a bit lately, maybe HA is getting confused when it has to reconnect to multiple instances at the same time or something ? If that’s the case I unhid the network now so it should stop, we’ll see.

The “best” way to clean that “mess” would be probably to delete all esphome integrations you have and then add them again.

I have changed the name of one of the ESPs at one point but I haven’t changed the hardware, just re-named the yaml and re-flashed it to the same device, then re-added it to HA.
I’ve deleted and re-added all the integrations multiple times since so sadly that doesn’t fix it.

You checked the docs for wifi?

Yes, I have a separate thread about it and I’ve also opened an issue for what looks like a bug to me, channel & bssid being ignored when hidden = true.
For now I’ve unhid my network, because as you guessed I have multiple APs and some of the ESPs aren’t connecting to the one they should.
Shouldn’t be related to this issue though

Thanks

Hi,
did you ever figure out what caused this, or how to solve it?

I have the exact same situation

  • two ESPs named A and B (nowadays), fixed IP
  • A at IP x.y.z.93, B at IP x.y.z.234
  • first ESP was previously called A, but renamed to B later
  • both work fine for days, then B (never A) is “lost”
  • HA looks for B at the IP for A and is surprised to find the name of A there
  • Log file entry as you describe it
  • No problem pinging A and B at their respective IP addresses

The only way I have resolved this is by deleting integration B from HA and re-adding it

When you say “static ip” addrs. Defined on the ESP devices or declared in your switch/router/dhcp ?

I could easily declare an ESP device being MAC xx:yy:zz:aa:bb:cc to get 192.168.1.101 named “A” on my pihole being a static one not one assigned by the DHCP server.

And I then recompile that ESP using ESPhome with a given name “B”.

Won’t be of much help, since within the network depending upon lousy tools used you might locate is being B but your switch/router/pihole will still recognise it being named “A”. since the MAC and the linked IP are defined to be a device named “A”.

Swapping names of existing & known devices in one task is a tricky thing.
It’s as if saying Peter is now Tom and Tom is Peter. … Depending upon who was listening when you descided you swapped their names, others might still act as if Peter is Peter and Tom is Tom :slight_smile:

Not to mention, if you declared a static IP on the ESP device but also on a switch/router/pihole you better chance that on both ends. If you want to be on the safer side … ensure that existing leases are also thrown not that there’s leases from the DHCP/router pointing to the old one.

Hey,

I did not, basically most of what I got back from this was “just use mdns lol”, barely paraphrasing.

My workaround for this has been to simply use regular DNS, Unifi Networks now supports defining a local DNS name for a device in the same place as static DHCP definitions, so I just do that.
Home Assistant is then pointed to those local DNS names, it works around whatever bug that integration has when using IPs.

If you can’t do it like that you could also use pihole or any other local dns resolver, most of these will let you define local DNS entries like that which will work fine.

Basically it doesn’t matter what you do as long as you don’t give the IP directly to Home Assistant, that seems to be what causes the issue as soon as you have >1 esphome integration defined.