Failure with riemann sensor calcualting solar yield

For cost calculations on our PV power plant I calculate the values with helpers and feed them into a riemann sensor. This works but not as I hoped.

I studied all the values and formulas and found out that there are many spots missing in the timeline.

I am a new user and so I have to split this in three parts.

1
Here you can see what I mean:

2
This seems to result of this Helper which calculates the consumption:

In the above picture we see that it has peaks. And every peak is a value that counts. But I did not figure out yet, why it does not count the rest of it.

  • Spots missing are most likely because the input sensor is unavailable during that time.
  • If you have weird jumps in yield, then you should check if you used left Riemann sum instead of trapezoid, which is typically wrong for most sensors in Home Assistant.
  • How can your Riemann be in unit CHF if the base sensor is W? Are you sure you’ve show us the real base sensor used in the integral helper?

3
Here is that same plot with the other over each other that gave me the hint that it just calculates the peaks:

Has someone a hint on why this could be? It is not everyday the same, sometimes it is before lunch only and other days as in the example above it is for the whole day.

Thanks for help.

Please show the hilfswert sensor definition, because that has only got values during spike, it seems.

Ps. History graphs are more useful than the statistics graphs in entity details, because the latter show aggregated values.

Thank you for the quick response.

You are right, this is unavailability.

Riemann is left. That should work.
The Base Sensor is “Solar Ersparnis Hilfswert CHF/h”.

Here is the template for it:


{% if states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float(0) > 0 %}
  {{ states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt") | float()/1000  }}
{% else %}
  {{ (states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt")) + (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float() *-1) * (states("input_number.tarif_einspeisung_pv") | float())  /1000 }}
{% endif %}

This calculates everything and divides it by 1000 to have W/H instead of KW/h.
Your Question about CHF is correct but I don’t know the answer because I copied it from Simon42. He used This to calculate the benefit from one hour and the riemann adds it and the unit of the total is the currency, which in my case is CHF.

I checked every entity in this template for availability and they are all seamless.

As I said before, it is better to check the history graph: the details page shows statistics, which are aggregated and might hide the unavailability.

I think you should check the logs for errors. Most float filters do not use a default, so they error out when the input is not a number. I suspect that is what is going on. There are multiple sensors involved, so either going unavailable will cause problems.

OK, found it.
I just can not find which one causes the unavailability.

I might find something googling, but if you see it right away then I would appreciate your help.

EDIT: I think it could be the float(). See here:

I now changed the float to the beginning instead to the end and now next Week we will see what happens as of now we do not have sun out for a couple of days it seems.

Have a good day.

This template below is now not the same but I left it here anyway to check for experts if I might had the float() on the wrong place.

Logger: homeassistant.components.template.template_entity
Quelle: components/template/template_entity.py:203
Integration: Template (Dokumentation, Probleme)
Erstmals aufgetreten: 13. März 2025 um 14:04:53 (41 Vorkommnisse)
Zuletzt protokolliert: 12:13:42

TemplateError('TypeError: can't multiply sequence by non-int of type 'float'') while processing template 'Template<template=({% if states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float(0) > 0 %} {{ states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt") | float()/1000 }} {% else %} {{ (states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt")) + (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float() *-1) * (states("input_number.tarif_einspeisung_pv") | float()) /1000 }} {% endif %}) renders=99064>' for attribute '_attr_native_value' in entity 'sensor.solar_ersparnis_hilfswert_chf_h'
TemplateError('TypeError: can't multiply sequence by non-int of type 'float'') while processing template 'Template<template=({% if states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float(0) > 0 %} {{ states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt") | float()/1000 }} {% else %} {{ (states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt")) + (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float() *-1) * (states("input_number.tarif_einspeisung_pv") | float()) /1000 }} {% endif %}) renders=100386>' for attribute '_attr_native_value' in entity 'sensor.solar_ersparnis_hilfswert_chf_h'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{% if (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power")) | float(0) > 0 %} {{(float(states("sensor.shellypro3em_a0dd6ca1972c_total_active_power")) + (float(states("sensor.solar_uv_power"))) | float(0)) | round (1) }} {% else %} {{((float(states("sensor.solar_uv_power")) - (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power"))*-1) + (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_b_active_power")) + (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_c_active_power")))))) | round(1) }} {% endif %}' but no default was specified') while processing template 'Template<template=({% if (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power")) | float(0) > 0 %} {{(float(states("sensor.shellypro3em_a0dd6ca1972c_total_active_power")) + (float(states("sensor.solar_uv_power"))) | float(0)) | round (1) }} {% else %} {{((float(states("sensor.solar_uv_power")) - (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power"))*-1) + (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_b_active_power")) + (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_c_active_power")))))) | round(1) }} {% endif %}) renders=195760>' for attribute '_attr_native_value' in entity 'sensor.haus_korrigierter_wert_fur_flow_card'
TemplateError('TypeError: can't multiply sequence by non-int of type 'float'') while processing template 'Template<template=({% if states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float(0) > 0 %} {{ states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt") | float()/1000 }} {% else %} {{ (states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt")) + (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float() *-1) * (states("input_number.tarif_einspeisung_pv") | float()) /1000 }} {% endif %}) renders=102586>' for attribute '_attr_native_value' in entity 'sensor.solar_ersparnis_hilfswert_chf_h'
TemplateError('TypeError: can't multiply sequence by non-int of type 'float'') while processing template 'Template<template=({% if states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float(0) > 0 %} {{ states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt") | float()/1000 }} {% else %} {{ (states("sensor.solar_eigenverbrauch") | float () * states("sensor.auto_tarif_ht_nt")) + (states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power") | float() *-1) * (states("input_number.tarif_einspeisung_pv") | float()) /1000 }} {% endif %}) renders=103018>' for attribute '_attr_native_value' in entity 'sensor.solar_ersparnis_hilfswert_chf_h'

Here is the changed template:

{% if (float(states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power")))> 0 %}
  {{ (float(states("sensor.solar_eigenverbrauch")))* (float(states("sensor.auto_tarif_ht_nt")))/1000  }}
{% else %}
  {{ (float(states("sensor.solar_eigenverbrauch"))* (float(states("sensor.auto_tarif_ht_nt")))) + 
  ((float(states("sensor.shellypro3em_a0dd6ca1972c_phase_a_active_power")))*-1) * (float(states("input_number.tarif_einspeisung_pv"))) /1000 }}
{% endif %}