I use this value template for a mqtt sensor
value_template: "{{ value_json.aenergy.total | float * 0.001 | round(2) }}"
It returns a value like 0.328278.
So it shows all decimals and not only 2.
What is wrong with my template?
I use this value template for a mqtt sensor
value_template: "{{ value_json.aenergy.total | float * 0.001 | round(2) }}"
It returns a value like 0.328278.
So it shows all decimals and not only 2.
What is wrong with my template?
You need parentheses around the multiplication so that the round()
is applied to its product… but I would expect the value returned by your current template to be 0.
That did the trick Thanks.
value_template: "{{ (value_json.aenergy.total | float * 0.001) | round(2) }}"