Creating a new sensor to fix unit issue in energy counter

Preamble: until a few months ago I was reading the PV production using a shellyEM. I changed the inverter, added a battery and since then I could not use the same sensor anymore.

I didn’t want to loose my “history” in the energy dashboard, therefore I created a new template sensor witch included the “last total” of the ShellyEM plus the values incoming from the new sensor while using the old name. By doing this I was able to keep history while adding the new values.

        - name: shellyem_1_energy
          unit_of_measurement: "kWh"
          device_class: energy
          state_class: total_increasing
          state: >
             {{ 5091.3482 + (states('sensor.solar_energy_riemann')|float(0) * 0.001 )  }}

The inverter / integration didn’t actually provide the output energy, therefore I had to use the riemann integration to calculate it.

- platform: integration
  source: sensor.input_power_with_efficiency_loss
  name: solar_energy_riemann
  round: 3

I know it might be wrong, but somehow it worked. Unfortunately I didn’t use the “unit prefix” in the integration, therefore the number in Watts is growing rapidly. As far as I know python should be able to manage also high numbers, but I’d prefer to do everything in kWh.

- platform: integration
  source: sensor.input_power_with_efficiency_loss
  name: solar_energy_riemann_kWh
  unit_prefix: k
  round: 4

How should I edit the name: shellyem_1_energy total counter in order to use the new solar_energy_riemann_kWh?

Thank you!

Anyone? Do I need to clarify something better?