1299
1
I want to convert the brightness 0-255 value to percentage but something weird is going on with the round function.
{% set brightness = (255 | int / 2.55 | round(0)) %}
{{ brightness }}
Result: 85
Cause everyone knows 255 / 2.55 = 85 ![:confused: :confused:](https://community.home-assistant.io/images/emoji/twitter/confused.png?v=9)
{% set brightness = (255 | int / 2.55 | round(1)) %}
{{ brightness }}
Result: 102
What is going on, how is something so basic not working like one would expect?
In jinja the pipes are applied first.
Your first one is rounding 2.55 to zero decimal points, which is 3
255 / 3 = 85
Your second one is rounding 2.55 to 1 decimal point, which is 2.5
255 / 2.5 = 102
The calculation is correct, your syntax is wrong if that is not the calculations you want to do.
1 Like
1299
3
Iām an idiot ![:dizzy_face: :dizzy_face:](https://community.home-assistant.io/images/emoji/twitter/dizzy_face.png?v=9)
{% set brightness = (255 | int / 2.55) | round(1) %}
{{ brightness }}
Somehow I can break my head over something and never find a solution. But the moment I post something I find the error.
1 Like