Flashing of ESP32 with ESPHome not successful?

Hi, I am new to the HomeAssistant (HA) and the ESP32 Game. Somehow. I am trying to integrate my ESP32 (ESP32-WROOM-32) to show me some temperature information I am retreiving from an Switchbot Temp Sensor. But that is far away. I am struggling to even integrate the ESP into HA. These are my steps:

  1. I Installed HA on an RaspberryPi 4 and added all my Smart Home Devices
  2. I installed the ESPHome Addon
  3. I connected the ESP32 via an Micro USB (Data-) Cable to my RaspberryPi which is running HA
  4. I am adding a new device via the ESPHome Builder and entered my correct Wifi information
  5. I am selecting “ESP32” as target via the USB Port (CP2102 USB to UART Bridge Controller /dev/ttyUSB0) connected to the RPi
  6. It starts building and downloading all neccessary ressources
  7. At some point it starts flashing. After compiling it shows the following lines:
Linking .pioenvs/wetterstation/firmware.elf
RAM:   [=         ]  12.4% (used 40664 bytes from 327680 bytes)
Flash: [=====     ]  49.5% (used 907697 bytes from 1835008 bytes)
Building .pioenvs/wetterstation/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/wetterstation/firmware.bin"], [".pioenvs/wetterstation/firmware.elf"])
SHA digest in image updated
Wrote 0xef040 bytes to file /data/build/wetterstation/.pioenvs/wetterstation/firmware.factory.bin, ready to flash to offset 0x0
esp32_copy_ota_bin([".pioenvs/wetterstation/firmware.bin"], [".pioenvs/wetterstation/firmware.elf"])
======================== [SUCCESS] Took 143.54 seconds ========================
INFO Successfully compiled program.
esptool.py v4.8.1
Serial port /dev/ttyUSB0
Connecting.....
Chip is ESP32-D0WD-V3 (revision v3.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 7c:87:ce:30:c0:dc
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00010000 to 0x000effff...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Compressed 913472 bytes to 606442...
Wrote 913472 bytes (606442 compressed) at 0x00010000 in 14.4 seconds (effective 508.3 kbit/s)...
Hash of data verified.
SHA digest in image updated
Compressed 17440 bytes to 12128...
Wrote 17440 bytes (12128 compressed) at 0x00001000 in 0.7 seconds (effective 213.3 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 144...
Wrote 3072 bytes (144 compressed) at 0x00008000 in 0.1 seconds (effective 315.7 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.2 seconds (effective 431.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/ttyUSB0 with baud rate 115200

After that it tries to connect to my Wifi. The first couple of tries are failing (with reason=‘Authentication Failed’ or reason=‘Auth Expired’ but in the end, it seems to connect to the Wifi and the ESP gets an IP Address. This then is the rest of the log:

[18:05:29][D][wifi:697]: Retrying with hidden networks...
[18:05:29][I][wifi:313]: WiFi Connecting to 'homezone'...
[18:05:30][I][wifi:617]: WiFi Connected!
[18:05:30][C][wifi:428]:   Local MAC: 7C:87:CE:30:C0:DC
[18:05:30][C][wifi:433]:   SSID: [redacted]
[18:05:30][C][wifi:436]:   IP Address: 192.168.68.78
[18:05:30][C][wifi:440]:   BSSID: [redacted]
[18:05:30][C][wifi:441]:   Hostname: 'wetterstation'
[18:05:30][C][wifi:443]:   Signal strength: -68 dB ▂▄▆█
[18:05:30][C][wifi:447]:   Channel: 6
[18:05:30][C][wifi:448]:   Subnet: 255.255.252.0
[18:05:30][C][wifi:449]:   Gateway: 192.168.68.1
[18:05:30][C][wifi:450]:   DNS1: 10.0.0.138
[18:05:30][C][wifi:451]:   DNS2: 10.0.0.138
[18:05:30][D][wifi:626]: Disabling AP...
[18:05:30][C][api:026]: Setting up Home Assistant API server...
[18:05:30][I][app:062]: setup() finished successfully!
[18:05:30][W][component:170]: Component wifi cleared Warning flag
[18:05:30][W][component:157]: Component api set Warning flag: unspecified
[18:05:30][I][app:100]: ESPHome version 2025.3.1 compiled on Mar 23 2025, 18:03:16
[18:05:30][C][wifi:600]: WiFi:
[18:05:30][C][wifi:428]:   Local MAC: 7C:87:CE:30:C0:DC
[18:05:30][C][wifi:433]:   SSID: [redacted]
[18:05:30][C][wifi:436]:   IP Address: 192.168.68.78
[18:05:30][C][wifi:440]:   BSSID: [redacted]
[18:05:30][C][wifi:441]:   Hostname: 'wetterstation'
[18:05:30][C][wifi:443]:   Signal strength: -68 dB ▂▄▆█
[18:05:30][C][wifi:447]:   Channel: 6
[18:05:30][C][wifi:448]:   Subnet: 255.255.252.0
[18:05:30][C][wifi:449]:   Gateway: 192.168.68.1
[18:05:30][C][wifi:450]:   DNS1: 10.0.0.138
[18:05:30][C][wifi:451]:   DNS2: 10.0.0.138
[18:05:30][C][logger:177]: Logger:
[18:05:30][C][logger:178]:   Max Level: DEBUG
[18:05:30][C][logger:179]:   Initial Level: DEBUG
[18:05:30][C][logger:181]:   Log Baud Rate: 115200
[18:05:30][C][logger:182]:   Hardware UART: UART0
[18:05:30][C][captive_portal:089]: Captive Portal:
[18:05:30][C][mdns:116]: mDNS:
[18:05:30][C][mdns:117]:   Hostname: wetterstation
[18:05:30][C][esphome.ota:073]: Over-The-Air updates:
[18:05:30][C][esphome.ota:074]:   Address: wetterstation.local:3232
[18:05:30][C][esphome.ota:075]:   Version: 2
[18:05:30][C][esphome.ota:078]:   Password configured
[18:05:30][C][safe_mode:018]: Safe Mode:
[18:05:30][C][safe_mode:020]:   Boot considered successful after 60 seconds
[18:05:30][C][safe_mode:021]:   Invoke after 10 boot attempts
[18:05:30][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[18:05:30][C][api:140]: API Server:
[18:05:30][C][api:141]:   Address: wetterstation.local:6053
[18:05:30][C][api:143]:   Using noise encryption: YES
[18:06:06][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[18:06:06][D][esp32.preferences:114]: Saving 1 preferences to flash...
[18:06:06][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

There is no success message in the end, no matter for how long I am waiting. Should there be one? I then clicked on “Stop” on the bottom right corner. The yaml file I created tells me the EPS is “online”, but that is only because it is still connected via USB. A Wifi connection is not possible and it also does not show up as a device in my Wifi routers list.
I tried that procedure multiple times, tried also a second ESP32 Board (the same type), different cable, different flashing method (via Browser) but it does not matter what I do, i cant get it to work. At least I know the Wifi on the ESP is working because I connected to it via a simple program I coded within the Arduino IDE. What am I doing wrong?

This looks like a perfectly successful flash. But the initial flash is kind of a basic firmware with some connectivity. So now it is time to open the yaml and configure the sensors you want if you havent done so yet.

This says it has run without any problems for quite some time, so it won’t reboot to recover from a bad flash.

Okay so I end the flashing process by clicking on Stop then? But shouldn’t the ESP be connected to my Wifi after the flashing (nothing is ignored or hidden in the list)? It is not visible as Wifi Device in my Wifi-Routers GUI and also HA does not see the ESP as Device I could add. So…

Yes, you can click stop, it just stops the logging. Flash was done before it logged.

The log shows it connected to wifi just fine, should be at 192.168.68.78 if I see correctly.Home Assistant should be able to connect to it.

Right, this is what I thought. But it is not connected for sure. Also I noticed the ESP does not create the fallback hotspot for some reason. Could this be a hint regarding my problem?

It Is connected, that is why it is not creating the fallback hotspot. It sais so in the log. Did you put a static ip in it or let it get one from dhcp? How do you prove it is not connected? can you ping it?

I pinged it and it worked, but only when the ESP is connected to the Raspberry via USB. It then also shows up as “knot” (german: “Knoten”, my GUI is in german, I don’t know if it is called so in english). But it is unable to connect to the ESP. Here’s the error message:

So it says "No connection to ESP possible. Make sure that the YAML-File contains an “api:” line (which it does).

I then disconnected the ESP from the Raspberry and tried to connect it only to USB Power. Then nothing is working anymore and the ping also is not working. But why is the USB connection related to a successful IP ping?!

There is a message in the top left on your image.
Configure the ESP.

No, it says “ignore” the ESP :wink: Maybe my config file helps here (after flashing for the 1Mio^th time, I changed the name)

It says add.
https://www.google.com/search?q=hinzufĂźgen+english

1 Like

The use_address tag should be removed in its entirety. It meant to be used when you want to change the ip (or when mdns is broken), but it does not match where the esp can be found. It is also not how you set a static ip. That is very likely why it can’t connect.

As @Hellis81 said: Configure the ESP.

The clue was “only when connected to the Raspberry”. You aren’t finished. There should have been a notification on your dashboard tha t new device was found. If you didn’t get that, no worries, I only see it half of the time. Open the ESPHome integration. Scroll to the bottom and click on “Add Device”. This will open a dialog box asking for the host. Enter the IP address of the device here.

2 Likes

I thought you meant the button said “configure”. Of course this is what I tried in the very beginning, to add it. “Hinzufügen” in German. It is not possible and it throws the error message I postet (with the missing api line). I followed a youtube tutorial and the guy there immediately checked the logs wirelessly after the flashing was done. I can not even see the logs via the USB connection to my HA server.
Procedure:

  1. Click on LOGS from the yaml file
  2. Select “Plug into computer running ESPHome Dashboard”
  3. Select the (only) USB Port
  4. All I then get is this and there it is stuck:

After he then added the ESP, he went into the integrations and added the ESP via the encryption key without any issues. THAT is why this thread is named “Flashing failed?” because something seems not to be right from the start. This should not be that hard I guess. And the IP address the ESP gets after flashing is also not working, it is definitely not online. Strange though that sometimes I could see the ESP Knot in the integrations sections (and many times not). I am tempted to buy another ESP Module jsut to make sure, that is not the problem.

Omg I solved it. My Pi was connected to my home network via LAN. But this prevented the ESP from connecting to the RPi. I then also connected my Pi via Wifi (to the same Network) and suddenly it worked. Why is that?

Is it a modem and a separate router?

Yes it is. My main router is the one from my provider and behind that I connected a tplink deco. But as I am writing those lines, it makes sense, that it is not really the same network.

So my LAN setup looks like this:

Provider Router → Deco → Unmanaged Switch → RPi

My provider-Router does not have an active Wifi Network, I only use my Deco’s Mesh Wifi Network.

That setup should work.
I believe mine is connected the same way.

It should, yes. I am no Network technician but I mean it is the same network somehow. All Devices within it (no matter if I have the device connected to the providers router, the Deco directly or the small switch) can communicate with each other. No idea why it did not work in this case.