Gas counter adjustment not working (resetted automatically)

Hi everyone,

I have created a counter helper which counts the impulses of my gasmeter. (counter.gas_zahler_rohwerte)
This counter has a initial value and a step of 1 representing 0.01m³
The counter is used for two sensors as the source:

- platform: template # Gas in m³
  sensors:
    gas_meter:
      friendly_name: Gas gesamt [m³]
      unit_of_measurement: "m³"
      icon_template: "mdi:counter"
      device_class: gas
      value_template: "{{ states ('counter.gas_zahler_rohwerte') | float(0) * 0.01}}"
- platform: template # Gas in kWh
  sensors:
    gas_meter_kwh:
      friendly_name: Gas gesamt [kWh]
      unit_of_measurement: "kWh"
      icon_template: "mdi:counter"
      device_class: energy
      value_template: "{{ states ('counter.gas_zahler_rohwerte') | float(0) * 0.01 * 11.5}}"

My problem is, that the counter sometimes misses the pulse from the reed sensor (modified window contact).
Therefore I need to adjust the value of the counter every now and then.
However, if I do so using the developer tools (set state) it works, but then will be reset to the previous value after a while (next “real” pulse obviously).

Questions:

  1. Is there a reason for this I don’t get?
  2. How to adjust such counters permanently?

Thanks in advance!

No one with an idea what I am doing wrong?