OTA Failing on Wemos D1 Mini Pro

Hi Folks,

My D1 mini pro shares my Home energy data with my HA through ESPHOME 2022.11.2, while the device works fine I am having issues with OTA updates, I mean the OTA update finishes successfully but D1 does not boot after that, and soft reset or power cycle do not help.

To get it working again I have to download the firmware and install it through a USB TTL adapter with ESPHOME-flasher.

its kind of a hassle to pull out the energy monitoring system from the junction box every time to update the firmware, does anyone have a similar issue, any fix or workaround will be appreciated.

Anil Verma B

  name: a402-energy8266

  board: d1_mini_pro

# Enable logging

# Enable Home Assistant API

  password: "d4631574c67aa19694c4a18d772261de"

  ssid: !secret wifi_ssid
  password: !secret wifi_password


  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "A402-Energy8266 Fallback Hotspot"
    password: "o2Pjeefl5Nyq"


  rx_pin: D5
  tx_pin: D6
  baud_rate: 9600


  - platform: pzemac
    id: pzemaca402
      name: "A402C"
      name: "A402V"
      - lambda: |-
          return ((x * 0.992 ));
#          return ((x - 2 ));
      name: "A402E"
      unit_of_measurement: kWh
      accuracy_decimals: 2
      - multiply: 0.001
      name: "A402P"
      name: "A402F"
      name: "A402PF"
    update_interval: 60s

  - platform: template
    name: a402_reset
    id: reset_button

    # Optional variables:
    icon: "mdi:restore"
      - pzemac.reset_energy: pzemaca402

note - tested WEMOS D1 mini (non pro) with the same issue.

Could you provide logs (serial logs might be necessary) of your esphome node when doing the update?

Get yourself (or your esphome node) a safe mode button and press it 20 seconds before running ota :rocket:

Is it possible that you have the Wemos D1 Mini Pro too close to another WiFi devices? These things are very easy to jam an cause instabilities wich results to a failed OTA.

Also can you share log on how the OTA fails?

And out of curiosity: What voltages are you measuring and which device did you use to “calibrate” the pzem004t v3?

I have not saved them but the progress bar thing goes to 100% and I get the message “successfully updated” or something similar to that. then it tries to connect and fails with “unable to connect message”

no wifi devices in the vicinity of 10 meters.

I have modified PZEM following a youtube video by TheHWcave to make it a bit more safe and changed the opto resistors to work with 3.3V TTL.

it measures 220V mains calibrated through a fluke meter after the modification.

Edit - also added a small 5V ups incase the power fails, (happens very often in India) as ESP reports strange values when power is restored.

1 Like

That is the side which sends the ota update (for example the esphome dashboard ha addon) and it just can’t tell (for every case) why a update fails - specially if it transferred the complete binary like in your case.

What you need to know what’s happening is the logs from that esphome node. It will tell you if it received the full ota update and hopefully more (why it couldn’t apply it for example).

1 Like

I had a lamp which exhibited symptoms similar to this.
What I found was that - when the lamp was on - the power supply was not able to supply sufficient current to the ESP for flash writes to ‘stick’ and so it would fail to boot afterward.
A solution was to put code in the ota: section of the YAML to turn the lamp off when OTA begins.

      - light.turn_off: 
          id: the_light
          transition_length: 0s

I removed the ESPhome node from the energy meter circuit and connected directly to my laptop and the firmware updates over OTA is successful. As @ glyndon suggested looks like my UPS circuit does not have enough juice to perform OTA update.

I will check my circuit further and update once i have a solution.

Thank you for pointing me in the right direction, my current hardware running the D1 pro does not seem to have enough juice to support this.

It might be just enough to enter the safe mode before doing the ota in that case. For @glyndon it would be probably the same because the safe mode only initializes the bare minimum functions for ota to work.

Still @glyndon found a permanent way to be able to run ota's just a s normal without having a second manual step :muscle:

Guess it could be also adopted to just reboot into safe mode upon an ota update :trophy:


Solution: In case anyone has a similar issue.
I am using TP4056 as the UPS along with a 5V boost module to power the D1 pro, originally I had changed R3 to 10k with a 150mAh battery which was limiting the output current as well, but now changed to 2K with a 18650LI-ION 3Ah cell which now allows the module to take OTA update.

Thank everyone for looking into the issue and pointing me in the right direction.

Anil Verma B

1 Like