Difference between "accuracy_decimals" and "round"

Hi,

can someone explain to me what the difference is in processing the data whether I use “accuracy_decimals” or later a “round” filter?

examples:

  - platform: template
    name: "temperature"
    id: temp
    unit_of_measurement: "°C"
    accuracy_decimals: 1

or

  - platform: template
    name: "temperature"
    id: temp
    unit_of_measurement: "°C"
    filters:
      - round: 1

The round filter will change the actual state sent to home assistant to one decimal place.

The accuracy_decimals option does not change the value reported to Home Assistant, it just sets the number of decimals to use when displaying it in Home Assistant.

This setting:

Is this correct. @tom_l ?


Round filter set to 2 decimals
------------
Original State      Updated State      Displayed State
 25                  25                 25
 25.1                25.1               25.1
 25.012              25.01              25.01
 25.678              25.68              25.68
 25.111111111        25.11              25.11
 25.999999999        26                 26


Accuracy_decimals set to 2 decimals (updated state does probably not even exist here!)
------------
Original State      Updated State     Displayed State
 25                  25                 25.00
 25.1                25.1               25.10
 25.012              25.012             25.01
 25.678              25.678             25.67
 25.111111111        25.111111111       25.11
 25.999999999        25.999999999       25.99

That’s what I thought too, but for some reason it doesn’t apply in my case

any ideas?

maybe because of the calibration? but then there should be just 1 decimal

same behaviour with the ADC value set to “accuracy_decimals: 2”

If it worked like it should, my next question would be how the logs in the database are created (e.g. Influx): is the displayed value logged or the transferred value with all decimal places? In the latter case, the database would quickly become full of useless garbage, when a value frequently changes in the “unseen” decimals.

Accuracy_decimals does not change the value, so all changes should be logged.
You can make a derived sensor that only logs a few, logs a mean, a round or other ways of limiting the values, and then you can exclude the original sensor from the logs.

okay I understand. So this is also as expected. I just tested this and can confirm it. I reduced the display precicion in the HA entity settings window and it continues to log to full accuracy.

But the question left is why the decimal places are lost when I transfer a value from ESPHome to HA (just accuracy_decimals set - no round filter).

Can anyone test whether this is only the case in my configuration or is it a bug? Are there any general settings that could affect this?

ESPHome can work with displays too, so the accuracy_decimal setting is probably only for those local displays.

Am I taking crazy pills here? You have accuracy_decimal set to 2, so you’ll only ever get 2 in HA regardless of the settings in HA.

I’d post the config you should use, but you took pictures instead of pasting code. next time paste code and we can provide you with working configurations.

i dont think so, the documentation tells what @tom_l wrote in the 2nd post:

  • accuracy_decimals (Optional, int): Manually set the number of decimals to use when reporting values. This does not impact the actual value reported to Home Assistant, it just sets the number of decimals to use when displaying it.

My initial question was about the difference between “accuracy_decimals” and filter: round…"
@tom_l wrote in the 2nd post that “accuracy_decimals” does not affect the accuracy of the value, but only the HA setting for displaying the decimal places. This is also confirmed by the documentation (see previous post). In contrast, the decimal places in HA are definetly reduced when using a “round filter”.
Accordingly, when using “accuracy_decimals” you should be able to increase the display accuracy again if the value is actually transmitted with all decimal places. If that’s not the case, then I’ll ask again about the difference between the two approaches.

Here is my code, but I’m not asking you to change anything, I can work with it and it works as desired in my application. However, I would like to understand the difference in order to choose the right path if necessary.

sensor:
  - platform: adc
    pin: A0
    name: "Spannung A0"
    id: spannung_a0
    update_interval: 0.01s
    unit_of_measurement: "V"
    accuracy_decimals: 3
    filters:
      - multiply: 3.3
      - throttle_average: 1s
    on_value:
      then:
        - lambda: |-
            id(temp).publish_state(id(spannung_a0).state);

  - platform: template
    name: "Temperatur Sole"
    id: temp
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
          - 1.443 -> 30.3
          - 2.053 -> 16.0
          - 2.190 -> 13.3

well, you can attempt to add logs to see actual values

sensor:
  - platform: adc
    pin: A0
    name: "Spannung A0"
    id: spannung_a0
    update_interval: 0.01s
    unit_of_measurement: "V"
    accuracy_decimals: 3
    filters:
      - multiply: 3.3
      - throttle_average: 1s
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "Voltage sent to temp %.6f", x);
            id(temp).publish_state(id(spannung_a0).state);

  - platform: template
    name: "Temperatur Sole"
    id: temp
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    filters:
      - calibrate_linear:
          - 1.443 -> 30.3
          - 2.053 -> 16.0
          - 2.190 -> 13.3
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("main", "Temp sent to HA %.6f", x);

Within the ESPHome script it works as it should: when I pass a value (using “accuracy decimals 1”) to another template sensor, I still get the full number of decimal places. For testing I’ve set decimals to 4, because it seems the default setting is 1.

Maybe it’s meant that way, but then the documentary isn’t formulated very clearly.

sensor:
  - platform: adc
    pin: A0
    name: "Spannung A0"
    id: spannung_a0
    update_interval: 0.01s
    unit_of_measurement: "V"
    accuracy_decimals: 3
    filters:
      - multiply: 3.3
      - throttle_average: 1s
    on_value:
      then:
        - lambda: |-
            id(temp).publish_state(id(spannung_a0).state);

  - platform: template
    name: "Temperatur accuracy 1"
    id: temp
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    filters:
      - calibrate_linear:
          - 1.443 -> 30.3
          - 2.053 -> 16.0
          - 2.190 -> 13.3
    on_value:
      then:
        - lambda: |-
            id(temp2).publish_state(id(temp).state);

#test runden    
  - platform: template
    name: "Temperature accuracy 4"
    id: temp2
    unit_of_measurement: "°C"
    accuracy_decimals: 4

here the logs, but in fact i can’t see all the decimals in HA

[15:01:53][D][sensor:093]: 'Spannung A0': Sending state 2.12186 V with 3 decimals of accuracy
[15:01:53][D][sensor:093]: 'Temperatur accuracy': Sending state 14.66433 °C with 2 decimals of accuracy
[15:01:53][D][main:094]: Temp sent to HA 14.664326
[15:01:53][D][main:078]: Voltage sent to temp 2.121857

The exact values ​​are in the logs anyway, but they don’t arrive in HA with full accuracy

For shits and giggles, try sending the value as a number with a random unit of measurement, not temperature (make a 3rd sensor). Maybe this is specific to the temperature device_class in home assistant.

Same behavior with your suggestion…

but: the log files already indicate that only the set decimal places are sent to HA.

As already mentioned, the documentation does not seem to be formulated very clearly here. Or maybe this description comes from an earlier version and was forgotten to change:

so in summary:
accuracy_decimals maintains full accuracy of values ​​within the ESPHome script, but not when passed to HA

1 Like

TBH, I’ve never read the description of accuracy_decimals until you posted it. Might be worth making a PR for the esphome documentation to clarify your findings. I’ve always assumed they truncated what was being sent to HA.