How to detect direction of electrical energy flow

I have a solar panel and a Nibe heatpump with current transformers installed to main braker panel. I can successfully monitor the solar production and electrical energy consumption. However, the current transformers wont detect the direction of energy flow, so the senor values are always positive even if solar production exceeds my consumption. Is there any way to detect the change of energy flow direction? I could probably create an automation that tries to estimate the flow direction from the sensor values.

Maybe you can use a Shelly EM to detect the direction of energy flow?