Hi All!
I trying to make selfmade sensor based on another sensor which outputs temperature as text string. But I can’t convert string to float because format is “73,05” with comma, not point. Is there any such function?
Hi All!
I trying to make selfmade sensor based on another sensor which outputs temperature as text string. But I can’t convert string to float because format is “73,05” with comma, not point. Is there any such function?
Please don’t post pictures of text. I’m not writing all that out.
{{ states('blahblah...')|replace(',','.') }}
OK, sorry.
So, “{{states(‘sensor.n100_nvr_n100_nvr_temperature’)|replace(‘,’,‘.’)}}” now returns string “12.34”. How convert it to numeric value?
All states are strings. If you want it to be treated as a number so you can graph it all you need is a unit of measurement, which you have already, so you should be good to go.
If you want to do maths with it in the template just add |float
after the replace()
I just want to add a unit of measurement to sensor which has no any unit. But I can not find where can I edit sensor parameters
Where does the original sensor sensor.n100_nvr_n100_nvr_temperature
come from?
Was it discovered or did you add it using YAML?
If it was YAML share your sensor configuration, correctly formatted for the forum.
This sensor has been created by HASS.Agent HACS integration.
Why is has no measurement unit? Because it is result of abstract WMI Query request on remote WIN10 PC. I don’t know where and how can I edit this sensor, now it renurns bare string without any attributes
You should use the template suggestions above, but you should also remove the outer quotes from your template in the template editor. If you do not, they end up in the value for the state. Note the tripple quotes in the error message.
I thought to create another template sensor which will use this bare string, but will had temperature attributes. But I have error
“Sensor None has device class ‘temperature’, state class ‘measurement’ unit ‘°C’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘«78 »’ (<class ‘str’>)”
Hah! Yes, that’s right, now it works! Thank you a lot!