Skip to content

v1.3.2 - Read statistics in their stored unit

Choose a tag to compare

@mayerwin mayerwin released this 22 Sep 01:57
· 8 commits to main since this release

Fix

Statistics are read in the unit they are stored in, not the unit they are displayed in

Home Assistant keeps a sensor's statistics in the unit they were first compiled in. That stored unit is fixed for the life of the statistic: Home Assistant converts incoming readings into it. The unit shown on the entity is only a display unit, which you can change in the entity settings, and Home Assistant converts storage to display when something reads the statistics back.

The import was reading the displayed values and writing them straight back into the stored column. If a sensor's display unit differed from its stored unit, imported statistics and the running-total adjustment were wrong by exactly the conversion factor. An energy sensor stored in kWh but displayed in Wh would have had a correction a thousand times too large.

Both the source's and the destination's statistics are now read directly from the stored values, so a display setting cannot skew an import. This also puts them in the same terms as the restart detection and the repair, which already read the stored values.

Sensors stored in different units

If the two sensors' statistics are stored in different units, nothing is converted for you. The import result says which units they are and points you at Adjust imported values under Options, which is the one setting that rescales, and which applies to states and statistics alike so both halves of an import stay consistent.

Notes

  • Affects you only if one of the sensors has a display unit that differs from the unit its statistics are stored in, which happens when you pick a different unit in the entity settings. If you have never done that, this release changes nothing about your imports.
  • A destination with no statistics and no loaded state, such as a disabled entity, again takes the source's unit for the metadata it creates. That fallback had been lost.
  • Back up your database before importing, as always.