Track a gas meter with ESPHome

Hello!
I don’t know if this is still helpful. I had a similar problem with the inaccurate values. I have now found a solution that is sufficient for my needs. My goal is to track the gas consumption as a whole, i.e. total gas.
My setup:
ESP D1 mini, reed contact with AD converter (like this : Reed Switch).
The solution with pulse_counter and pulse_meter did not work satisfactorily.
My approach with binary_sensor and a template:

binary_sensor:
  - platform: gpio
    id: internal_pulse_counter
    pin: D5
    internal: true
    filters:
      - delayed_on: 100ms
    on_press:
      then:
        - lambda: id(total_pulses) += 1;
sensor:
  - platform: template
    name: "total_gas"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 2
    lambda: |-
        return id(total_pulses) * 0.01;
globals:
  - id: total_pulses
    type: int
    initial_value: '0'