core: Riemann sum integral sensor not updating while source sensor value is stable
The problem
The Riemann sum integral sensor currently only updates when the source sensor updates, which is not always sufficient. Ideally it would calculate a new value periodically too, even if the source sensor value remains stable.
For example: I’m monitoring the energy used by our pool filtration system. It’s power usage stays exactly the same throughout the day after a brief priming phase. In this scenario the integration sensor does not calculate the energy used until the end of the day when the pump stops.
What version of Home Assistant Core has the issue?
2023.2.5
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Integration - Riemann sum integral
Link to integration documentation on our website
https://www.home-assistant.io/integrations/integration/
Diagnostics information
No response
Example YAML snippet
sensor:
- platform: integration
source: sensor.pool_filter_pump_power
name: Pool Filter Pump Energy
unit_prefix: k
round: 2
method: left
Anything in the logs that might be useful for us?
No response
Additional information
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 13
- Comments: 24 (5 by maintainers)
I missed this thread during my search and had opened a parallel issue here https://github.com/home-assistant/core/issues/102057
I also explained why it is a bug. Essentially, the current Rieman sum reports 0 kWh consumption even if the source constantly consumes 1 kWh. So the result of the integration is wrong. If no update is performed, the returned value must not be 0. Returning 0 is simply false. An hourly sum must either force an update even if the input data is constant or must return unknown/unavailable.
By the way, one could argue that the integration of a constant value is the simplest form of an integration 😉
I know that the current implementation is based only on sensor update. But that is not exactly true: HASS doesn’t broadcast any updates if the new value of the sensor is the same as the previous. That means the current implementation is practically changes only when the sensor value changes and not when the updates received from the sensor device. So the integration should also include an (optional, configurable) timer that periodically updates the integration value based on the last value and the time elapsed since that moment. There is no need to check or poll the sensor.
I have made an attempt to solve this issue https://github.com/home-assistant/core/pull/110685
I have moved away from using this Riemann Sum sensor because it is unreliable. That rules out using the Enphase integration because it needs Riemann Sum for some data. I have moved to REST for my power/energy data and it is working without issue.
In my case the constant reporting (0kW) was not the problem. The system went off-line for 60 seconds and that caused the sensor to fail until it had a reading other than 0kW.
I found the comments that the issue with the Riemann Sum sensor ‘isn’t a bug but a feature request’, to be strange.
Hi, As long the author doesn’t recognise stable sensors as a valid use case, I created extra template sensors as a work around to add time triggers in case the value remains stable. See https://github.com/home-assistant/core/issues/96875#issuecomment-1656810325
@Steve2017 the other issue was related to loosing the source sensor when it shortly became unavailable. Maybe good to know that seems to be solved as well since I use the template workaround. Maybe related to your issue
My two cents, read the values at least ones per unit_time. Just add a simple timer that will give an additional event when unit_time expired. I predict that having these extra events won’t harm and don’t require a completely new implementation. I suspect it will even simplify your current design! Now you somehow have to chop integrations results over various unit time buckets, when the next sensor event took longer than the unit time.
Note: the derivative integration has a very similar issue. When the sensor stops changing, the derivative shall become zero, but doesn’t without further sensor updates
To possibly address the lack of updates in some sources, I’ve created a Helper integration: https://github.com/dgomes/ha_sampler
If you run the source through this custom helper, and then use this custom helper as the source of Riemann Integration, you should get better results.
PLEASE: don’t create issues or reply to this thread about this custom_component, use the GitHub repository of the custom_component!