Energy Meter Template sensor

I have a binary sensor which tells me when im connected (consuming my energy from) the Grid Electricity and another for the Solar.

and I have an energy_kwh sensor for the whole house, which accumulates the energy used by the house.

I would like to create a sensor that would show me the energy_solar_kwh and another for the energy_grid_kwh.

So the energy_solar_kwh should increment the difference between when it started energy_kwh and how much it is now.

This is what I have written so far.

I would be grateful for any help

      - name: "edl_kwh"
        unique_id: "edl_kwh"
        unit_of_measurement: "kWh"
        state_class: total_increasing
        device_class: energy
        state: >
             {% if is_state('binary_sensor.electricity_state', 'off') %}
                {{(states('sensor.Energy_H')|float + states('sensor.Energy_L')|float)}}
             {% else %}
             {% endif %}