Template - State_Class: total_increasing

Hello

I tried to create a new sensor for energy :slight_smile:

 - platform: template
   sensors:
        shelly_energy:
          friendly_name: "Shelly total Energy KWH"
          unit_of_measurement: 'kWh'
         #  state_class: total_increasing
          value_template: "{{ states('sensor.shellyem3_bcff4dfd1d62_channel_a_energy') |float  + states('sensor.shellyem3_bcff4dfd1d62_channel_b_energy') }}" 
          device_class: "energy"

but I am not able to choose the state_class: total increasing in order to include it in the energy board

Do you have any idea how to create such sensor ?

Thank you

That’s because your Template Sensor is configured in legacy format which doesn’t support the state_class option.

You can add state_class: total_increasing to it via Manual Customization or re-configure it in modern format.

Hi thank I move all to my template.yaml and all is working !

Glad to hear that switching to modern format resolved the problem.

Please consider marking my post with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other words that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

Hi, can you show your template.yaml how it is, because the state_class: “total_increasing” doesn’t work for me, it keeps reporting an error in template.yaml. I have to edit it in customize.yaml.

#template:
sensors:
virtual_battery_p5:
friendly_name: “Virtualna Bateria P5”
unit_of_measurement: “kWh”
device_class: energy
value_template: “{{ states(‘sensor.power5’) }}”

state_class: “total_increasing”

icon: mdi:battery-charging-30

`