Engergy pv production sensor drops to zero, how to avoid in template sensor?

Dear community, I struggle now for over a year with my PV inverter giving me for total solar production 0 value, when there is no production for a longer time. This causes the enegery dashboard to show a spike in PV production, once the new energy is produced:

This is how the drop looks like in the sensor and my new template sensor below.

I had hoped to be able to use a new template sensor, which should ignore these drops by using availability_template. But unfortunately it does not. Has anybody an idea how to fix or ignore theses drops in the template sensor? If the orginial sensor drops is fine and maybe based on how the integration works, but I had hoped to fix as a template.

 - platform: template
    sensors:
      pv_production:
        unit_of_measurement: "kWh"
        value_template: >-
          {{ (states('sensor.pv_gen_meter')| float | round(2))}}
        availability_template: >-
          {{ states('sensor.pv_gen_meter') not in ['unknown', 'unavailable', 0]}}

Appreciate any hint or help here.

Thank you very much

Would something like the below fix my problem?

        value_template: >-
          {%  if (states('sensor.pv_gen_meter')| float | round(2)) > 0 -%}
            {{ (states('sensor.pv_gen_meter')| float | round(2))}}
          {%- else -%}
            {{ (states('sensor.pv_production')| float | round(2))}}
          {%- endif %}

if states('sensor.pv_gen_meter') drops to zero, you need to account for it properly in the availability template. All states are strings, so you need to check it against a string zero, not an int zero. Also doesn’t hurt to add a decimal version of zero in quotes as well.

        availability_template: >-
          {{ states('sensor.pv_gen_meter') not in ['unknown', 'unavailable', '0', '0.0']}}
1 Like

thank you, it is very logical what you say, I should have noticed this myself!

Since the December update, every Friday I have a pv spike on the energy dashboard showing the total yield from my SMA inverter. I’ll wait for the January update and hope it will be fixed.

the problem is now fixed, the dropdown to 0 is now gone.

1 Like

Unfortunately problem here still not fixed. Every Friday at 02:20 total yield goes to 0. When the SMA inverter starts, total yield goes to it’s original value giving a spike in the energy page of the total yield.

You’re issue won’t be fixed by a core update, it needs to be fixed by you. If your sensor is dropping to zero and ramping back up, then it will add that to the calculation. You either need to fix that on your sensor side, or make a template sensor that filters out zero.

Strange. Am I the only one? Why did it work OK until December? Why does it only drop to 0 on Fridays?

exactly, what I wanted to say, you have to create a template sensor and then catch the spike, as I did.

I see the problem mostly in winter, when Sensor goes unavailable, due to less sunlight during the day

  - platform: template
    sensors:
      pv_production:
        unit_of_measurement: "kWh"
        value_template: >-
          {%  if (states('sensor.pv_gen_meter')| float | round(2)) > 0 -%}
            {{ (states('sensor.pv_gen_meter')| float | round(2))}}
          {%- else -%}
            {{ (states('sensor.pv_production')| float | round(2))}}
          {%- endif %}
        availability_template: >-
          {{ states('sensor.pv_gen_meter') not in ['unknown', 'unavailable', '0', '0.0']}}

That’s a question you need to ask yourself about whatever is creating that sensor. We can help if you give that information.

You’re focusing on the result, and not what’s producing the zero.

Problem solved. Applied the template. Now no more spikes on Friday. :slightly_smiling_face:

Now I have the spike on Tuesday. :cry:

Then you didn’t make the template sensor correctly, or you are using the wrong sensor for the calc.

Seems the SMA inverter does a reboot once a week. So no output (not even zero) between 01:30 and power-up.

Yes, and during that time the state should be unavailable. If it’s not, then you’ll have spikes that change your data.

Solved with 2022.2 release :slightly_smiling_face:

Thanks.

do you have to put this on the configuration.yaml?
if try to test in the template section (under developer tools) i got the correct value but when i try to put in the yaml file, it wont accept is

yes you need to create a remplate sensor, please let us know your error message.