How to save counter data when ESP is reset?

I have a water meter in esp home.
Everything works fine until I make changes to the ESP code.
After that, the sensor is reset. How can I make the meter data be saved?
I made another meter in a separate home assistant package, but it is also reset.



This counter in ESP home:


    total:
      unit_of_measurement: 'litr'
      name: 'лічильник води загальний'
      state_class: total_increasing
      device_class: water
      accuracy_decimals: 1
      filters:
      - lambda: return (x / 17.0);  



This counter in package home assistants :


  sensor:
        - platform: template
          sensors:

            socket:
              friendly_name: 'Лічильник води новий '
              device_class: volume
              unit_of_measurement: 'літри'
              value_template: "{{ (states('sensor.bolernaj_2') | float) | round(3)}}"        

If you upload new code, i think the best way is to manually set the total with
pulse_counter.set_total_pulses: