Template definition error - numeric and string values

Hi,

(first post, so please be patient)
I want to create a helper sensor which calculates the sum of 2 sensors.
In fact it does the calculation (the 7.1 in the error message below), but do not shows it due to an error for non-numeric and string.
Searched and tried several variants but ending always in the same issue of non-numeric values. Where is the error?

Here my template code (created in UI) and below the error.

- platform: template
   sensor:
    fritzbox_gb_total:
      friendly_name: 'FRITZ!Box 7590 AX Hauptrouter GB insgesamt'
      entity_id:
        - sensor.fritz_box_7590_ax_gb_empfangen
        - sensor.fritz_box_7590_ax_gb_gesendet
      value_template: {{ states.sensor.fritz_box_7590_ax_gb_gesendet.state |float(0) + states.sensor.fritz_box_7590_ax_gb_empfangen.state |float(0) }}

Error:
Sensor None has device class ‘data_size’, state class ‘total_increasing’ unit ‘GB’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘- platform: template sensor: fritzbox_gb_total: friendly_name: ‘FRITZ!Box 7590 AX Hauptrouter GB insgesamt’ entity_id: - sensor.fritz_box_7590_ax_gb_empfangen - sensor.fritz_box_7590_ax_gb_gesendet value_template: 7.1’ (<class ‘str’>)

This is the only part you put in the UI template sensor.

And you should heed this warning:
https://www.home-assistant.io/docs/configuration/templating/#states

So:

{{ states('sensor.fritz_box_7590_ax_gb_gesendet') |float(0) + states('sensor.fritz_box_7590_ax_gb_empfangen') |float(0) }}

Thanks a lot! :bouquet:

Obviously I am not experienced enough yet to know the difference between the UI components and what is only in code/yaml. Took an example as starting point which was obviously not made for the UI editor.

With the states I read before. Just tried so many things around (obviously on the wrong places) that it was in the last version.

Thanks again

1 Like