UTF-8 Error

Hi all,

I have been posting on another topic on this forum with an issue with the climate sensor not working and showing NULL as the current temperature.

My temperature sensor is reporting just fine to HA. I was told that its because I wasnt using the unit_of_measurement: °C on the temperature sensor.

When I put this line against my temperature sensor I get the following error when I restart HA

Can anyone help with this?

Link to the topic regarding the climate sensor and this symbol error, may provide some context as to why im needing to use this symbol - Thermostat Trouble

Try this:
# iconv --from <your_encoding> --to utf-8 < config_file_orig.yaml > config_file_new.yaml

Then rename the new config file to the old one.
Don’t use the name of the original file as the new one as you will end up with an empty config file.

Sebastian

Thanks,

I run this as a command in an SSH terminal yes? Where you have put <your_encoding> how do I found out what the current encoding is to know what to put here?

Yes, this is run from the command line.
You can try “file <your_config>”, it should return something like “ASCII text” or “ISO-8859 text” or something like that - it depends on your system language settings.
So if you get ISO-8859 you run “iconv -f iso-8859 -t utf-8 <configuration.yaml >configuration_new.yaml” and you should be good to go.
Alternatively you can use an editor that produces valid utf-8 encoded files - I think there’s a thread here somewhere.

Sebastian

Ok great,

one last question, does this have to be done on the configuration.yaml file? My configuration is spread over multiple yaml files. So the one where im trying to insert the character is in climate.yaml so im guessing id run it against that file containing the character rather than the main configuration.yaml file?

No, you need to do this on the file that HA is complaining about.
Looking at your screenshot, it should be sensors.yaml.

Sebastian

Didnt work

I ran

iconv --from “ASCII Text” --to utf-8 < sensor.yaml > sensor_new.yaml

Then renamed the new file to what the original one was called.

Restarted HA and get the same error again.

Ok ignore that I checked the wrong file and used ASCII when it should have been ISO-8859

I ran

iconv -f iso-8859 -t utf-8 <sensor.yaml >sensor_new.yaml"

I get the following error

iconv: conversion from iso-8859' is not supported Try iconv --help’ or `iconv --usage’ for more information.

Tried a different approach,

I backed up the file first then ran

iconv -t UTF-8 sensor.yaml

Aparently you can run this command without specifying the original encoding.

I get the following error

  • platform: mqtt
    name: Bedroom Temperature
    state_topic: “homeassistant/sensors/DHT22/temperature”
    unit_of_measurement: "iconv: illegal input sequence at position 4486

So it seems it dosent like the degree symbol inside the sensor.yaml file. Any ideas why it dosent like it?

I think iconv tries to guess the original encoding when you don’t specify a source encoding.
It may be that you’d need to be more specific specifying an iso8859 encoding, like iso-8859-1.
When iconv is complaining, there’s probably a mismatch in the specified source encoding.
It’s probably best to redo the file with the correct encoding from scratch.
I think many members are using SublimeText or Atom for editing their config files.

Sebastian

Great, fixed the problem.

I created in an SSH session a new empty sensor.yaml file after backing up the old one.

I then converted it using your command above to UTF8, although when I did that and then re checked the file it said it was ASCII. Ignored that.

I opened my sensor.yaml backup file and copied all of the data inside it and pasted it using an SSH terminal into the new one and then added the “line unit_of_measurement: “°C”” and saved it. I then ran a “file sensor.yaml” and it came back as UTF-8 woohoo!

Re ran HA and it ran successfully and now my climate module is now picking up the temperature from the temperature sensor :slight_smile:

Thanks for your help!

1 Like

Glad it works now :slight_smile: