-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Switch to left method as default for rieman sum #116736
base: dev
Are you sure you want to change the base?
Conversation
Hey there @dgomes, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
I don't think this is the right path. There is #110685 And ultimately left does not provide a better approximation of the integral, it is just an over simplification for resistive loads. |
left is much much much better for anything that keeps a constant value over a long time since we don't update the underlying sensor then. I for example ended up with HUGE electrical usage in my data, since my electrical heater wasn't used and at 0 for several weeks, then kicked up to 6 kw for half an hour. Since the last changed value was way way back, it was really a huge trapezoidal. I fully agree that this is not a full solution. But it's much better default than trapezoidal until we start updating periodically. |
Ps. I suspect a very common use case is just power to energy, where the power value could remain constant for some periods. I didn't read the docs careful, since i thought I just need a simple integration of this, i don't care if it's 100% accurate. I do care when i get values of 100kwh added to the intergral, when it was just 6kw over 30 minutes, ie 3kwh. So a magnitude wrong value. |
I understand your struggle, but this is IMHO not the right approach. The PR for time based integration trigger would solve your issue as an example. |
The integration trigger mostly will solve the issue when it is configured correctly. I suspect most users won't configure it until they run into the issue, and even then their configuration may not be optimal. Trapezoidal makes sense outside home assistant - if you are polling a sensor say every minute, and want to integrate that value, trapezoidal is probably the best method. But home assistant does not work that way. Sensor values are not updated when the value hasn't changed. It's an assumption everywhere else in home assistant that the best approximation at any point in time is the last sensor value before it (what left does), not some interpolated value (like what trapezoidal does). This is how sensor values are stored (ignoring updates that don't change the value), and the way it's rendered in the history graph. When you use the new In all other cases, if your sensor can ever give you the same value twice in a row, left is a better approximation. And in cases such as energy sensors, which is the probably the main use case for the integration sensor (it's the only documented example), duplicate values are very common which makes trapezoidal very wrong.
|
"configured correctly" depends on each one use case, for many the current integration fits perfectly their needs
That is the case for many people with sensors that only provide the power readings and update quite often, you can find that for many solar inverters for example, and even for some other smart devices.
That's why #113869 is under review.
It will certainly will, and you can figure out a value easily enough and start with a sensible default of couple minutes.
See #113869 |
Solar inverters are a perfect example of where this is broken. You get zero values for the entire night, causing a wildly incorrect value when the first non-zero value is reported in the morning.
I wasn't aware of that PR. I think that should fix the issue of "the defaults give completely broken results", avoiding the need to change the default. |
Proposed change
Let the rieman sum integration default to left instead of trapezoidal. Trapezoidal is mostly wrong since home assistant does not update data when value is unchanged. There is attempts to resolve this, but as of yet the integral sensor does not take those into account. Defaulting to left is a better default.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: