Home Assistant Energy - Return to grid not working

I think this is about as straightforward as it gets, but given that I have no direct experience with this yet, I hope I can get it right.

HA Energy wants to know three things:

  1. How much energy was imported from the grid.
  2. How much energy was exported to the grid.
  3. How much energy was generated locally.

You have said that your solar has the ability to drive your mains negative, so that indicates you have what is by OEM convention a type-2 solar service, meaning the solar inverter feed downstream (on the load side) of your mains. So your single CT on the mains provides all the data you need for items 1 and 2. Import is the positive component and export is the negative component.

I would change MainsConsumption as you have it to Consumption = GRID + SOLARPRODUCTION

Then define a new output MainsImport as GRID max 0 that satisfies Item 1 above. MainsExport satisfies item 2. SOLARPRODUCTION satisfies item 3.

Now change the YAML configuration entry to:

sensor:
  - platform: integration
    source: sensor.MainsImport
    name: import_wh_calculated
    unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.MainsExport
    name: export_wh_calculated
    unit_prefix: k
    round: 2

.
The Energy configuration stays the same, except Solar production is changed to SOLARPRODUCTION_wh

Give that a try. Unlike influxDB or PVoutput, there is no way that I’m aware of to update the history in Hass, so unfortunately this will only take effect going forward.

Thanks for posting this, please post your results in a day or two when it shows results. This is exactly the simpler example I had in mind as it’s more of a typical case. Once (if) this proves out. I’ll elaborate on the simple changes needed for split-phase systems and type 1 (solar feed upstream of the mains) systems.