PV sold to grid + own usage = total earings calculations using Nordpool hourly prices

I want to find a way how to calculate the money i have earned from selling the energy to grid (Nordpool without VAT) and how much i have saved using the solar energy (nordpool with VAT + tariffs). Lets call it total earnings. Probably something similar to the Energy Dashboard logic.

So what i have:

Prices.

  1. Nordpool hourly price (current price) excluding VAT: sensor.nordpool_kwh_ee_eur_3_10_0
  2. Nordpool hourly price (current price) including VAT: sensor.nordpool_kwh_ee_eur_3_05_02
  3. Network fee, or Tariff: sensor.el_tariff
    *Actually i have the sensor.total_el_price, which sums the 1. and 3. and which i’m using in Energy Dashboard

Returned electricity to the grid

  1. Phase 1: sensor.phase_1_energy_returned
  2. Phase 2: sensor.phase_2_energy_returned
  3. Phase 3: sensor.phase_3_energy_returned

PV production:
Only one sensor that sums the three Phases: sensor.inverter_total_yield. Usually it produces equal amount on all three phases.

I have managed to make template sensors to calculate “sold to grid” and “used by myself” energy:

  - platform: template
    sensors:
      sold_to_grid_energy:
        friendly_name: "Sold to Grid energy"
        unit_of_measurement: "kWh"
        value_template: >-
          {{ (states('sensor.phase_1_energy_returned') | float + 
               states('sensor.phase_2_energy_returned') | float + 
               states('sensor.phase_3_energy_returned') | float) }}
  - platform: template
    sensors:
      used_self_pv_energy:
        friendly_name: "Used Self PV Energy"
        unit_of_measurement: "kWh"
        value_template: >-
          {% set pv_production = states('sensor.inverter_total_yield') | float %}
          {% set energy_returned = states('sensor.phase_1_energy_returned') | float + 
                                   states('sensor.phase_2_energy_returned') | float + 
                                   states('sensor.phase_3_energy_returned') | float %}
          {% set used_self_pv = pv_production - energy_returned %}
          {{ used_self_pv }}

Now next step would be to calculate the earnings based on usage during specific hours and then cumulatively. This actually excaclty what Energy Dashboard is doing, and actually I have at least the energy sold numbers from there, but not used PV energy numbers and because of that i would like to replicate it outside of Energy Dashboard. Seems like a simple task as it has been already done in Energy Dasboard, but i’m out of ideas how to move on.

Would be extremely nice if Energy Dashboard could calculate this out of the box.

In the end I would like to see:

  1. Daily PV energy sold - kwh and € (already in Energy Dashboard)
  2. Daily PV energy self used - kwh and €
  3. Daily total PV earning - kwh and €
  4. Monhtly PV energy sold - kwh and € (already in Energy Dashboard)
  5. Monhtly PV energy self used - kwh and €
  6. Monthly total PV earning - kwh and €
  7. Yearly PV energy sold - kwh and € (already in Energy Dashboard)
  8. Yearly PV energy self used - kwh and €
  9. Yearly total PV earning - kwh and €
  10. All Time PV energy sold - kwh and € (already in Energy Dashboard)
  11. All Time PV energy self used - kwh and €
  12. All Time total PV earning - kwh and €

In Energy Dashboard can be done with the current filter and only self used money calculations are needed.

But I doubt it will happen, so i need to replicate the logic somehow