Calculating Kms Run So Far

I use the Strava custom integration.

I am trying to calculate the kms I have run so far by telling HA (with an iput_number) how many runs I have done and the template will calculate by adding the run distances. I know it is messy but it is my first attempt and I’m not too hot with YAML.

When a new run is saved it always saves as the first Strava sensor, the distance sensor being sensor.strava_0_3. So by stating how many runs I have done this week I add all of the distance sensors together, 1 run would be showing the value of sensor.strava_0_3, two runs would be adding the two distance sensors; sensor.strava_0_3 + sensor.strava_1_3, and so on.

So my messy template sensor is this:

   - platform : template
     sensors:
       kms_this_week:
         friendly_name: Kms This Week
         icon_template: mdi:trophy
         unit_of_measurement: kms
         value_template: >-
              "{% if is_state('input_number.runs_this_week', '1.0') %}
              {{ states('sensor.strava_0_3') }}
              {% elif is_state('input_number.runs_this_week', '2.0') %}
              "{{ states('sensor.strava_0_3') | float + states('sensor.strava_1_3') | float }}"
              {% elif is_state('input_number.runs_this_week', '3.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '4.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '5.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '6.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) + states('sensor.strava_5_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '7.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) + states('sensor.strava_5_3') | float | round(2) + states('sensor.strava_6_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '8.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) + states('sensor.strava_5_3') | float | round(2) + states('sensor.strava_6_3') | float | round(2) + states('sensor.strava_7_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '9.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) + states('sensor.strava_5_3') | float | round(2) + states('sensor.strava_6_3') | float | round(2) + states('sensor.strava_7_3') | float | round(2) + states('sensor.strava_8_3') | float | round(2) }}"
              {% elif is_state('input_number.runs_this_week', '10.0') %}
              "{{ states('sensor.strava_0_3') | float | round(2) + states('sensor.strava_1_3') | float| round(2) + states('sensor.strava_2_3') | float | round(2) + states('sensor.strava_3_3') | float | round(2) + states('sensor.strava_4_3') | float | round(2) + states('sensor.strava_5_3') | float | round(2) + states('sensor.strava_6_3') | float | round(2) + states('sensor.strava_7_3') | float | round(2) + states('sensor.strava_8_3') | float | round(2) + states('sensor.strava_9_3') | float | round(2) }}"
              {% else %}
              No Runs So Far 
              {% endif %}"

It is working in Development Tools however now I have added it to my sensors.yaml I get the ffollowing error:

ValueError: Sensor sensor.kms_this_week has device class ‘None’, state class ‘None’ unit ‘kms’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘" 25.36 "’ (<class ‘str’>)

I guess I need to convert from a string to a number but not sure how to do this.

Any help would be appreciated. Thanks in advance

Removed unit_of_measurement has fixed this…