OTA error: Update Failed: Flash Read Failed

Hardware: AI Thinker ESP-12K (nodemcu-32s2 clone)
Freshly installed from web through USB cable. I can load the webpage running on the device. After a couple of minutes it confirms correct boot and writes the settings to flash.
Next I try to program my YAML configuration using the OTA dialog to update the firmware. Immediately this fails with the message “Update Failed: Flash Read Failed on first OTA attempt”.

I’m new to ESPhome so please bear with me :slight_smile:
The YAML I try to run is pretty simplistic:

esp32:
  board: nodemcu-32s

light:
  - platform: binary
    name: "Desk Lamp"
    output: light_output

output:
  - id: light_output
    platform: gpio
    pin: GPIO02

Where should I start to look for the solution?

If that is your entire yaml, you are missing the ota: component.

esp32:
  board: nodemcu-32s

ota:

light:
  - platform: binary

etc...

I added the ota: component and even removed the output: component, but still the same message.

So the yaml above isn’t what’s loaded over USB? Because that yaml has no web server component. Post the yaml you loaded via the USB cable.

Also, have you tried:

esp32:
 board: nodemcu-32s2

or

esp32:
  board: nodemcu-32s
  variant: esp32s2

It is supposed to autodetect, but some boards don’t.

@zoogara I installed the initial firmware through https://web.esphome.io/ , connecting over USB.
No YAML loaded over USB so far.

With the updated YAML as you suggest, again the same message. It appears immediately when trying to run OTA update.
Any way to debug this?

Ah - I get you.

Hmm maybe it doesn’t like the S2 board when it sets up the board initially. I’ll have a fiddle tomorrow.

Are you using the OTA update option on the web interface of the ESP?

If so what file are you trying to upload?

If you have the ESPHome dashboard running you should be able to adopt this device and update it from there.

Sorry, I may not express myself clearly.
Initial installation is done through https://web.esphome.io with the device connected on USB.
Once this succeeds, I try to perform OTA firmware update by adding it in Home Assistant and connecting to the link presented under “Device info” which is just the http://<dev_ip>:80 website.
On this page the device name is properly displayed, and a short while after booting it prints some log information in the box on the right:

Time	level	Tag	Message
21:15:27	[I]	[ota:113]	
Boot seems successful, resetting boot loop counter.
21:15:27	[D]	[esp32.preferences:114]	
Saving 1 preferences to flash...
21:15:27	[D]	[esp32.preferences:143]	
Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

From this page, in the section “OTA Update” I choose the yaml file that I copied in the opening post (with the ota: component included now), yet still the same error when I press the “Update” button.

Using the command line, I managed to generate a new YAML and upload a new firmware file to the device using OTA update:
esphome run <file.yaml> --device <device_ip>
Probably I do something wrong with the browser-based flashing?

Yes - you did.

The web based OTA update is so you can flash a compiled .bin file to the device. You cannot flash a .yaml file directly to the device.

The esphome run command you successfully updated with does 2 things. It compiles your .yaml file with ESPHome and creates a .bin file. It then loads that .bin file to the device.

Thanks, I finally get it. I guess I was confused by the fact that the file dialog for upload accepts a YAML as input while it should actually get a bin file instead.