This seems like a very dumb question, but i cannot figure out how to get it solved.
I have a PHP-script that updates a virtual sensor in my HASS setup:
<?php
$temp = '19';
$tempfloat = floatval($temp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.4.13:8123/api/states/sensor.buitentemperatuur");
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"state\": \"$tempfloat\", \"attributes\": {\"unit_of_measurement\": \"°C\", \"friendly_name\": \"Buitentemperatuur\"}}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "X-Ha-Access:";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
```
It updates the temperature nicely, but the degree sign is messed up, as it displays as '19 �C'.
I tried with '°' in the PHP-code, but it didn't work.
Can someone please enlighten me how to get a correct degree sign (°) in HASS by using this PHP-script?
I'm also not sure if the value is being put in HASS as a float, even though i put in the `floatval()` part. How can i check if it is? If it is put in as a string, that would make it unuseable to use in a automation :stuck_out_tongue:
i think its probably better to just update the value from the sensor.
the unit of measurement is then set just 1 time in the config as a customize from the sensor.buitentemperatuur
i think it must be something like this.
youre PHP must make a sensor buitentemperatuur and the template connects to that.
and it must have a different name
It was indeed a problem with encoding. I always edit my .yaml’s with the built-in editor of WinSCP, so i can edit the files directly on the VM that HASS is running in.
In WinSCP i opened the file with an external editor (Sublime Text 3, nice syntax marking), copied and pasted the Celsius markup part from here and clicked ‘Save with encoding’ and chose ‘UTF-8’. Then HASS would boot without problems and displayed a nice degree symbol
Further i setup the sensor like ReneTode mentioned: