home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.69k stars 30.44k forks source link

wrong values for input number helper when incrementing in 0.01 steps #128127

Open pjoester opened 1 week ago

pjoester commented 1 week ago

The problem

This issue was alread reported with #114329 but unfortunately it was closed and is not fixed at all. Can you please take a look at this issue?

I use the input number helper for tracking our gas consumption. An automation has an action to increment the input number value. This should be done in 0.01 steps like it is configured in the settings of the input number helper: Helper

This works fine for a while but sometimes the incrementation is done in 0,0000000001 steps so the result is a wrong value for my gas meter: issue

This issue can also be reproduced when just setting up another input number helper which was incremented e.g. every second. After a few minutes the error already occurs. The latest test shows that it the increases are done in 0.0.1 steps but then there is one step of 0,9999999999 in between: test

What version of Home Assistant Core has the issue?

2024.10

What was the last working version of Home Assistant Core?

was never working before

What type of installation are you running?

Home Assistant OS

Integration causing the issue

input_number

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

elupus commented 1 week ago

Log screensh6 shows increments of 0.01 in all steps. The addition decimals is just float precision limitation. Just set you display decimals to 2

pjoester commented 1 week ago

It's definitely not only a display setting of the decimals. My "gas meter" should increase by 0.01 steps every time the action is triggered. Some times it just increases by 0,0000000001. The inaccuracy of the digital gas meter over the real one gets gets worse and worse over time then.

elupus commented 1 week ago

Well yes by a very, very small error. Would take many years to be any real discernable difference.

Like I said the screenshot you show shows each step being about to .01. (the hard to see one being 2.27 to 2.2799...) which with rounding is still correct.

Can you show a log of where it increments with a wrong step?

pjoester commented 1 week ago

Hey. I did another test. This time the value had again the "X.0000000001" at the end (see screenshot). But if rounded the incremental steps were correct like you said. But then it is not a display issue of the input number. It is a very small inaccuracy of the incremental step because if the issue occurs multiple times I have "X.0000000002" or "X.0000000003" at the end. Due to the fact that the difference of the values of the virtual and the physical gas meter is increasing over time I was sure that the incremental step was "X.0000000001" some times. But maybe my sensor just doesn't get every pulse. I'm gonna check that again. According to the last tests it is more likely that the incremental steps are sometimes "X.0100000001"or "X.009999999". Then this issue is not as bad as I thought :-). Thanks for your Feedback. test2

Baxxy13 commented 1 week ago

I can see these float precision limitations here and there in HA. Another example to reproduce: https://github.com/home-assistant/core/issues/89154

Even statistics is affected, i wrote about it here: https://community.home-assistant.io/t/energy-dashboard-csv-download-values-with-up-to-18-decimal-places-is-that-normal/770103

Of course a precision error of 0,0000000000000001 isn't a real problem but mathematically it's a failure.

In this example the increment should be 0.001, but it is 0,0010000000000001

Input_number_Helper_Inkrement_Test wechselte zu 0,0720000000000001 ausgelöst durch Automatisierung Test Increment ausgelöst durch Zeit pattern
15:24:10 - Vor 18 Minuten
Input_number_Helper_Inkrement_Test wechselte zu 0,071 ausgelöst durch Automatisierung Test Increment ausgelöst durch Zeit pattern
15:24:00 - Vor 18 Minuten

And the opposite, the inkrement should be 0.001, but it is 0,0000000000000009

Input_number_Helper_Inkrement_Test wechselte zu 0,1 ausgelöst durch Automatisierung Test Increment ausgelöst durch Zeit pattern
15:29:40 - Vor 15 Minuten
Input_number_Helper_Inkrement_Test wechselte zu 0,0990000000000001 ausgelöst durch Automatisierung Test Increment ausgelöst durch Zeit pattern
15:29:30 - Vor 15 Minuten