How to configure sensor for ststistics

Sometime last year, my water consumption sensor stopped appearing in statistics. Obviously HA changed something about it. The only thing HA tells me is, that the sensor must be configured accordingly. The documentation is as usual - too much information and no examples. Can someone help to make the appropriate corrections for me.

  - sensor:
      - name: "water_month"
        unique_id: water_month
        device_class: water
        unit_of_measurement: "m³"
        state: >
          {% set total = states('sensor.mytapwater_total') | float %}
          {% set target = states('sensor.mytapwater_target') | float %}

          {{ (total - target) | round(2, default=0) }}

To have long tern statistics a sensor must have a correct state_class.

  - sensor:
      - name: "water_month"
        unique_id: water_month
        device_class: water
        state_class: total # or total_increasing
        unit_of_measurement: "m³"
        state: >
          {% set total = states('sensor.mytapwater_total') | float %}
          {% set target = states('sensor.mytapwater_target') | float %}

          {{ (total - target) | round(2, default=0) }}

As it appears that you sensor can decrease (total - target) you probably want total instead of total_increasing.