Counter gets reset after setting state manually

Dear Home Assistant Community,

I am getting a bit frustrated in finding the solution to my problem and hope that you can point me in a direction that I am absolutely missing for the last few days. My increasing counters are getting reset daily (which is quite the opposite that a few topics here are about) and I want them to increase continously as they did before. For explanation: All was working well until I decided to go against the saying “never change a running system” and tried to switch from a VM to a docker system. While dealing with some problems in the docker environment, I switched back to my VM, but this is where my problems started…

Here is what I have configured:

I have a sensor which is reading the solar power usage that I am using:

# Solar Power Production Self Usage Calculation Sensor
    - name: solar_power_production_self_usage
      unique_id: "solarpowerproductionselfusage"
      unit_of_measurement: "W"
      device_class: power
      state: >-
        {% set sensorA_value = states('sensor.electricity_current_power_usage') | float(0) %}
        {% set sensorB_value = states('sensor.hoymiles_hm1500_p_ac') | float(0) %}
        {% set calculated_value = sensorA_value - sensorB_value | float(0) %}
        {% if calculated_value < 0 %}
            {% set calculated_value = sensorA_value | float(0) %}
            {% else %}
            {% set calculated_value = sensorB_value | float(0) %}
        {% endif %}
        {{ calculated_value | float(0) }}

I am taking those values and put them into a new Integration - Riemann sum integral sensor (“sensor.solar_power_production_self_usage_counter” - I created the sensor as a helper in the GUI) where they are getting converted into kW/h. The results are being added increasingly so that I can see the total amount of kW/h I used so far.

I have several sensors in the same way created, which are all having the same problem now (solar power excess, cost counter, etc.), but if I understand the problem on one sensor, I am sure I can get the other ones also fixed by myself.

Now comes my problem: After reverting back to the VM and starting up the system, my counters got reset and started from 0 again. I can only explain this to the me somehow with the fact, that the values are not only written in my MariaDB, but must have been somehow also somewhere in the HomeAssistant files somewhere (just a wild guess).
Nevertheless, I then tried to manually set the old values for my counters via the Developer Tools / States, which shows the correct value for a moment, until a new value gets saved. After that, it directly reverts to its initial value.
I am guessing here a missunderstanding from me what “setting a state” means, which might have also caused the trouble. Since then, my counters get reset daily:

Also, I suspect that it could be connected to the following topic somehow, but it would not explain to me why it worked all before my mess up.

https://community.home-assistant.io/t/negative-solar-production-after-midnight-on-energy-dashboard/567146

Is there any chance for me to fix my collected data or do I have to create new sensors?

Thank you in advance for any help!