I’ve got a scrape sensor that grabs a tag made up of a number and degree symbol. If it passes “299 and the degree symbol”, I want to take the 299 and use Float to convert it. I can’t seem to find a way to slice the string using the value template to get rid of the degree symbol. Slice and Truncate don’t work and Trim is only for whitespace. Replace would if it were a regular character not an ASCII symbol (using a Linux system).
My next step is to write an Appdaemon app to slice it, but I’d like to keep it simple if I’ve overlooked something.
EDIT:
Replace() will work with special characters if they are entered correctly (I was using ASCII keyboard shortcuts). The tip I found was to use the Character Map accessory built into both Ubuntu and Windows to enter the exact character. It’s searchable so Ctrl-F “degree” found the degree symbol. My value template looks like this:
I experienced same problem accessing the TP-Link HS-110 state attributes. I am using the HS-110 to manage the 120V charging system for my Nissan Leaf so I know when the car is actually charging. However, the state attributes are returned to HA as strings apparently so using just the ‘float’ parameter doesn’t work.
For example, the following template statement run in the developer tools:
The JSON response I get from a query is:
{“bus”: “344”, “time”: “2”, “distance”: “625”, “estate”: “0”}
All data is treated as text. How could I convert them to an “int” type?
The following instruction does not work (| int):
'{{states.sensor.origendatosautobuses.attributes.time | int}} ’
Is that an actual response or something you’ve typed yourself? Some of the quotation marks are typographic, try replacing them with straight ASCII ones " ". If you do that, type casting should work fine (at least it does so for me).