Possible bug - value_template

Think I found a possible bug, but I’d like to run it past the community before submitting a bug report.

So I’ve got a REST sensor, that’s pulling a JSON value.
The Value from JSON is: "moisture": 0.35171621374774037

The current value_template is:
value_template: '{{ (value_json.last_measurements[0]["moisture"]) | round(3) * 100 }}'

Which results in: 35.199999999999996

Another similar sensor has a JSON value of: "moisture": 0.44976927421165236

Put through the same value_template, the result is: 43.8

I would expect both values (after the value_template) to be XX.X.
So why the difference, is my value_template wrong?

First this would be a bug not with HA but with Jinja if I am not mistaken. Further I would do all calculations and THEN use the “round” method. Because that makes it the most accurate and should guarantee your result.

So it would be:

value_template: '{{ ((value_json.last_measurements[0]["moisture"]) * 100) | round(3) }}'


1 Like

Thanks! I’ve implemented the new value_template, and will give it a try for a few days to see if that clears up the problem. If it doesn’t do you have any idea where I might go to submit a bug report for Jinja?

No idea sorry :wink: