SImple math... But how?

So, I got these two values…

sensor.totalpowerusage, that is the amount of kWh that my home have used from 00:00 till 23:59

sensor.grid_export, that is the amount of kWh that I’ve send back to the grid.

So, if i do sensor.totalpowerusage minus sensor.grid_export I should get the amount of kWh that I’ve used from my solar panels directly. Correct?

I tried this as a helper, but how do I need to configure this?

Template sensor helper with a state template of:

{{ states('sensor.totalpowerusage')|float(0) -
   states('sensor.grid_export')|float(0) }}

Key point here is that states are always strings and need “casting” (converting) to a number before doing maths operations.

Bedtime reading: