New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Riemann sum integral sensor not updating while source sensor value is stable #88940
Comments
Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) integration documentation |
I'm afraid that this is not a 'feature' since integration is a function of values and time. So excluding time completely and keeping the same value until the source sensor value changes means that this integration is only half-implemented. I've tried forcing update of the base sensor and the integral itself through an automation but it didn't change anything. The only 'solution' is to insert some fakes into the sensor value stream time to time. But that makes the original sensor history look ugly. |
The current implementation is event driven to support sensors that update often (which is also when Riemann Sum best approaches the integral function). You are requesting a new feature because it requires a completely new implementation that is based on periodic polling of the source sensor. It's not that it can't be done, it's just that it isn't a bug... |
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. |
My rain gauge sends a new reading every 10 minutes with 0.01 inch resolution. When its raining, successive values are often the same: 0.01, 0.01, 0.02,. 0.02, etc. This wreaked havoc with HA. It missed all the new, valid, values that happened to be the same value as the last value. Each new value is cumulative, not a repeat of the current state if unchanged from the prior. I solved this by adding a small +/- random lambda value to each incoming data point. This doesn't guarantee that two identical 10 minute readings will not also get identical random adders, but, good enough for me. So, until another solution arises, here's mine. The In the - platform: command_line
name: 'Acurite 10-Min Rainfall'
command: "[[ $((`date +%s` - `date +%s -r '/config/externaldata/acuriteweatherdata.txt'`)) -le 60 ]] && cat /config/externaldata/acuriteweatherdata.txt || echo '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0' "
# Add a small lambda to try to keep successive values unique so the Utility Meter will add each value to the sum.
value_template: >-
{% set val = ( value.split( ',' )[14] | float(0.0) ) | round(2) %}
{% if val == 0.0 %}
0.0
{% else %}
{{ ( val + ( [ 0.0, -0.000001, 0.000001, -0.000002, 0.000002, -0.000003, 0.000003, -0.000004, 0.000004, -0.000005, 0.000005, -0.000006, 0.000006, -0.000007, 0.000007, -0.000008, 0.000008, -0.000009, 0.000009, -0.000010, 0.000010,-0.000011, 0.000011, -0.000012, 0.000012, -0.000013, 0.000013, -0.000014, 0.000014, -0.000015, 0.000015 ] | random ) ) | round(6) }}
{% endif %}
unit_of_measurement: 'in' |
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! |
So what is the solution to fix this? to add a helper for a helper? |
The sampler helper is a stop gap for some use-cases. I don't even know the real impact. If any of you is testing/using, feedback would be nice. |
I don't see ha_sampler in either Integrations or HACS. I'm on 2023.4,
though, if it was included later
…On Mon, Jun 5, 2023, 12:00 PM Diogo Gomes ***@***.***> wrote:
The *sampler* helper is a stop gap for some use-cases.
I don't even know the real impact.
If any of you is testing/using, feedback would be nice.
—
Reply to this email directly, view it on GitHub
<#88940 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AL2THYV4SDXVL36S2OKECNLXJYUFZANCNFSM6AAAAAAVLL4TF4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
it's a trial, it's not part of HACS (although you can use HACS to install it) |
Work around, suggest to create automation alias: reload INTEG
|
@dgomes I'm out for the next month or so and have not been able to test your idea. Sorry, and I really appreciate your digging into this issue. HA's assuming successive identical sensor readings reflect no-change in the state is a large and lurking problem. Rain Gauges are a great test case in which successive 10-minute intervals each report, say, 0.01 in of new rain. HA without a fix or workaround ignores those successive identical new incremental readings by assuming the readings are not incremental, but cumulative to date. |
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. 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 |
This looks like it could be the same problem I have with Riemann sum sensors which become unavailable when a source sensor becomes unavailable for a short period while it is producing unchanged data. I have the Enphase integration that supplies data about electricity consumption and solar production. For some unknown reason the device goes off-line for a minute at 23:00, leaving all consumption and production sensors unavailable for that minute. At that time the solar production is zero and has been for several hours. Template sensors using the integration sensors (Solar Export Power & Grid Import Power) come back after showing unavailable for the same minute as the integration sensors. This is the solar export power sensor:
The Grid Import sensor resumes showing my consumption as expected (about 500-watts). At this time of night, the solar export sensor is showing 0kW before and after the event, but is available before and after the outage. Downstream from that I have a Solar Export Energy sensor using Reimann Sum:
This sensor and all sensors relying on it as a source (daily energy export, $ earned from the export, net cost of power etc.) become unavailable and remain that way until solar production resumes the next morning. Even though sensor.solar_export_power has returned to available, the Reimann Sum sensor is unavailable until sunrise. The downstream Reimann Sum sensors using the Grid Import sensor have no such issue, possibly because they are receiving changijng data? I thought the "available" template command might help, but I am not sure how to use that. BTW I thought this only started happening in May - ie: 2023.5.0 |
Hi, |
@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 |
It could be - but we shouldn't need a workaround. I am trying to understand your solution because I still don't have a good understanding of the functions. |
The integrate and derive integrations only trigger calculations when the source sensor updates. With the time pattern, the template sensor periodically changes the content of a dummy attribute, which also counts as an update, without changing the sensor value. So that triggers a new calculation for stable sensors |
I missed this thread during my search and had opened a parallel issue here #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. By the way, one could argue that the integration of a constant value is the simplest form of an integration ;-) |
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. |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
bump |
I have made an attempt to solve this issue #110685 |
This looks exactly as the solution we need. Finally get rid of helpers. Thanks! Can't wait to have it into the release |
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
Anything in the logs that might be useful for us?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: