It is impossible to update (write) a new code

on some ESP boards, it is not possible to write the code after making edits or flash a new board , freezes at the compilation stage ( apparently the server does not respond )
here is an example code :

esphome:
  name: esp-s2-garage
  friendly_name: ESP32 S2 Garage

esp32:
  board: lolin_s2_mini
  framework:
    type: arduino

logger:
#  level: VERBOSE
# logs:
#    switch: ERROR
#    text_sensor: ERROR

api:


ota:
  - platform: esphome

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

  ap:
    ssid: "Esp-S2-Garage"
    password: "Milk33kg"

  manual_ip:
    static_ip: 192.168.2.23
    gateway: 192.168.2.88
    subnet: 255.255.255.0

web_server:
  port: 80
  version: 3

captive_portal:

i2c:
  - scan: True

# Приемник 433МГц
remote_receiver:
  pin: 3
  dump: rc_switch
  tolerance: 50%
  filter: 200us
  idle: 3ms # 4ms
  buffer_size: 2kb

# Передатчик 433МГц
remote_transmitter:
  pin: 40
  carrier_duty_percent: 100%

binary_sensor: # Вход

# Вход бинарный (Pin 1-5)
  - platform: gpio
    pin:
      number: 39
      inverted: True
    device_class: door
    name: "Pin1" # Вход рол гараж
    filters:
      - delayed_on: 50ms # Фильтр дребезга (задержка 50 мс)
    on_press:
      then:
        - switch.turn_on: rel2
    on_release:
      then:
        - delay: 120s
        - switch.turn_off: rel2

  - platform: gpio
    pin:
      number: 37
      inverted: True
    device_class: door
    name: "Pin2" # Вход род двор
    filters:
      - delayed_on: 50ms # Фильтр дребезга (задержка 50 мс)

  - platform: gpio
    id: d12
    pin:
      number: 12
      inverted: True
    device_class: door
    name: "Pin3"  # Калитка
    filters:
      - delayed_on: 50ms # Фильтр дребезга (задержка 50 мс)
    on_press:
      - script.execute: activate_relay_script
    on_release:
      - script.stop: activate_relay_script
      - script.stop: repeat_script 

  - platform: gpio
    pin: 21
    name: "Pin4" # Вход кнопка света во дворе
    filters:
      - delayed_on: 50ms # Фильтр дребезга (задержка 50 мс)
    on_click:
    - min_length: 50ms
      max_length: 350ms
      then:
        - switch.toggle:  rel3
    - min_length: 2500ms
      max_length: 10s
      then:
        - switch.toggle: rel4
        - delay: 800ms

        - switch.toggle: rel3
        - delay: 350ms
        - switch.toggle: rel3
        - delay: 350ms
        - switch.toggle: rel3
        - delay: 350ms
        - switch.toggle: rel3
        - delay: 350ms
        - switch.toggle: rel3
        - delay: 350ms
        - switch.toggle: rel3

        
  - platform: gpio
    pin: 17
    name: "Pin5"
    filters:
      - delayed_on: 50ms # Фильтр дребезга (задержка 50 мс)

# Бинарный датчик RF (433МГц)
  - platform: remote_receiver
    name: "Remote Input1"
    rc_switch_raw: 
      protocol: 2 
      code: '000111110101010000110000'  
    filters:
      - delayed_off: 80ms # Фильтр дребезга (задержка 50 мс)
    on_press: 
      - then:
        - switch.toggle: rel3
  - platform: remote_receiver
    name: "Remote Input2"
    rc_switch_raw: 
      protocol: 2  
      code: '000111110101010000011111'  
    filters:
      - delayed_off: 80ms # Фильтр дребезга (задержка 50 мс)
  - platform: remote_receiver
    name: "Remote Input3"
    rc_switch_raw: 
      protocol: 2  
      code: '000111110101010000100000' 
    filters:
      - delayed_off: 80ms # Фильтр дребезга (задержка 50 мс)
  - platform: remote_receiver
    name: "Remote Input4"
    rc_switch_raw: 
      protocol: 2  
      code: '000111110101010000100001'  
    filters:
      - delayed_off: 80ms # Фильтр дребезга (задержка 50 мс)

