How to code an energy sensor

Hello everyone…

I thought i did it all right, just to get yelled from HASS for issues.
this is my attempt, but obviously wrong:

  - platform: template
    sensors:
      herd_240:
        friendly_name: "WH Herd double breaker 240v"
        unit_of_measurement: "WH"
        device_class: energy
        state_class: total_increasing
        value_template: "{{ (states('sensor.energymonitor1_circuit_2_daily_energy_2') | float + states('sensor.energymonitor1_circuit_3_daily_energy_2') | float) | round(2) }}"

How would i configure this to show in the energy dashboard?
Thx alot

configuration.yaml (not sensors.yaml)

template:
  - sensor:
      - name: "WH Herd double breaker 240v"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing
        state: "{{ (states('sensor.energymonitor1_circuit_2_daily_energy_2') | float + states('sensor.energymonitor1_circuit_3_daily_energy_2') | float) | round(2) }}"
        availability: "{{ has_value('sensor.energymonitor1_circuit_2_daily_energy_2') and has_value('sensor.energymonitor1_circuit_3_daily_energy_2') }}"

Thx a lot. was not aware of the two different template options…
Will keep it as reference

The legacy template sensor platform is still supported but is not getting new features, like state_class.

You should use the new template integration for new sensors instead.

Do you have an example?

Your config above is the legacy template sensor platform. Mine is the template integration.

Oh ok, got u. Thx

Never mind, i was missing the ) at the end of each line…typical copy paste issue