How to set "state_class: total" correctly?

In order to use a statistic diagram to display rain sensor data in an hourly/daily manner it is needed to set
state_class: total as described here

I tried following configuration. But getting this error:

Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->rain_total->state_class. (See ?, line ?). 
sensor:
  - platform: rest
    name: regensensor
    json_attributes:
      - devices
    resource: https://www.data199.com/api/pv1/device/lastmeasurement
    method: POST
    headers:
      Content-Type: application/json
    payload: '{"deviceids": "083F7F2A2320"}'
    value_template: "{{ value_json.success }}"
    scan_interval: 120
    state_class: total
    
  - platform: template
    sensors:
      rain_total:
        friendly_name: "Regen gesamt"
        value_template: "{{ state_attr('sensor.regensensor', 'devices')[0]['measurement']['r'] }}"
        unit_of_measurement: "mm"
        state_class: total

Without “state_class: total” set the the config works fine but the sensor is not shown in the statistic diagram configuration.

How to set “state_class: total” correctly?

Set it in customize.yaml.