ESPHome in Shelly won't upgrade to new version, but no errors

Hi everyone,

I have a strange situation with one shelly device with esphome on it. I can send new firmware to the device, but it seems the version stays the same in the logs.
See the logs, I compiled a 2023.9.1 version, I send it successfully to the shelly device, but after connecting, it’s still 2023.8.2.

Anyone can help me to find the issue?

----LOGS----
INFO ESPHome 2023.9.1
INFO Reading configuration /config/esphome/luchtpomp-drain2.yaml…
INFO Detected timezone ‘Europe/Amsterdam’
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO0 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from luchtpomp-drain2.local using esphome API
INFO Successfully connected to luchtpomp-drain2.local
[11:22:42][I][app:102]: ESPHome version 2023.8.2 compiled on Aug 29 2023, 22:28:38

Still breaking my head on this one. Seems the old firmware stays persistent in the device while updating completes without errors. I included my config and the update proces. I hope someone can point me a direction in how to debug this issue.

My config:

#https://devices.esphome.io/devices/Shelly-Plus-1PM

substitutions:
  device_name: "Luchtpomp Drain 2"
  # Higher value gives lower watt readout
  current_res: "0.001"
  # Lower value gives lower voltage readout
  voltage_div: "1995"

esphome:
  name: "luchtpomp-drain2"
  platformio_options:
    board_build.f_cpu: 160000000L

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_FREERTOS_UNICORE: y
      CONFIG_ESP32_DEFAULT_CPU_FREQ_160: y
      CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "160"

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

logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxx="

ota:
  password: "xxxxxxx"

time:
  - platform: homeassistant

output:
  - platform: gpio
    id: "relay_output"
    pin: GPIO26

switch:
  - platform: output
    id: "relay"
    name: "${device_name} Relay"
    output: "relay_output"

binary_sensor:
  - platform: gpio
    name: "${device_name} Switch"
    pin: GPIO4
    on_press:
      then:
        - switch.toggle: "relay"
    filters:
      - delayed_on_off: 50ms

sensor:
  - platform: ntc
    sensor: temp_resistance_reading
    name: "${device_name} Temperature"
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: "mdi:thermometer"
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 298.15K
    on_value_range:
      - above: "80.0"
        then:
          - switch.turn_off: "relay"
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 10kOhm
  - platform: adc
    id: temp_analog_reading
    pin: GPIO32
    attenuation: 11db

  - platform: adc
    name: "${device_name} Relay Supply Voltage"
    pin: GPIO33
    attenuation: 11db
    filters:
      - multiply: 8

  - platform: hlw8012
    model: BL0937
    sel_pin:
      number: GPIO23
      inverted: true
    cf_pin: GPIO5
    cf1_pin: GPIO18
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: "${device_name} Current"
      unit_of_measurement: A
      accuracy_decimals: 3
      icon: mdi:flash-outline
    voltage:
      name: "${device_name} Voltage"
      unit_of_measurement: V
      accuracy_decimals: 1
      icon: mdi:flash-outline
    power:
      name: "${device_name} Power"
      unit_of_measurement: W
      id: power
      icon: mdi:flash-outline
      on_value_range:
        - above: "600"
          then:
            - switch.turn_off: "relay"
    change_mode_every: 2
    update_interval: 10s
  - platform: total_daily_energy
    name: "${device_name} Daily energy consumed"
    power_id: power
    filters:
        - multiply: 0.001
    unit_of_measurement: kWh
    icon: mdi:clock-alert

status_led:
  pin:
    number: GPIO0
    inverted: true

The update process:

INFO ESPHome 2023.9.3
INFO Reading configuration /config/esphome/luchtpomp-drain2.yaml...
INFO Detected timezone 'Europe/Amsterdam'
WARNING GPIO4 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO0 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Generating C++ source...
INFO Compiling app...
Processing luchtpomp-drain2 (board: esp32doit-devkit-v1; framework: espidf; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 160MHz, 320KB RAM, 4MB Flash
 - framework-espidf @ 3.40405.230623 (4.4.5) 
 - tool-cmake @ 3.16.4 
 - tool-ninja @ 1.7.1 
 - toolchain-esp32ulp @ 2.35.0-20220830 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Reading CMake configuration...
Dependency Graph
|-- noise-c @ 0.1.4
Compiling .pioenvs/luchtpomp-drain2/src/main.o
Linking .pioenvs/luchtpomp-drain2/firmware.elf
RAM:   [=         ]   8.0% (used 26108 bytes from 327680 bytes)
Flash: [====      ]  42.9% (used 787857 bytes from 1835008 bytes)
Building .pioenvs/luchtpomp-drain2/firmware.bin
Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/luchtpomp-drain2/firmware.bin"], [".pioenvs/luchtpomp-drain2/firmware.elf"])
Wrote 0xd1c00 bytes to file /data/build/luchtpomp-drain2/.pioenvs/luchtpomp-drain2/firmware-factory.bin, ready to flash to offset 0x0
========================= [SUCCESS] Took 11.59 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of luchtpomp-drain2.local
INFO  -> 192.168.100.103
INFO Uploading /data/build/luchtpomp-drain2/.pioenvs/luchtpomp-drain2/firmware.bin (793600 bytes)
Uploading: [============================================================] 100% Done...

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from luchtpomp-drain2.local using esphome API
INFO Successfully connected to luchtpomp-drain2.local
[16:07:37][I][app:102]: ESPHome version 2023.8.2 compiled on Aug 29 2023, 22:28:38
[16:07:37][C][status_led:019]: Status LED:
[16:07:37][C][status_led:020]:   Pin: GPIO0
[16:07:37][C][wifi:543]: WiFi:

I think I found the issue just after posting my previous post. I see these lines:

Wrote 0xd1c00 bytes to file /data/build/luchtpomp-drain2/.pioenvs/luchtpomp-drain2/firmware-factory.bin, ready to flash to offset 0x0

And after:
INFO Uploading /data/build/luchtpomp-drain2/.pioenvs/luchtpomp-drain2/firmware.bin (793600 bytes)

It seems i’m sending the wrong file, or compile it to the wrong filename. Where can I change this setting to recover from this?

No, I think this is normal behaviour with ESPHome: this is from your log:

Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/luchtpomp-drain2/firmware.bin"], [".pioenvs/luchtpomp-drain2/firmware.elf"])
Wrote 0xd1c00 bytes to file /data/build/luchtpomp-drain2/.pioenvs/luchtpomp-drain2/firmware-factory.bin, ready to flash to offset 0x0

I am seeing the exact same logging output when successfully flashing ESP devices.
As I understand it, the files firmware.bin and firmware.elf are combined in firmware-factory.bin which is then written to flash.

Sorry, but I have no idea why this is not working in your case.

Was it at one time flashed with Tasmota ?

Yes, I upgraded the shelly firmware over the air to Tasmota and after Tasmota was running I uploaded the ESPHome bin file to upgrade to ESPHome.

I did convert three devices (same type) and one is giving me this problem.

There’s a different storage partition starting with tasmota v12 not compatible with esphome
If you have safe boot partition, then you need to serial flash it

Thank you Francis, going to try that next weekend. Still strange my other shellys don’t have this problem, but it’s worth the try.

I guess i can flash it straight away from the ESPHome web with Webtools right?. No need to prepare the device with a special bin-file to undo the partitioning schema?

Thanks again for your help.

No, should work straight from ESPhome