Unicode Characters from MQTT

Hi all,
I get messages from MQTT that contain unicode characters like “\u00f6” in text strings. How can I configure HA to display the special character?

Here an example what I see:

“Ladevorgang nach Ablauf der Abschaltverz\u00f6gerung gestoppt.”

I like to see:
“Ladevorgang nach Ablauf der Abschaltverzögerung gestoppt.”

That is the YAML config

mqtt:
  sensor:
    - name: "openWB State Str"
      unique_id: "openWBstate_str"
      state_topic: "openWB/openWB/chargepoint/2/get/state_str"
      #encoding: ""
      device:
        name: "openWB"
        identifiers:
          - "openWB"  

Thanks for your help!

Display where?

Looks like the template engine converts it:

Does it mean I have to use a template too? Okay, when I add an additional template it works. Is it possible to avoid an additional template and add this to the sensor config?

Total guess, and this line often crops up in people’s questions but does nothing usually — try adding:

value_template: "{{ value }}"

to your config.

1 Like

Great, that works! I understand that the value needs to run through " {{ }}".

1 Like

oops, I put a fixed string in the config, not a states function. Both ways do not work, it still shows the wrong encoding. :thinking:

Where does it show it? Did you understand that the value_template was meant for the MQTT sensor?

mqtt:
  sensor:
    - name: "openWB State Str"
      unique_id: "openWBstate_str"
      state_topic: "openWB/openWB/chargepoint/2/get/state_str"
      value_template: "{{ value }}"
      device:
        name: "openWB"
        identifiers:
          - "openWB"  

Can you see the MQTT topic in something like MQTT Explorer?

MQTT Explorer shows both:

The config is completely as you wrote above.

image

Try:

value_template: "{{ value.encode('utf-8').decode('unicode-escape') }}"

Cool, now it works:

Help me please, what is going on in this line?

value_template: "{{ value.encode('utf-8').decode('unicode-escape') }}"
1 Like

It’s taking the (ASCII / unencoded) string with the escaped special characters, converting it (encode) into a UTF-8 bytes sequence, then converting it (decode) into a Unicode string with real characters that are outside the ASCII range.

If you really want to get into the nuts and bolts:

2 Likes