Cannot update OTA

Here is my program:

 
esphome:
  name: button2
  friendly_name: Button2
  comment: Remote Button



esp32:
  board: esp32dev
  #framework:
    #type: arduino
    

packages:
  base:     !include { file: A_package/basic.yaml,              vars: { uptime_update_inverval: 10sec }}
``
And the package that I use for all my ESP devices.
```# This is the package used in all my Esphome Devices
#
#  FOLLOWINGS Substitutions MUST be defined
#    - devicename                 : This is used to define the SSID name
#    - esp_id                     : This used a prefix to all entities name
#    - Uptime_update_inverval     : This used to determine update interval

esphome:
  name: ${devicename}

# Enable logging
logger:

api:        # Enable Home Assistant APIx   API is used to communicate directly with Home Assistant

 # encryption:
  #  key: !secret encryption_key
  

ota:        #Enable OverTheAir ota update
  - platform: esphome
    password: !secret ota_password

wifi:
 ssid: !secret wifi_ssid
 password: !secret wifi_password
 ap:              # Enable an access point mode on the node in case wifi connection fails
   ssid: ${devicename}
   password: !secret ap_wifi_password

captive_portal: # component is a fallback mechanism for when connecting to the configured WiFi fails

switch:
  - platform: restart           # To restart your node remotely through Home Assistant.
    name: "Restart"

  - platform: shutdown          # To shutdown when the battery is below the minimu, level
    id: my_shytdown
    name: "Shutdown"

sensor:
  - platform: wifi_signal       # Read the signal strength of the currently connected WiFi Access Point
    name: "WiFi Signal" # wifi force
    update_interval: 5min       # update every 5 minutes

binary_sensor:
  - platform: status
    name: "Status"
    entity_category: diagnostic

text_sensor:    # Text Sensor with general information

  - platform: wifi_info               # Expose WIFI information
    ip_address:
      name: IP Address
    ssid:
      name: Connected SSID
    bssid:
      name: Connected BSSID
    mac_address:
      name: Mac Wifi Address

  - platform: template
    name: Uptime
    id: new_uptime
    icon: mdi:clock-start
    update_interval: ${uptime_update_inverval}
    lambda: |-
      auto s = millis() / 1000;
      return str_snprintf("%02d:%02d:%02d:%02d", 11, s / 86400, s / 3600 % 24, s / 60 % 60, s % 60);
output:

light:

web_server:
    port: 80

I can compile my program and upload when connected to my Rasberry Pi. Then I can “Visit” it and LOGS Wirelessly.
However when I try to install it wirelessly, It compile and upload when stop there. Here is the log:

INFO ESPHome 2024.6.1
INFO Reading configuration /config/esphome/button2.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing button2 (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.3
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- ArduinoJson @ 6.18.5
RAM:   [=         ]  12.4% (used 40788 bytes from 327680 bytes)
Flash: [=====     ]  49.4% (used 905657 bytes from 1835008 bytes)
========================= [SUCCESS] Took 17.87 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 10.0.0.249
INFO Uploading /data/build/button2/.pioenvs/button2/firmware.bin (911536 bytes)
Uploading: [============================================================] 100% Done...

INFO Upload took 11.18 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 10.0.0.249 using esphome API
WARNING Can't connect to ESPHome API for button2 @ 10.0.0.249: Timeout while connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='10.0.0.249', port=6053))] (TimeoutAPIError)
INFO Trying to connect to button2 @ 10.0.0.249 in the background

Text

I remove the device from ESPhome integration and reinstalled it. Without succes.
Any ideas to get it to work !

I had the same problem. Deleted the ota password and it worked fine.

Resolved.
I did not remove the password for OTA, because the same package is used for 5 other esp devices and works perfectly.
I did not included my substitution ${devicename} in the main program