Hello, I’m trying to create a template sensor in my configuration file that calculates today’s energy usage in kW x my energy cost of (.16) to display the cost of energy so far today in my dashboard. The following code returns a error message. Ideas?
It’s not rounding the way you expect because the round() function is being applied only to the 0.16 value. In other words, it rounds 0.16 to two decimal places (effectively changing nothing) then multiplies it with the sensor’s value.
That’s why the two terms of the multiplication must be grouped with parentheses to ensure that the result of the multiplication is rounded.