# Датчик протечки воды 1 (новый сенсор!)
  - platform: remote_receiver
    name: "Water Leak Sensor"  # датчик протечки 1 в офисе 
    device_class: moisture
    rc_switch_raw: 
      protocol: 1  
      code: '001110001000011001011001'  
    filters:
      - delayed_off: 10s # Фильтр дребезга (задержка 80 мс)

  - platform: remote_receiver
    name: "Water Leak Sensor2"  # датчик протечки 2
    device_class: moisture
    rc_switch_raw: 
      protocol: 1  
      code: '101000000000111110101001'  
    filters:
      - delayed_off: 10s # Фильтр дребезга (задержка 80 мс)

# Микроволновый сенсор
  - platform: gpio
    pin: 16
    name: "PIR Sensor Office"
    device_class: motion
    filters:
      - delayed_on: 5000ms

sensor:
# Температура,влажность , давление
  - platform: aht10
    variant: AHT20
    temperature:
      name: "Temperature aht20"
    humidity:
      name: "Humidity aht20"
    update_interval: 29s
  - platform: bmp280_i2c
#    temperature:
#      name: "Temperature bmp280"
#      oversampling: 16x
    pressure:
      name: "Pressure bmp280"
    address: 0x77
    update_interval: 31s

switch: # Выход
# Реле
  - platform: gpio
    pin: 5
    id: rel4
    name: "Блокировка роллет" # Реле вкл ролет

  - platform: gpio
    pin: 7
    id: rel3
    name: "Свет во дворе" # Rel3 Реле вкл свет во дворе 

  - platform: gpio
    pin: 9
    id: rel2
    name: "Свет в гараже " #Rel2 Реле вкл свет в гараже

  - platform: gpio
    pin: 11
    id: rel1
    name: "Rel1"

# Индикатор работы esp32(мигает , пин15)
  - platform: gpio
    pin:
      number: 15 
      mode: output
    id: builtinLED

interval:
  - interval: 2000ms
    then:
      - switch.toggle: builtinLED

text_sensor:
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
    ssid:
      name: ESP Connected SSID
    bssid:
      name: ESP Connected BSSID
    mac_address:
      name: ESP Mac Wifi Address
    scan_results:
      name: ESP Latest Scan Results
    dns_address:
      name: ESP DNS Address

script:
  - id: activate_relay_script
    mode: restart
    then:
      - delay: 300s
      - script.execute: blink_sequence  # Первый набор импульсов
      - script.execute: repeat_script   # Запуск циклического повтора

  - id: blink_sequence
    then:
      - repeat:
          count: 6
          then:  # <---- 
            - switch.toggle: rel3
            - delay: 350ms

  - id: repeat_script
    mode: restart
    then:
      - delay: 60s
      - if:
          condition:
            binary_sensor.is_on: d12  # Проверка удержания кнопки
          then:
            - script.execute: blink_sequence
            - script.execute: repeat_script

and at this stage it stops :

INFO ESPHome 2025.10.4
INFO Reading configuration /config/esphome/esp-s2-garage.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp-s2-garage (board: lolin_s2_mini; framework: arduino, espidf; platform: https://github.com/pioarduino/platform-espressif32/releases/download/54.03.21-2/platform-espressif32.zip)
--------------------------------------------------------------------------------
INFO Package configuration completed successfully
Library Manager: Installing bblanchon/ArduinoJson @ 7.4.2
INFO Installing bblanchon/ArduinoJson @ 7.4.2
Downloading  [------------------------------------]    0%

Until someone more knowledgeable about ESPHome than I comes along, I’ll take a shot at this one:

Where are you running the compile? If it’s on the HA host (using the ESPHome Builder add-on) and it’s a low-end machine, then I’d suspect you’re running out of memory or overloading the CPU during the compile. Obviously none of that applies if your host has excess capacity of both.

1 Like