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.

Regards
Anil Verma B

esphome:
  name: a402-energy8266

esp8266:
  board: d1_mini_pro

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "d4631574c67aa19694c4a18d772261de"

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

  manual_ip:
    static_ip: 192.168.1.67
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.25
    dns2: 8.8.8.8

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

captive_portal:

uart:
  rx_pin: D5
  tx_pin: D6
  baud_rate: 9600

modbus:

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

button:
  - platform: template
    name: a402_reset
    id: reset_button

    # Optional variables:
    icon: "mdi:restore"
    on_press:
      - 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.
HTH

ota:
  on_begin:
    then:
      - light.turn_off: 
          id: the_light
          transition_length: 0s
3 Likes

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:

image

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.

Regards
Anil Verma B

1 Like