Calculate Yeld (Photovoltaic)

I would like to create a sensor that represent the yeld of Photovoltaic. so I need to calculate the following (which returns a value between 0 and 1)

sensor.consumo_giornaliero / (sensor.consumo_giornaliero+sensor.produzione_fotovoltaico_giornaliero)

What is the syntax for creating a new sensor with this formula?

Thanks in advance

I answer myself… as I found the solution.
I post here so someone else could benefit (you only need to indent properly… I can’t do it here)
EDIT: thanks to the @tom_I answer I fixed also the formatting :wink:

  platform: template
        friendly_name: "Resa fotovoltaico"
        value_template: "{{(((states('sensor.produzione_fotovoltaico') | float)  / (((states('sensor.consumo_giornaliero') | float) + (states('sensor.produzione_fotovoltaico_giornaliero')| float))))) * 100 }}"
1 Like

1 Like