My switch was on for 10 minutes today (controlled by an HA timer) which gives a state of 0.1666. Clearly this is a rounding issue (so you could, and probably will argue it is not wrong ) but would it have hurt for the history sensor to have saved a few extra decimals given it measure fractions of a fairly large unit i.e. an hour?
Even so…
how does 0.17 hours translate to the attribute value: 9m?
I see that, “The History Stats integration was introduced in Home Assistant 0.39” so either I am wrong or no one has noticed this in a long time.
But I also see that, “it’s used by [only] 3.7% of the active installations.” So I’m probably banging my head against a wall on this one
The state is the time in hours. 0.17 * 3600 = 612s, which is 10m12s. Each increment in the second decimal place represents an increase of 36s — an additional decimal would be 3.6s resolution, which is probably where it gets more precise than it is accurate.
It would be easy to “fix” this: see line 162 of this file:
but I’d argue that if you’re seeking that level of precision, you’re using the wrong tool. Note that the rounding is only in returning the internal value as the state, and “full” precision is retained internally.
See line 182, then line 330 of that file. The pretty_duration() function is turning the internal float hours value into a “pretty” integer number of minutes — must be fractionally under 10 mins. 0.165h (the minimum to show 0.17) is 9m54s.
Unless you submit it as a pull request for the core…