-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Have statistics functions return a meaningful, non-none result even if only one value is available #127305
Have statistics functions return a meaningful, non-none result even if only one value is available #127305
Conversation
Hey there @ThomDietrich, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
255cbf9
to
2351e4a
Compare
@unfug-at-github Can you please motivate why your proposed change is beneficial? |
I'm not the author of the PR but a user, so please accept my apologies if you didn't want to hear my opinion. I've noticed significant issues with statistical values, especially when home assistant is restarted and/or the sensor that provides values for the statistical entity is "sparse" and does not provide many values but only (significant) changes (e.g. to conserve energy). I hope for a speedy inclusion of this PR and the other, linked one, as I see spikes and incorrect values from the statistics entities after a lot of restarts of home assistant as well as the issues described in the other PR when a sensor's value does not change for a long time (e.g. "0" illuminance at night from a sensor but the average not returning to zero, constant temperature values that break derivative calculations). |
Please have a look at the description. I have updated it with a corresponding scenario where the current behavior is an issue. |
@eljoest @unfug-at-github I am not convinced this PR does anything to improve the issues you mention since the statistics sensor restores past states of input entities from the recorder? |
Yes, that is what it does, assuming those changes have happened within the the specified interval (max_age). It doesn't load values from the database that are older than max_age. This leads to the buffer being filled with the values that have changed within the interval. If there is only a single value there, the "average_step" / "average_linear" becomes "unknown" instead of that value. |
@emontnemery For the jumps: Nope, this will not change anything - that's what the other request is supposed to address. Most of my sensors are zigbee based and only send new values when there's a significant change. Unfortunately they're sometimes "noisy" so I use statistics entities with "keep_last_sample" to smooth them. In periods with constant conditions the recorder will only have a single value (or no value at all) within the max_age timeframe and this seems to lead to issues. I haven't debugged this after the addition of keep_last_sample so my conclusions may be outdated but the issue is still present. |
You are exactly right. Currently many of the functions return "unknown" when there is only a single value. This means that even if I use "keep_last_sample", and hence, have a single value, the result is "unknown". By the way, even if I use "keep last sample" I am not able to properly compute the statistics of the last minute. Assuming my sensor provides 0.0 (1 hour ago) and then 1.0 (1 second ago) and I compute the minimum of the last minute. The buffer would only hold the 1.0, since "keep last sample" only applies when there is no value within the interval. The outcome of this would be: minimum of last minute = 1.0 (instead of 0.0) I have already solved all these issues, but was asked to split the pull requests into small portions. So this one just fixes the issues around the computation failing for buffers containing only a single value. Just have a look at the following example to see how messy averages currently look with input that is perfectly fine to compute averages.
|
2351e4a
to
ccd4a53
Compare
@unfug-at-github i still lack an explanation of how this PR improves the behavior considering the statistics sensor restores past states of input entities from the recorder Could you maybe try to dig down in the git history (the easiest way would be to use git blame, either in github or in vscode) to see what the rationale was for only calculating most characteristics when there are at least 2 states? Why do some of Python's stdlib |
The simple answer to the first question is: it doesn't. There is a separate change request to address the issues of the spikes. Regarding the other topic: I can only speculate why several of the functions don't return a value for the single value case. Most likely it wasn't considered because the authors had sensors spitting out enough values that were changing frequently (being noisy). Also the whole thing started with limiting the buffer by size not by it's age, so the problem arose only after "max_age" was introduced. I can only say that computing an average, a maximum, a mean etc. are mathematically well defined for the single value case, and it doesn't make any sense at all that this module is unable to compute those values. |
The recorder will not restore more values to satisfy "arbitrary" limitations of the statistics functions (e.g. average_step needing two data points to calculate the average).
I did to the original PR ~ 3 years ago. Other than the fact that the current implementation can't compute the value with only one point I was unable to identify a conscious choice. As @unfug-at-github mentioned there are still edge cases (e.g. with one single value within the max_age frame and another value just outside) that can not be adressed with this PR. As already stated the other reviewer requested that the larger PR be split into smaller pieces. As far as my understanding of both PRs goes, doing so unfortunately results in partial/incomplete fixes of the current issues.
Not sure which stdlib statistics functions do so, but I suspect in these cases there are mathematical rules in place that define it's impossible. Depending on the statistic the solution would likely be to provide more than the last sample (e.g. the last two) - which I think was part of the original PR. This would also be required to fix the example edge case mentioned before, but cannot be accomplished in a "small" and minimal PR as requested. |
Hey guys.
Happy to explain my reasoning for this decision some time ago :) The statistics sensor calculates statistical characteristics for a sensor's history. Speaking with a mathematical, statistical, or even physical experimentation mindset, sensor values become dangerous with sparse data. A single sensor reading in the buffer won't provide meaningful values for e.g. The idea behind the minimum samples condition is to ensure a stable statistics result, or unknown otherwise. Scientifically speaking that's exactly how it should be: Provide an average if you can, otherwise be honest that you can't. I would argue in the opposite direction and claim to increase the threshold for minimum samples needed :) Here is the thing: Statistics can only be calculated correctly, if enough samples are available in the buffer. That is a fact everyone should easily agree with. The addition of I am convinced what the statistics integration is missing is a service, or rather an action as it is called nowadays. action: statistics.trigger_manual_update
data:
from_source_entity: true This action can be called on a schedule or better based on state-triggers and conditions. The user can specifically ensure when and which values go into the statistics sensor to ensure a populated buffer and a meaningful statistical characteristic. A change of the minimum sample count isn't necessary any longer and the use of Does that make sense? Cheers! |
@ThomDietrich Hi Thom, thanks for the clarification. With the introduction of "max_age" to cope with sensors (or storage implementations) that do not transmit or keep unchanged values, the number of samples is a poor indicator of "valid" calculations. As you mentioned, the calculations would probably need to be changed to account for values just outside the max_age window. As an example consider the following raw data:
With a max_age of 60 the current implementation of average_step would give a value of 101 I believe (it does have 2 values to work with, 100 and 102). My expectation as a user would be a lot closer to 50. If the implementation were to retain (and/or be provided with) and use the last sample just outside the max_age timeframe, the value could be calculated correctly. On the other hand: Without the updated values at -1 and 0 seconds, the average within the max_age timeframe of 60 should presumably be 1 not "None" as long as the current value of the source is still "1" and not unknown. This would however require a larger overhaul of the statistics component and its interaction with the data sources. The ability to trigger intermediate calculations would match what I am currently doing: Programatically adding "noise" to the sensor values to force updates at fixed intervals. |
@ThomDietrich: I'm not quite sure I can follow that argument. At the very least, we should leave it to the user to decide whether or not he / she is happy with values calculated based on a small sample set. We are not talking about scientific studies where large sets of samples are a must have here. We could introduce a parameter like "fail if less than x samples in buffer", for cases where large sample sizes are a real requirement. Actually, there already is a counter for the actual number of elements in the buffer that could be used in these situations. To explain my concrete situation: my inverter is queried every two seconds, this produces updated values every two seconds, so technically speaking there are lots of values to put into a 30 second average for example. The problem is that home assistant is not passing on these values, if they don't change. At night my solar production is 0W. This is measured every two seconds, but what ends up at the statistics sensor is a single 0W measurement performed around sunset. This very accurately presents the current situation, my average production is indeed 0W, so why would I want to see "unknown" instead? By the way, in case there is an outage at night, this would correctly be reported as "unknown", since the updated "unknown" value would make it through the system. To work around this "unknown" issue you could use a template sensor that either reports the current value or the average from the statistics sensor if it is available. That's what I did in my first attempts. However, that leads to a whole lot of useless templates repeating the same pattern. Another solution is adding additional dummy-attributes that would force the values to be propagated, or as @eljoest mentioned adding artifical noise. To be honest, I am slowly getting a little frustrated over this issue. The current sensor is producing results that nobody will be able to understand without looking into the source code. Some of the functions require at least one value, others require at least 2. This is not consistent and can't be explained from a mathematical standpoint. Also, the values that are getting computed don't represent the whole time interval (as explained by @eljoest above), but only the interval between the first and last change within the interval. I have already fixed all these issues here and was hoping to get them added to the statistics component bit by bit. Anyway, if you think that the current behavior is as it should be, I'll just convert my solution into a separate custom component and leave it at that. |
@ThomDietrich wrote
I think that is an issue both if there is a single or two observations? I'd suggest to not block calculating characteristics unless they are not defined. |
@unfug-at-github you mention that
The solution to this is the newly introduced A PR which changes the For reference, here's a PR for the integration sensor which does that: #113869. Note that there were a couple of follow-up PRs, the initial implemented directly subscribed to the events which performed very poorly. A different approach is to periodically sample the input sensor instead. I don't remember if the statistics sensor already has that functionality? Here's a PR for the integration sensor which added that: #110685 |
@emontnemery: Thanks for your explanations. I agree that getting more frequent updates would take many of the pain points away or at least mellow them down significantly:
Having said that, I still think that the changes proposed in this PR make sense. Why average_step and average_linear need two values at least, while average_timeless and mean just need one, can't be justified in my eyes. Implementing the changes as you proposed them makes sense in my eyes. However, it will generate quite a bit of effort
I haven't decided yet whether I'm going to give that a try, after all I have a solution that works for me now. I must admit that I have underestimated the amount of effort that goes into contributing even comparably small changes here. |
Hey friends,
I have no strong preference on this detail. Just a few samples is shit either way. Instead of dealing with low sample count we need to help the user to keep a high sample count. Therefore ...
Erik, I completely forgot about this topic. We did discuss it before. I totally agree, this would be the most important improvement to the statistics component today.
This is an additional improvement and exactly what the suggestion of the
I am sorry to hear this. Being honest, that is the same reason why I haven't been active so long. Between family and building a house, I did not have the time and energy to deal with the rigorous review process here.
I agree, on the other hand, I am convinced my proposed action would solve your and many more issues and serve many use cases. If you can find the motivation to implement it, I promise to provide you with a swift and quick review&approval 😺 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the discussion, I agree we can go ahead and merge this PR.
However, before merge:
- The PR description needs a breaking change section to alert users to the changed behavior. It's enough to list the characteristics which previously needed 2 samples to produce output but now only need a single one.
- Add or adjust test cases as needed to ensure full test coverage of the new behavior
PS: Thanks for your patience so far @unfug-at-github 👍
…f only one value is available
ccd4a53
to
4e035a8
Compare
@emontnemery: We are getting a little of-topic here, but are you sure these state report events ("state updated, but not changed") would travel through cascaded layers of template sensors? Otherwise, listening for them will only be a partial improvement, that will not work for values computed by the template sensors. |
@unfug-at-github All sensors which consume states from one or several input sensors need to be updated to recalculate on state reports instead of on state changes. Template sensors will need some extra consideration because You're most welcome to contact me on Discord, my nickname there is @emontnemery, if you want to discuss this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @unfug-at-github 👍
Congrats on the first accepted PR, we hope to see more of them! 🎉
…f only one value is available (home-assistant#127305) * have statistics functions return a meaningful, non-none result even if only one value is available * improved code coverage
Use new reauth helpers in weatherflow_cloud (home-assistant#128821) Use new reauth helpers in wallbox (home-assistant#128820) Simplify custom component loading (home-assistant#128813) Use new reauth helpers in webostv (home-assistant#128823) Use new reauth helpers in whirlpool (home-assistant#128825) Handle invalid zeroconf messages in Android TV Remote (home-assistant#128819) Use new reauth helpers in yale (home-assistant#128828) Update zhong-hong-hvac to 1.0.13 (home-assistant#128822) Use new reauth helpers in vicare (home-assistant#128779) Auto lower case username for Schlage auth flows (home-assistant#128730) Bump plugwise to v1.4.3 (home-assistant#128773) Use new reauth helpers in weheat (home-assistant#128824) Use new reauth helpers in youtube (home-assistant#128835) Use new reauth helpers in yolink (home-assistant#128834) Update attrs to 24.2.0 (home-assistant#126656) Add Spotify to strict typing (home-assistant#128846) Use new reauth helpers in yalexs_ble (home-assistant#128831) Use new reauth helpers in withings (home-assistant#128826) Add New Music Category for Media Browser (home-assistant#128147) Align consumption sensor names in ViCare integration (home-assistant#127888) Reduce the size of the Nest event media storage cache (home-assistant#128855) Reduce max media items per nest device Add humidity to KNX climate (home-assistant#128844) Use new reauth helpers in yale_smart_alarm (home-assistant#128836) Bump google-nest-sdm to 6.1.3 (home-assistant#128871) Bump pyTibber to 0.30.3 (home-assistant#128860) Remove myself from roomba codeowners (home-assistant#128858) Bump habluetooth to 3.6.0 (home-assistant#128815) Add audio feature sensors to Spotify (home-assistant#128785) Improve entity cached attributes (home-assistant#128876) Use runtime_data for Swiss Public Transport (home-assistant#128369) * use runtime_data instead of hass.data[<key>] * fix service response export type * reduce runtime_data to be just the coordinator * fix rebase * fix ruff * address reviews * address reviews * no general core import * no general config_entries import * fix also for services * remove untyped config entry * remove unneeded cast Add translations for Netatmo thermostat preset modes (home-assistant#128890) Simplify Swiss public transport coordinator (home-assistant#128891) Include Z-Wave JS lowSecurityReason in node added websocket message (home-assistant#128896) * Propagate lowSecurityReason to FE when adding a zwavejs device insecurely * update tests Remove dead code from concord232 (home-assistant#128907) Add reconfigure flow to ring integration (home-assistant#128357) Co-authored-by: Christopher Fenner <[email protected]> Co-authored-by: Joost Lekkerkerker <[email protected]> Push real binary sensor states to state machine in tests (home-assistant#128894) Use STATE_ON/STATE_OFF constants in template test (home-assistant#128883) Bump pyopenweathermap to v0.2.1 (home-assistant#128892) Add ecobee set_sensors_used_in_climate service (home-assistant#102871) * Add set_active_sensors Service * Remove version bump from service addition commit * Reviewer suggested changes * Changed naming to be more clear of functionality * Adjusted additional naming to follow new convention * Updated to pass failing CI tests * Fix typo * Fix to pass CI * Changed argument from climate_name to preset_mode and changed service error * Made loop more clear and changed raised error to log msg * Fix typo Co-authored-by: Erik Montnemery <[email protected]> * Removed code that was accidentally added back in and fixed mypy errors * Add icon for service * Added sensors as attributes and updated tests * Revert changes made in home-assistant#126587 * Added tests for remote_sensors and set_sensors_used_in_climate * Changed back to load multiplatforms (home-assistant#126587) * Check for empty sensor list and negative tests for errors raised * Added tests and fixed errors * Add hass to class init to allow for device_registry lookup at startup and check for name changed by user * Added tests to test the new functions * Simplified code and fixed testing error for simplification * Added freeze in test * Fixed device filtering * Simplified code section * Maintains the ability to call `set_sensors_used_in_climate` function even is the user changes the device name from the ecobee app or thermostat without needing to reload home assistant. * Update tests with new functionality. Changed thermostat identifier to a string, since that is what is provided via the ecobee api * Changed function parameter * Search for specific ecobee identifier * Moved errors to strings.json * Added test for sensor not on thermostat * Improved tests and updated device check * Added attributes to _unrecoreded_attributes * Changed name to be more clear * Improve error message and add test for added property * Renamed variables for clarity * Added device_id to available_sensors to make it easier on user to find it --------- Co-authored-by: Robert Resch <[email protected]> Co-authored-by: Erik Montnemery <[email protected]> Add Airzone switch entities to zones (home-assistant#124562) Add new QNAP QSW uptime timestamp sensor (home-assistant#122589) Co-authored-by: Joost Lekkerkerker <[email protected]> Remove explicit templating of persistent_notification service data (home-assistant#128903) Add Airzone Cloud main zone mode select (home-assistant#125918) Co-authored-by: Joost Lekkerkerker <[email protected]> Add Airzone Cloud switch entities to zones (home-assistant#125917) Co-authored-by: Joost Lekkerkerker <[email protected]> Add floor heating device valve positions in Homematic IP Cloud (home-assistant#122759) * Update sensor.py for new FALMOT Sensors First Integration attemp to support ValvePosition as Sensor for HmIP-FALMOT-C12 * Update sensor.py * Update sensor.py * Add Valve Position to FALMOT-C12 * modified: devcontainer * Service für minimum vale postion hinzugefügt. * update to services * Service call optimized * Add valvePosition to HomematicIP Cloud for Falmot-C12 and show only channels that are connected with an motorized actuator * Fix some tests * Add icon for service * Fix tests, add check for ValveState in icon * Remove minimum valve service * REmove minimum valve * Use list comprehension for devices, support other terminal blocks * Remove unused constant * Check correct channel --------- Co-authored-by: thecem <[email protected]> Add fan `set_speed` support for Xiaomi Mi Air Purifier 3C (home-assistant#126870) Add config flow to local_file (home-assistant#125835) * Add config flow to local_file * Small mods * Add/fix tests * Fix * slug * Fix strings * Mod strings Add firmware update entity to IronOS integration (home-assistant#123031) Add diagnostics to Comelit SimpleHome (home-assistant#128794) * Add diagnostics to Comelit SimpleHome * add test * add missing tests * introduce SnapshotAssertion * cleanup * exclude date based props Deprecate entity_id template variable in camera services (home-assistant#128592) * Deprecate entity_id template variable in camera services * Update snapshots * Tiny lang tweak * Fix translation --------- Co-authored-by: Franck Nijhof <[email protected]> Add diagnostics to Vodafone Station (home-assistant#128923) * Add diagnostics to Vodafone Station * cleanup and exclude props based on date Add update_percentage property to update entity (home-assistant#128908) Allow Trend title to be translated (home-assistant#128926) Fix description placeholder in fibaro reauth (home-assistant#128925) Allow Random title to be translated (home-assistant#128928) Bump holidays to 0.59 (home-assistant#128924) Remove explicit templating of telegram_bot service data (home-assistant#128906) Remove explicit templating of minio service data (home-assistant#128905) Remove explicit templating of velbus service data (home-assistant#128904) Remove explicit templating of logbook service data (home-assistant#128902) Allow Timer title to be translated (home-assistant#128927) Fix description placeholder in brunt reauth (home-assistant#128933) * Fix description placeholder in brunt reauth * Update homeassistant/components/brunt/config_flow.py Co-authored-by: Jan-Philipp Benecke <[email protected]> * Update homeassistant/components/brunt/config_flow.py Co-authored-by: Jan-Philipp Benecke <[email protected]> --------- Co-authored-by: Jan-Philipp Benecke <[email protected]> Add subscription tier attribute to Twitch integration. (home-assistant#128870) * Add subscription tier to Twitch integration. * Add test for Twitch tiers. Tests do not currently pass, so this is only theoretical. * Fix variable type * Show tier levels as 1,2,3 instead of the raw API values of 1000,2000,3000. * Make Twitch subscription tier fixtures strings. * Use proper assertion value for subscription tier test. Edited on a bus on my phone. 😎 * Update homeassistant/components/twitch/coordinator.py * Update tests/components/twitch/test_sensor.py --------- Co-authored-by: Joost Lekkerkerker <[email protected]> Add missing strings for mold indicator (home-assistant#128205) * Add missing localization keys for random component configuration * Add missing localization keys for mold_indicator component configuration * one_integration_at_a_time * Fix localization strings for mold_indicator: use direct values instead of non-existing keys * Fix localization strings for mold_indicator: use direct values instead of non-existing key * Add missing translations for Mold Indicator helper * correcting it for hassfest * Fixes --------- Co-authored-by: G Johansson <[email protected]> Drop not needed reauth strings in tplink (home-assistant#128937) Use new reauth helpers in unifi (home-assistant#128837) * Use new reauth helpers in unifi * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <[email protected]> * Update config_flow.py --------- Co-authored-by: Joost Lekkerkerker <[email protected]> Fix description placeholder in imap reauth (home-assistant#128940) Implement new state property for alarm_control_panel which is using an enum (home-assistant#126283) * Alarm state from enum * Fixes * Set final * Fix rebase * Test const * Fix breaking version * Fix other for alarm_control_panel * Fix integrations * More * More * More * More * Fix zha * Replace _attr_state * Fix alarm_control_panel * Fix tests * Fixes * Mods * Change some * More * More * More * Tests * Last tests * Return enum * Fix zha * Remove not needed check * Fix wording * Fix homekit * Mod prometheus * Fix mypy * Fix homekit * Fix ifttt Fix description placeholder in transmission reauth (home-assistant#128938) Add motion detected binary_sensor for tplink (home-assistant#127883) * Add motion binary_sensor for tplink * Remove strings definition as we have device class that handles this * Simplify instructions * Remove mentions about fixture creation and snapshot updates as requested * re-add newline Expose tplink temperature sensor as measurement (home-assistant#128640) Add state_class=measurement to the temperature sensor, making it available for long-term statistics. Fix flaky update coordinator test (home-assistant#128943) Bump xiaomi-ble to 0.33.0 (home-assistant#128946) Update astroid to 3.3.5 (home-assistant#128948) Bump yarl to 1.16.0 (home-assistant#128941) Bump gcal_sync to 6.2.0 (home-assistant#128949) Add snapshot service to image entity (home-assistant#110057) * Add service definition for saving snapshot of image entity * Add service to image * Add tests for image entity service * Fix tests * Formatting * Add service icon * Formatting * Formatting * Raise home assistant error instead of single log error * Correctly pass entity id * Raise exception from existing exception * Expect home assistant error * Fix services example * Add test for templated snapshot * Correct icon service config * Set correct type for service template * Remove unneeded Co-authored-by: Erik Montnemery <[email protected]> * remove template * fix imports * Update homeassistant/components/image/__init__.py * Apply suggestions from code review --------- Co-authored-by: Erik Montnemery <[email protected]> Add OSO Energy services (home-assistant#118770) * Add OSO Energy services * Fixes after review * Add tests for OSO Energy water heater * Fixes after review * Revert changes for service schema in OSO Energy * Improve osoenergy unit tests Fix google tasks todo docstrings (home-assistant#128978) Add support for fetching bindkey from Mi cloud (home-assistant#128394) Fix zha test RuntimeWarnings (home-assistant#128975) Bump aiocomelit to 0.9.1 (home-assistant#128977) * Bump aiocomelit to 0.9.1 * remove exception Bump aiovodafone to 0.6.1 (home-assistant#128976) * Bump aiovodafone to 0.6.1 * remove exception Bump PySwitchBot to 0.51.0 (home-assistant#128990) Add limited template to at field for time triggers (home-assistant#126584) * Add limited template to at field for time triggers * fix mypy * Fix comments * fix-tests --------- Co-authored-by: Erik Montnemery <[email protected]> Update aioairzone-cloud to v0.6.8 (home-assistant#128992) Bump axis to v63 (home-assistant#129005) Bump python-roborock to 2.6.1 (home-assistant#128804) Bump lektricowifi to 0.0.43 (home-assistant#128979) Use ConfigEntry.runtime_data in gardena_bluetooth (home-assistant#129000) Improve template docstring (home-assistant#128967) Fix step in presets for generic thermostat (home-assistant#128922) Expose scripts with no fields as entities (home-assistant#123061) Fix FUNDING.yml to OHF (home-assistant#129013) Add Hassio HTTP logs/follow to allowed paths (home-assistant#126606) * Add logs/follow to admin paths in hassio.http * Add tests for logs/follow admin paths in hassio.http * Add tests for logs/follow admin paths in hassio.http * Add compress and timeout exclusions for hassio http api * Fix should_compress usage in hassio/ingress * Add missing follow exceptions for hassio/http * Add hassio range header forward for logs endpoints * Fix test syntax hassio/http Bump orjson to 3.10.10 (home-assistant#129015) changelog: ijl/orjson@3.10.9...3.10.10 Adjust logging level in ModBus (home-assistant#128980) Fix issue 127570 in ModBus Component Remove battery device class from bmw secondary sensor (home-assistant#128970) Remove battery device class Add go2rtc binary config to expose api only on localhost (home-assistant#129025) Bump github/codeql-action from 3.26.13 to 3.27.0 (home-assistant#129019) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.13 to 3.27.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@v3.26.13...v3.27.0) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Powerview migrate scene to string unique_id (home-assistant#128131) Bump pyduotecno to 2024.10.1 (home-assistant#128968) Bump python bsblan version 0.6.4 (home-assistant#128999) Allow configuring WebRTC stun and turn servers (home-assistant#128984) * Allow configuring WebRTC stun and turn servers * Add tests * Remove class WebRTCCoreConfiguration Have statistics functions return a meaningful, non-none result even if only one value is available (home-assistant#127305) * have statistics functions return a meaningful, non-none result even if only one value is available * improved code coverage Add switch platform to the Lektrico integration (home-assistant#126721) Fix devolo_home_network devices not reporting a MAC address (home-assistant#129021) Bump actions/cache from 4.1.1 to 4.1.2 (home-assistant#129018) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Remove deprecated channel views attribute from Twitch (home-assistant#129008) Use runtime_data in balboa (home-assistant#129035) Add `completed` to the wait variable when using triggers (`wait_for_trigger`) (home-assistant#123427) * Add support for the wait.completed variable when using wait with triggers * Remove junk comment --------- Co-authored-by: Erik Montnemery <[email protected]> Use runtime_data in bang_olufsen (home-assistant#129037) Create tests for sense integration (home-assistant#128418) * Create tests for sense integration * Rearrange files * Update to use snapshots * Update tests/components/sense/__init__.py Co-authored-by: epenet <[email protected]> * Update tests/components/sense/__init__.py Co-authored-by: epenet <[email protected]> * Update tests/components/sense/test_binary_sensor.py Co-authored-by: epenet <[email protected]> * Update tests/components/sense/test_sensor.py Co-authored-by: epenet <[email protected]> * Add missing imports --------- Co-authored-by: epenet <[email protected]> Bump yt-dlp to 2024.10.22 (home-assistant#129034) Bump sensorpush-ble to 1.7.0 (home-assistant#128951) changelog: Bluetooth-Devices/sensorpush-ble@v1.6.2...v1.7.0 Fix calculation of attributes in group sensor (home-assistant#128601) * Fix calculation of attributes in group sensor * Fixes * Fixes * Make module level function Fix get_time_zone annotations in dt_util (home-assistant#129050) Fix cancellation leaking upward from the timeout util (home-assistant#129003)
Have statistics functions return a meaningful, non-none result even if only one value is available
Breaking change
The
statistics
sensor will now calculate a value based on a single numerical sample from the input sensor, instead of requiring two numerical samples, for the following characteristics:average_linear
average_step
distance_95_percent_of_values
distance_99_percent_of_values
noisiness
percentile
standard_deviation
sum_differences
differences_nonnegative
variance
Proposed change
Currently many of the statistics function return none when only one value is available, however, a meaningful value exists (e.g. the average of { 17.5 } is 17.5). This change will return a value for all of those cases. None will still be returned in cases where no value is available.
This is primarily an issue when you have values that are (at least sometimes) not changing frequently. E.g. my solar production is noisy during the day (meaning subsequent measurements will usually vary at least a little), however, at night the value is stable (zero). E.g. when I want to compute the average, the maximum, the minimum of those values, it will return none at night. This value will become none at night even though everything is working fine and it could (and should) report zero in the mentioned cases and you have to build workarounds around it to combine the current value with the average to have the "real average" computed.
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
.To help with the load of incoming pull requests: