Calculated value returned as string?

I have this legacy configuration which calculates a value from other items:

sensor:
  - platform: template
    sensors:
      consumo_ufficio:
       unique_id: yetopen.consumo_ufficio
       friendly_name: "Consumo ufficio"
       value_template: >-
          {% set tot = states.sensor.shelly_em_assorbimento_ch2_rete.state|float %}
          {% set pdc = states.sensor.shelly_em_assorbimento_ch1_PdC.state|float %}
          {% set vmc = states.sensor.shelly_em_assorbimento_ch2_vmc.state|float %}
          {% set boiler = states.sensor.shelly_em_assorbimento_ch1_boiler.state|float %}
          {{ (tot - pdc - boiler - vmc)|float|round(1) }}

But on the frontend it’s displayed as I string (I suppose), because it doesn’t get graphed:

immagine

I checked several threads but my configuration seems correct. What am I doing wrong?

Thanks

It’s because you never set the unit_of_measurement, as explained here:

Sensors with missing unit_of_measurement are showing as discrete values

1 Like

thank you!!