You must add all statistic-needed attributes (unit_of_measurement, device_class & state_class).
Check my template sensor config (water pulse meter data from nodemcu running tasmota):
- name: "water_meter_total_m3"
state: >
{{ states('counter.voda') |float * 0.001 }}
unit_of_measurement: m³
device_class: water
state_class: total_increasing