Keep a template result as a string, even if it could be converted to a number

Yes, that would work as well. Home assistant’s typing logic is not recursive. It only looks at the top level object and types that. So providing a dict {} or list will cause the contents to remain what they are when being pushed to whatever field they end up in. Templating the whole data field is rather new (~ circa 2021.08, 09, or 10). However many non-single item fields have always accepted lists. This will be hit or miss without you looking at the documentation.

Thanks for the {{ "{}\x00".format(x) }} reference. I have HA version sensor badges based on template sensors that would convert HA version format from 2021.12.9 to 12.9 worked great until version .10 came out and the trailing zero is lost.

Now I use {{ "{}\x00".format(states.sensor.latest_version.state[5:]) }} and it correctly reports 12.10 as the version in the badge.

1 Like

Is there a way to change the language on a string result ? I have Google Travel Time enabled and with a sensor attribute result it displays it as like 38 mins. I would love to remote “min” from results or maybe change it to my own language.

{{ states.sensor.google_ev_is.attributes.duration_in_traffic }}

![Ekran Resmi 2022-06-08 18.17.19|690x298](upload://71tQWC0bkVYeJtx0ogoIlsJJ4u6.png)

Thnx, I just bumped into this problem as well when storing the audio format as an attribute value. “5.1” becomes a number and there seems nothing you can do about other than adding the string termination char.
Not sure if this char will bite me again when I start using this attribute with matching.

I understand is if nice that some parser in the background automatically determines types. But as always, there’s always an exception where this is undesirable.
Would have been nice if there was a keyword to bypass this auto parsing behavior.