Help negative/positive value template from Grid sensor Import and export

Hi everyone, I need help because I don’t know how to do it, I need to create a sensor that shows me a negative value if I’m taking energy from the GRid and a positive value if I’m feeding it into the grid.
In home asistan I have two separate sensors one for import and the other for export

can you help me?

1 Like

It’d help if you gave us details of the sensors, otherwise we need to make them up and then you need to convert our made-up sensors back to your real ones.

Create a template sensor in the UI (under Helpers) with this as the state template:

{{ states('sensor.export')|float(0) - states('sensor.import')|float(0) }}

That simply subtracts import from export. If that’s not what you need, be clear on what your two sensors provide.

1 Like

Thanks a lot, Troon! I had the same problem and this works perfectly.