Calculate percentage

I got these 3 sensors

  • Total Energy Usage (sensor.totalpowerusage)
  • Total Solar (sensor.totalsolarkwh_samen)
  • Total Grid (sensor.grid_import)

I want to calculate 2 more sensors (helpers)

  • How much % of my energy comes from solar?
  • How much % of my energy comes from the grid?

How can I do this?

Create two helper template sensors:

{{ ((states('sensor.totalsolarkwh_samen') | float(0) / states('sensor.totalpowerusage') | float(1)) * 100) | round }}

and

{{ ((states('sensor.totalsolarkwh_samen') | float(0) / states('sensor.totalpowerusage') | float(1)) * 100) | round }}

or the second on could be

{{ 100 - states('sensor.YOUR_FIRST_TEMPLATE_SENSOR') | int(0) }}
1 Like