ESPHome is using wrong IP to connect to device

Hi all,
I’ve an issue with ESPHome device.

I initially configured the device with DHCP and then change to use a fixed address.

No I continuously have the issue that if I want to connect to the device (e.g look at the logs) the ESHome device is searched at the “old” DHCP address not at the new static IP address which is correctly registered in my Router.
Also after power off of the ESPHome device the entities are no more available - also I think this is also consequence from the wrong IP address the add on ESPHome uses.

I have tried the following:

  • to remove the device and added it again - no solution
  • have removed ESPHome device and the add on (!) and installed it again - no solution

Can someone tell me how to reset the used addresses or what else to do?

Many thanks,
Rainer

My ESPHome Device set at IP 192.168.1.150

esphome:
  name: templogger
  friendly_name: templogger

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "<key>"

ota:
  - platform: esphome
    password: "<pwd>"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.1.150
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.150
    gateway: 192.168.1.1
    subnet: 255.255.255.0
  
  # Komminikation IP hard coded!

  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Templogger Fallback Hotspot"
    password: "<key>"

captive_portal:

# https://esphome.io/components/i2c
# https://lastminuteengineers.com/esp32-pinout-reference/
i2c:
  - id: i2c0
    sda: GPIO21
    scl: GPIO22
    scan: true  
    frequency: 1.0kHz # 10 kHz Minimale Frequenz möglich


# Multiplexer - sollte gleiche Frequenz wie Input haben!
# https://esphome.io/components/tca9548a
tca9548a:
  - address: 0x70
    id: multiplex0
    i2c_id: i2c0
    channels:
      - bus_id: multiplex0channel_0
        channel: 0
# https://github.com/esphome/esphome-docs/blob/4d329c605528a9b3eae5cfffcd71d5b467ff38ca/components/sensor/sht4x.rst  
# Address 0x44
sensor:
  - platform: sht4x
    # Kanal 0
    i2c_id: multiplex0channel_0
    update_interval: 30s
    temperature:
      name: "Temperatur Kanal 0"
      id: Temperatur_Kanal_0
    humidity:
      name: "Feuchtigkeit Kanal 0"
      id: Feuchtigkeit_Kanal_0

ESPHome looks at 192.168.1.88

INFO ESPHome 2024.10.0
INFO Reading configuration /config/esphome/templogger.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing templogger (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.4
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.6
|-- Wire @ 2.0.0
Compiling .pioenvs/templogger/src/main.cpp.o
Linking .pioenvs/templogger/firmware.elf
RAM:   [=         ]  12.5% (used 41056 bytes from 327680 bytes)
Flash: [=====     ]  50.9% (used 933841 bytes from 1835008 bytes)
Building .pioenvs/templogger/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/templogger/firmware.bin"], [".pioenvs/templogger/firmware.elf"])
Wrote 0xf5660 bytes to file /data/build/templogger/.pioenvs/templogger/firmware.factory.bin, ready to flash to offset 0x0
esp32_copy_ota_bin([".pioenvs/templogger/firmware.bin"], [".pioenvs/templogger/firmware.elf"])
========================= [SUCCESS] Took 45.63 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.88
ERROR Connecting to 192.168.1.88:3232 failed: [Errno 113] No route to host

Hi, I see that you already have “use_address” specified, but you are stating the same IP address as the static_ip, that’s normally the correct method.

I wonder if it’s getting the old IP from mDNS, what happens if you try ping “templogger.local”, does that resolve to the new IP or the old one?

You could also try this:

mdns:
  disabled: true

No its not. You use use_address to specify the old address (ie the address the esp is currently on)

Yes correct, it’s already on 192.168.1.150 but the host is still looking at .88. Maybe it’s redundant if the static IP and the use_address are the same?
He could try setting the static_ip to 192.168.1.88 and the use_address to .150.

Ronnie,
where would I try templogger.local?
Many thanks,
Rainer

Ping from the host where esphome is running - this could be a rasberry pi or home server where it’s installed.
The .local part is the mDNS “local-link” designation. It tells your host to lookup the hostname (templogger.local) by broadcasting to the network instead of using DNS. So if we stop this then it might pickup the correct IP.

Also I forgot to suggest that you add in your actual DNS server to the manual IP section:

  manual_ip:
    static_ip: 192.168.1.150
    gateway: 192.168.1.1
    subnet: 255.255.255
    dns1: <your local DNS server IP>

Ronnie,
“ping templogger.local” looks at the right address (sorry for the picture, but I don’t know how to copy text from HA local terminal):
grafik

So I will try the following:
1.) remove use_address
2.) add dns1:
I’ll come back when I’ve tried it.
Many thanks so far.
Rainer

Ah, so mDNS is correct. So then the local arp cache may be wrong.
Do an arp lookup to see if it’s cached incorrectly. Type in “arp -a” in the core terminal. You should see an entry for the templogger - is this the old/wrong IP address?
If it is, clear the entry for that device by doing “arp -d [templogger fqdn]” where the full name of the device replaces the brackets and such. Example (you may need to use sudo):

sudo arp -d myesp.homenet.lan

Ronnie,
here’s the output from the cmmands: Unfortunately the “sudo arp -d myesp.homenet.lan” is not recognized:

grafik

I still have the problem of not getting access to the esp device - even after deleting the “use_address” and adding the “dns1” entry.

Flashing works and then the logger looks again at *.88 address:

Code:

esphome:
  name: templogger
  friendly_name: templogger

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "<key>"

ota:
  - platform: esphome
    password: "<pwd>"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.150
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
  
  # Kommunikation IP hard coded!

  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Templogger Fallback Hotspot"
    password: "<pwd>"

captive_portal:

# https://esphome.io/components/i2c
# https://lastminuteengineers.com/esp32-pinout-reference/
i2c:
  - id: i2c0
    sda: GPIO21
    scl: GPIO22
    scan: true  
    frequency: 1.0kHz # 10 kHz Minimale Frequenz möglich


# Multiplexer - sollte gleiche Frequenz wie Input haben!
# https://esphome.io/components/tca9548a
tca9548a:
  - address: 0x70
    id: multiplex0
    i2c_id: i2c0
    channels:
      - bus_id: multiplex0channel_0
        channel: 0
# https://github.com/esphome/esphome-docs/blob/b99a7c6a071b04d486cbfff6113ad26227e56578/components/sensor/sht4x.rst  
# Address 0x44
sensor:
  - platform: sht4x
    # Kanal 0
    i2c_id: multiplex0channel_0
    update_interval: 30s
    temperature:
      name: "Temperatur Kanal 0"
      id: Temperatur_Kanal_0
    humidity:
      name: "Feuchtigkeit Kanal 0"
      id: Feuchtigkeit_Kanal_0

Logging details from flashing sessing:

INFO ESPHome 2024.10.0
INFO Reading configuration /config/esphome/templogger.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing templogger (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.4
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.6
|-- Wire @ 2.0.0
Compiling .pioenvs/templogger/src/main.cpp.o
Linking .pioenvs/templogger/firmware.elf
RAM:   [=         ]  12.5% (used 41056 bytes from 327680 bytes)
Flash: [=====     ]  50.9% (used 933841 bytes from 1835008 bytes)
Building .pioenvs/templogger/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/templogger/firmware.bin"], [".pioenvs/templogger/firmware.elf"])
Wrote 0xf5660 bytes to file /data/build/templogger/.pioenvs/templogger/firmware.factory.bin, ready to flash to offset 0x0
esp32_copy_ota_bin([".pioenvs/templogger/firmware.bin"], [".pioenvs/templogger/firmware.elf"])
========================= [SUCCESS] Took 45.85 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.88
ERROR Connecting to 192.168.1.88:3232 failed: [Errno 113] No route to host

ok, so arp on the core does not have the templogger device cached.
What device are you running HA from as the 172.30.x.x address range suggests to me that it’s running in docker? Is esphome also running in another docker container?

No. I have a HA Yellow with RP 4.

I think that’s using docker - I don’t know much about the HA Yellow. There must be a host OS IP address (for the Raspberry Pi) that you can ssh into and run those commands from.

Did you try a reboot of the HA Yellow?

Ronnie,
it is the Home Assistant Yellow with a Raspberry Pie 4 computer module running Home Assistant OS (Documentation – Home Assistant Yellow).

Yes, I have restarted the system several times.

But I have not shutdown, made it powerless and restarted then. I will do that right now.

Regards,
Rainer

Update,
unfortunately nothing has changed with the issue after system shut off - power off - restart.

I’m not sure what next to try … or shall I try to get help in the HA Discord?

One observation though, maybe tzhat gives some hint:
I had during my tests one time the wrong Wifi credentions - in this case the esphome logger tried to connect to 192.168.1.150 (the right address) - of course didn’t found the esphome device as it was not on the wifi network.

Once I had corrected the Wifi credentials it again started to look at 192.168.1.88

Anyhow many thanks so far for your help !!
Rainer

Sorry, I’m not sure. The underlying OS is where you need to troubleshoot this from and not from the HA container. I’d try do the same tests (the arp output and the pings from there).

Ronnie,
many thanks for your help.

I now had success that the logger connected to the correct IP address 192.168.1.150.

Does ESPHome fall back to the “192.168.1.88” if the WIFI Router shows the device as not available?

Background: I switched off the power of the ESP device and the logger tried to connect to 192.168.1.88. When I re-powered the ESP device waited for a few second and invoked the logger it to connect to the correct IP 192.168.1.150 and it worked.

Maybe I had some hickup of my Fritzbox WiFi network ?

Best regards,
Rainer

Set the use_address

Tried it again - does not work!

Update,
after initially working at 192.168.1.150 it suddendly stopped to work and again the invoking the logger shows he tries to connect to 192.168.1.88.

Ping works on 192.168.1.150 - device replies.

I’m really frustrated now.

Rainer

Use address: is ONLY for when you change the IP, then you remove the line and reinstall.

My advice: use DHCP.

If you really need an unchanging IP address, set it in your router. I have far too many WiFi devices, over 100, and managing that many static IP addresses would be a nightmare. (If you want to see strange effects, just assign two devices the same static IP.) Only my servers and NAS have static IP addresses. Everything else is DHCP.

1 Like