You’ll probably need to create a new template sensor which returns a positive value in one direction and a negative value for the reverse direction.
Something like the following in your yaml.config file but use the right sensors as input.
A big disclaimer - I am lousy at yaml, so there is every probability I have the syntax wrong. Hopefully others can correct it, this is more about indicating the sort of thing you can do.
template:
- sensor:
- name: "NewPowerSensor"
unit_of_measurement: "W"
state: >
{% if states('sensor.mainsdirection')|= "FORWARD"}
{{ states('sensor.mainspower') }}
{% else %}
{{ states('sensor.mainspower') * -1 }}
{% endif %}
Of if you want two separate sensors, one for import, one for export then you can do something like in this post: