I’m wondering if there is a way that I can change the state that is given for a sensor. For example, I have an Allergy Index sensor that returns “6.9 index” and I want to be able to create a template that will show an image based on the value. So I want the state return to be an integer like “6.9” instead of the text return. This way I can use conditions to display the image I want.
I get what you mean though. This should replace " index" (including the leading space) in the string with nothing then convert it to a floating point number.
If the text you wish to remove is always 6 characters long (one space character plus five letters in the word ‘index’) you can slice off the last 6 characters like this: