I tried using EEPROM on Esphome by lambda but I need help with this simple code

I want some variables to survive my esp 32 completely powering on and off. I saw we can include eeprom library so I tried doing it using lambda. I created a simple code but it has lots of error I don’t even know how to resolve. I have no programming background, I just learn.

esphome:
  name: esphome-web-43f658
  friendly_name: Floodgate
  libraries:
    - EEPROM


esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "NFbUsURD0HMB2gn/MMM8nHFCOS/lx6naQmfXhKwWJ/E="

ota:


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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-43F658"
    password: "BtYZbqTvD8Yz"

captive_portal:
    
globals:
   - id: button
     type: int

   - id: testint
     type: int


switch:
  - platform: template
    name: "Test"
    id: test
    optimistic: True
    on_turn_on:
      then:
        - lambda: |-
           id(testint) = 2;
        - script.execute: scrip

    on_turn_off:
      then:
        - lambda: |-
           id(testint) = 1;
        - script.execute: scrip

          

binary_sensor:
  - platform: template
    name: "Sensor"
    id: sensor

script:
  id: scrip
  then:
    - lambda: |-
        
        #include <EEPROM.h>
        #define EEPROM_SIZE 12
        Serial.begin(115200);
        EEPROM.begin(EEPROM_SIZE);

         if (id(testint) == 1) {
          EEPROM.write(0, 4);
          EEPROM.commit();
         } else {
          EEPROM.write(0, 8);
          EEPROM.commit();
         }

The errors I get:

In file included from /config/esphome/esphome-web-43f658.yaml:72:
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h: In lambda function:
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:52:5: error: invalid declaration of member template in local class
     template<typename T>
     ^~~~~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:61:5: error: invalid declaration of member template in local class
     template<typename T>
     ^~~~~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:88:5: error: invalid declaration of member template in local class
     template <class T> T readAll (int address, T &);
     ^~~~~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:107:5: error: invalid declaration of member template in local class
     template <class T> T writeAll (int address, const T &);
     ^~~~~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:118:20: error: 'setup()::<lambda()>::EEPROMClass EEPROM', declared using local type 'setup()::<lambda()>::EEPROMClass', is used but never defined [-fpermissive]
 extern EEPROMClass EEPROM;
                    ^~~~~~
Compiling /data/esphome-web-43f658/.pioenvs/esphome-web-43f658/lib64d/WiFi/WiFiServer.cpp.o
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h: At global scope:
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:46:10: warning: 'bool setup()::<lambda()>::EEPROMClass::commit()' used but never defined
     bool commit();
          ^~~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:44:10: warning: 'void setup()::<lambda()>::EEPROMClass::write(int, uint8_t)' used but never defined
     void write(int address, uint8_t val);
          ^~~~~
/data/cache/platformio/packages/framework-arduinoespressif32/libraries/EEPROM/src/EEPROM.h:42:10: warning: 'bool setup()::<lambda()>::EEPROMClass::begin(size_t)' used but never defined
     bool begin(size_t size);
          ^~~~~
*** [/data/esphome-web-43f658/.pioenvs/esphome-web-43f658/src/main.cpp.o] Error 1
========================== [FAILED] Took 7.89 seconds ==========================