Nodemcu esp 8266 and relay on restart or boot

I have a problem with the nodemcu and 4 channel relays. every time the nodemcu turns on or restarts from a voltage and causes the relays to activate for half a second and then return to the standy position. The same hardware with an arduino sketch didn’t give the problem, I also took an uninitialized nodemcu connected to the relays in the same way and the problem doesn’t appear, so there’s something wrong in writing the code in esphome. who can help me please

below is the esphome code

switch:
  - platform: gpio
    pin: D1 #D1 pin is GPIO 5 (Ricircolo ACS RELE IN1)
    inverted: true
    id: rele_acs
    name: "Ricircolo ACS"
    icon: "mdi:water-pump"
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: rele_acs

  - platform: gpio
    pin: D2 #D2 pin is GPIO 4 (PULSANTE Pompa Anticondenza RELE IN1)
    id: rele_anticondenza
    inverted: true
    name: "Spegnimento Pompa Anticondenza"
    icon: "mdi:pump"

  - platform: gpio
    pin: D7 #D7 pin is GPIO 13 (Cancello Grande RELE IN1)
    inverted: true
    id: rele_cancello_grande
    name: "Cancello Grande"
    icon: "mdi:gate"
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: rele_cancello_grande

  - platform: gpio
    pin: D5 #D5 pin is GPIO 14 (Cancello Piccolo RELE IN1)
    inverted: true
    id: rele_cancelletto
    name: "Cancelletto"
    icon: "mdi:door-closed-lock"
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: rele_cancelletto   

text_sensor:
  - platform: version
    name: "Serrature-ACS-Pompa ESPHome Version"

sensor:
  - platform: wifi_signal
    name: "Serrature-ACS-Pompa WiFi Signal"
    update_interval: 60s 
    type or paste code here