From 701e8a414a79d2fef2b486c8cf2fdc2be514134e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 3 Oct 2022 11:40:46 +0200 Subject: [PATCH] Adjust blog post for statistics changes (#1484) * Adjust blog post for statistics changes * Remove PR78932 --- blog/2022-09-29-statistics_refactoring.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/blog/2022-09-29-statistics_refactoring.md b/blog/2022-09-29-statistics_refactoring.md index 9eb79ff6..dffee6dd 100644 --- a/blog/2022-09-29-statistics_refactoring.md +++ b/blog/2022-09-29-statistics_refactoring.md @@ -4,25 +4,16 @@ authorURL: https://github.com/emontnemery title: "Long term statistics now tracks the source entity's unit" --- -Long term statistics now tracks the unit of the source in a new column `state_unit_of_measurement` in addition to the existing column `unit_of_measurement` in the `statistics_metadata` database table. The meaning of the two columns is: - -- `unit_of_measurement` - The unit which statistics is stored in. For sensor device classes where it's allowed for the user to override the unit, this is a normalized unit, for example `kWh` for energy sensors. -- `state_unit_of_measurement` - The unit which statistics should be displayed in. For sensors, this is the same as the `unit_of_measurement` state attribute. +Long term statistics now allows showing statistics in a different unit than it's stored in. For example, it's possible to show statistics stored as `kWh` as `Wh`, `kWh` or `MWh`. The changes are implemented in a series of PRs: - https://github.com/home-assistant/core/pull/78031 - https://github.com/home-assistant/core/pull/78578 -- https://github.com/home-assistant/core/pull/78932 +- https://github.com/home-assistant/core/pull/79370 The background is that we allow overriding the unit of several sensor device classes, and this override should also be reflected when viewing long term statistics. -This affects authors of custom integrations or web based services importing long term statistics: - - The type `StatisticsMetaData` has a new member `state_unit_of_measurement`, which must be set correctly in calls to `async_add_external_statistics` -- A new mandatory field `state_unit_of_measurement` has been added to the metadata parameter in WS API `recorder/import_statistics`. - -This also affects authors of code calling the following WS APIs: +This affects authors of code calling the following WS APIs: - `recorder/adjust_sum_statistics` - A new mandatory parameter `adjustment_unit_of_measurement` has been added, which defines the unit used by the `adjustment` parameter. - - `recorder/get_statistics_metadata` - The result now includes the `state_unit_of_measurement` for each returned metadata entry. - - `recorder/list_statistic_ids` - The result now includes a `state_unit_of_measurement` for each returned metadata entry. - - `recorder/statistics_during_period` - The returned statistics will be according to each statistic_id's `state_unit_of_measurement`. This behavior can be controlled by passing the optional `units` parameter. + - `recorder/statistics_during_period` - In case of statistics generated from sensor entities, the unit of returned statistics will be converted to the sensor's `unit_of_measurement`. This behavior can be controlled by passing the optional `units` parameter. \ No newline at end of file