I have small problem which I can’t find out how to solve.
I made template sensor to recalculate PM2.5 value to have as percentage.
sensor.air_quality_pm25 is my sensor
Thanks, makes it easier to read when formatted properly.
So that odd rounding (40.0000000000001) looks like floating point rounding error which is unfortunately unavoidable, even if you add the int filter at the end (I believe). As for why it displays differently in the template tool I’m not sure. I did, however, clean up your code:
Good practice to add a float filter to a number you’re using in a template to ensure it is parsed correctly. The int filter shouldn’t have an effect since you’re rounding to zero decimal places but I left it in anyway since it shouldn’t have an effect in this case being at the end of the value template.
Also, note that this template will accomplish the same as above with the added benefit of preventing errors from appearing in your log when the underlying sensor isn’t ready (such as upon startup):
Not quite sure of the way this processes the order but /25*100
Will either equate to /2500 or *4 (can’t check at the moment)
That would make it shorter still.
What number range do you expect ?
We could use text truncation and then just post that eg [0:3]
Sorry for this incorrect start from my side, but leasson learned, now I know a bit more. It’s like reading manuals - mostly nobody is doing that and then this person is suprised…
I will check this right now
Interesting thing is that it seems that it is some different problem…
When I’m editing template and then reloading just templates, it works OK. But after restart of HA, then value is incorrect… Any ideas?