Split kWh according to solar

Hi all

I want to split the recorded kWh for a heatpump into grey and green energy.

I first made a “Perc_Solar” entity, which gives values 0-100% depending on the ratio: device usage / solar output .

Now I want to measure “green kWh” and “grey kWh”.

I first tried to do this, hoping the recorded kWh would directly be split by the percent solar

utility_meter:
 wp_green_kwh:
     source: sensor.wp_kwh*states('Perc_Solar')
     name: WP green kWh
 wp_grey_kwh:
     source: sensor.wp_kwh*(1-states('Perc_Solar'))
     name: WP grey kWh

I now went on using the W measure of the heatpump, splitting that in a template sensor in grey and green wattage, and then convert back to kWh using the integration sensor. It works, but feels a bit cumbersome like this. Is there a way to directly make a ratio on the kWh sensor increments, and have them increment in something like the utility meter?