Adding new Consumed Energy sensor to Energy tab

In Energy tab I am tracking energy consumed by 3 entities (X, Y and Z) from Shelly directly (Shelly 1PM and Shelly EM). I want to add new entity (A) which will show consumed energy as A = X - Y - Z but I don’t know how to define new entity A to be visible and addable within Energy tab?

I tried with:

- name: "Snaga DT kompresor solo"
    unique_id: "Snaga DT kompresor solo"
    state_class: total_increasing
    state: "{{ (states('sensor.kompresor_energy') | float - states('sensor.podno_prizemlje_energy') | float - states('sensor.podno_kat_energy_2') | float) }}"
    unit_of_measurement: 'kWh'

but it is not visible.

If I defined A as:

energija_kompresor_dt:
    source: sensor.snaga_dt_kompresor_solo
    name: DT Kompresor Solo energija

it is visible but value of A is equal to value X as in picture:

Thank you.

You’re missing a device_class of energy.

Thanks. I previosuly defined device_class as energy but where do you think it should be defined? Within first chunk of code or second where energija_kompresor_dt: is defined.
If it is in second, it is visible in Energy tab without defined device_class but it is showing same value as directly from Shelly EM without decreasing.

Here.

I don’t really understand what you’re even doing with that second part or where you’re putting it.

No… If I define:

  - name: "Snaga DT kompresor solo"
    unique_id: "Snaga DT kompresor solo"
    state_class: total_increasing
    device_class: energy
    state: "{{ (states('sensor.kompresor_energy') | float - states('sensor.podno_prizemlje_energy') | float - states('sensor.podno_kat_energy_2') | float) }}"
    unit_of_measurement: 'kWh'

it is still not visible within Energy tab.

It is only visible if I add this second part:

utility_meter:
   energija_kompresor_dt:
      source: sensor.snaga_dt_kompresor_solo
      name: DT Kompresor Solo energija