Calculate power Usage in HA


I want to calculate my daily power usage and display it on a page in HA. I know I can see it also in the energy tab, but in that case I always need to switch tabs…

So, I got these variables :

  • Grid import (kWh) : How much kWh do I use from the grid?
  • Solar import (kWh) : How much kWh do my solar panels deliver?
  • Grid export (kWh) : How much kWh do I send towards the grid?

So, I think that I need to do this calculation (please let me know if I am wrong):
sensor.grid_import + sensor.totalsolarkwh - sensor.grid_export = my usage.

I suppose I need to create a template. Tried multiple times, but without luck…

Someone over here that could help me?

{{ states('sensor.grid_import') |float(0) + states('sensor.totalsolarkwh') |float(0) - states('sensor.grid_export') | float(0) }}

You can also place the cards from the Energy Dashboard in any other dashboard you want: