Round calculus

Hi,
I would to round a cpu temperature.
So I declare this sensor in sensor.yaml:

  • platform: command_line
    name: CPU Temperature
    friendly_name: ‘CPU’
    command: “cat /sys/class/thermal/thermal_zone0/temp”
    unit_of_measurement: “°C”
    scan_interval: 120
    value_template: ‘{{ (value | multiply(0.001)) | round(1) }}’

sometime I see correct result (49.692 °C), sometime I see result wrong (49.230000000000004 °C).
Why ?

What your seeing is called machine epsilon

This happens sometimes, you can’t do anything about it other than convert the number to a string (format or string filter).

1 Like

try adding:

| float

after “round(2)” or as a substitute of “round (2)” ?

Guess i’d try it like this:

| multiply(0.001)) | float | round(1)

Play around with it in the template editor of the FrontEnd to get the right desired result

@c.man
It doesn’t matter what you do. The epsilon error is coming from the round function. It’s present in all coding languages. As I said before: The only way to remove it is to convert it to a string. But if you want your graphs to use them as numbers, then leave it and ignore it.