The issue I’m having is that I’m seeing some entities in the resulting list with a state of 100% or 100.0%. I think this is because the state of these sensors are strings, rather than integers:
It’s not that some are strings and others are integers. The state value of all entities is a string.
The problem is that your template isn’t performing a numeric comparison, it’s doing a string comparison.
| selectattr ("state", "le", "20")
When you compare strings, it’s actually performing an alphanumeric comparison of each character in the string (based on the character’s ASCII code value). In other words the letter A is less than the letter B because A comes before B in the ASCII table. This means if you perform a string comparison of numeric strings, you can get seemingly nonsensical arithmetic results like "100" is less than "20".
Compare the difference between numeric and string comparisons:
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.