Shelly 3em sensor for energy tab

Hello there,im using a Shelly 3em sensor to gather data from my 3 phases,im using mqtt,i created a succesfull template that sum up the 3 phases,here is the code

sensor:
  - platform: template
    sensors:
      total_power_consumption:
        friendly_name: "Total Power Consumption"
        unit_of_measurement: "kWh"
        icon_template: mdi:flash
        value_template: >-
          {{ (states('sensor.3EM_L1_Total_Kwh_MQTT') | float(0) + 
              states('sensor.3EM_L2_Total_Kwh_MQTT') | float(0) + 
              states('sensor.3EM_L3_Total_Kwh_MQTT') | float(0)) | round }}

But this is not importable for the energy tab,how can i make a sensor that sum up the 3 phases so i can import it in the energy dashboard?

you need to add device_class. probably energy.

Also add option to continue increasing energy when 3EM resets to zero. See total_increasing

My suggestion is to record power instead of enegy, then create a Riemann sum integral helper. IMO it’s more reliable than rely on reported energy by 3EM

I can’t use state_class or device_class on a template it’s not compatible

You should be able to add device_class and state_class directly after your icon_template line,

sensor:
  - platform: template
    sensors:
      total_power_consumption:
        friendly_name: "Total Power Consumption"
        unit_of_measurement: "kWh"
        icon_template: mdi:flash
        device_class: energy
        state_class: total_increasing
        value_template: >-
          {{ (states('sensor.3EM_L1_Total_Kwh_MQTT') | float(0) + 
              states('sensor.3EM_L2_Total_Kwh_MQTT') | float(0) + 
              states('sensor.3EM_L3_Total_Kwh_MQTT') | float(0)) | round }}

Sorry i didnt see the answer before,thank you for your info but i still get this error
Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->total_power_consumption->state_class

I’m wondering if there was a format change in a past update. You’re using - platform: template and I don’t have that inn mine.
This is what I’m using:

template:
  - sensor:
    - name: "Total Energy Used"
      availability: >
        {{ states('sensor.channel_1_energy') not in ['unavailable', 'unknown'] and
        states('sensor.channel_2_energy') not in ['unavailable', 'unknown'] }}  
      state: >-
        {% set state1 = states("sensor.channel_1_energy")|float(0) %}
        {% set state2 = states("sensor.channel_2_energy")|float(0) %}
        {% if is_number(state1) and is_number(state2) %}
        {{ ( state1|float(0) + state2|float(0)) | round(2) }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing