How can i add 2 values and set result as a sensor

I have looked/searched but cannot find it.
How can i add these 2 values and set result to a new sensor?

Part from sdm meter:

 - platform: sdm_meter
    address: 2
    phase_a:
      current:
        name: "phase 1 current"
      active_power:
        name: "phase 1 power"
    phase_b:
      current:
        name: "phase 2 current"
      active_power:
        name: "2 power"

New sensor to be made:
Total power L1-L2: (phase 1 power + phase 2 power)

Thanks for pointing me in the right direction.
I have created this now:
It does compile in esphome, the totalpower entity is generated in home assistant, but no value is there.
my code:

sensor:
  - platform: sdm_meter
    address: 2
    phase_a:
      current:
        name: "Nibe heatpump f2120 phase 1 current"
      active_power:
        name: "Nibe heatpump f2120 phase 1 power"
        id: power1
    phase_b:
      current:
        name: "Nibe heatpump f2120 phase 2 current"
      active_power:
        name: "Nibe heatpump f2120 phase 2 power"
        id: power2
    phase_c:
      current:
        name: "Nibe heatpump f2120 phase 3 current"
      active_power:
        name: "Nibe heatpump f2120 phase 3 power"
        id: power3
    export_active_energy:
      name: "Nibe heatpump f2120 kwh"
    update_interval: 60s
    
  - platform: template
    name: "Nibe heatpump f2120 power"
    id: totalpower
    lambda: !lambda |-
      float totalpower;
      totalpower = (id(power1).state) + (id(power2).state) + (id(power3).state);
      return totalpower;

What am i doing wrong?

It works,
Had to restart HA to get the entity to update.
Above code is unchanged.

1 Like