Count solar / grid (day and night) energy cunsumption of a device (EV charger)

I will explain my situation quickly:

  • I have solar panels (and associaced mesurements of solar / grid energy)
  • I will have an electric car and will charge either at night or at day (during weekends)

I’m assuming that the rest of the house is the one consuming the solar power first so if i’m pulling 1 kW from grid, the EV charger is pulling 2 kW, i consider that the EV charger is consuming 1 kW fom the grid and 1 kW from the solar panels. That will simplify all calculations

I want to count the energy that goes into the EV in several categories:

  • Solar energy
  • Grid energy (peek tarif)
  • Grid energy (off peek tarif)

The resource below was close to what i want to acheive but its binary (it counts either as one category or the other)and i need to split energy form the grid and from the sun because there will be occurences where it will come form both at the same time

How would you approch this problem ?

Use three tariffs and a sensor with three states to switch between them.

Thanks, i’ll try that once i received everything and update