c.man
(carmine)
August 5, 2018, 5:41pm
1
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 ?
petro
(Petro)
August 6, 2018, 2:12am
2
What your seeing is called machine epsilon
Machine epsilon gives an upper bound on the relative error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subject of computational science. The quantity is also called macheps or unit roundoff, and it has the symbols Greek epsilon
ϵ
{\displaystyle \epsilon }
or bold Roman u, respectively.
The following values of machine epsilon apply to standard flo...
This happens sometimes, you can’t do anything about it other than convert the number to a string (format or string filter).
1 Like
c.man
(carmine)
August 6, 2018, 8:24am
4
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
petro
(Petro)
August 6, 2018, 11:54am
6
@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.