#ESPHome problem: hallucinated decimal values

1 messages · Page 1 of 1 (latest)

grim jolt
#

Sensor value seems to be coming from an esphome device with one level of accuracy (per the device logs) and Home Assistant is hallucinating some extra data that (maybe) wasn't sent 🙂

Example: ESPHOME Logs show "Sending state 56.20000 % with 0 decimals of accuracy" but HA shows "56.2000007629395" as the state. I tried adding accuracy_decimals: 2 to the config and now ESPHOME logs now show 2 decimals of accuracy but the value in HA still has the extra decimals at the end. This does not always happen - only sometimes.

Per https://esphome.io/components/sensor/index.html (Italics emphasis mine)

accuracy_decimals (Optional, int): Set the number of digits after the decimal point that data consumers should use. While this does not change the value sent across the API, Home Assistant’s ESPHome integration will round the value accordingly before using or storing it. The number of digits will also be used to set the entity’s default display precision. Thus, one can display fewer decimals, but cannot increase precision of sensor values in Home Assistant. (The default value varies depending on component and sensor.)

I asked over on the ESPHome Discord and the first response I got was "it's an HA problem, not an ESPHome Problem".

FWIW I've only noticed this happening recently (I did recently update all my docker images for HA and ESPHome and reflashed all my esphome devices with the latest firmware)

grim jolt
#

Per ssieb on ESPHOME Discord: "It's an HA issue with displaying and it depends on the value because of how floats work."

Any insight over here?

warm cave
#

Welcome to the world of floats 🙂 With a 32-bit float you can expect about 7 digits of precision. Not decimals, digits. So 56.20 is 4 digits of precision. For 64-bit that would be around 16 digits.

So it is a ESPHome issue. As ESPHome uses 32-bit floats and HA uses 64-bit (as they phase out 32-bit installation).

But setting the number of decimals to 2 in HA should fix it as that would limit it to below 7 digits. Seems like HA is not always adopting the new accuracy_decimals value from ESPHome.

#

Although I'm not sure how ESPhome will send the value. If it will transfer the 32-bits of the float or for example a 15 digits ascii value and or where it's parsed into the HA all string / 64-bit float state. As it could also be a problem in the ESPHome integration.