Power meter, export import energy

Hi,

I need to create power meter in HA witch one it can to count separatly exported and imported energy. Entity what I have is current power. So it’s show for ex. 500W import or -500W export.

How to create meter witch can count energy if is >0 count meter1 and if is <0 count meter2?