Calculate Yeld (Photovoltaic)

Hello
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:

sensor:
  platform: template
    sensors:
        yeld_fotovoltaico:
        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

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like