The easiest way would be to use the tariff feature of the utility meter helper/integration.
When the power sensor is negative then record the energy to a power out tariff, when positive to an energy in tariff. See here for more detail: How to use Utility Meter Tariffs to conditionally measure things