Lvgl: label using /n wont work

i cant get the /n newline to work in my label.

In my home assistnat automation i write to a json file: The servicecall fot add an entry with text wich includes /n newline. Whatever i do the LVGL label does not do anything with the /n. i try:

{{ 'Vandaag: ' ~ states('sensor.afvalwijzer_today') | capitalize
       ~ '\\nVolgende: ' ~ states('sensor.afvalwijzer_next_in_days') ~ ' ' ~
       ('dag' if states('sensor.afvalwijzer_next_in_days') == '1' else 'dagen')
       ~ '\\nType: ' ~ states('sensor.afvalwijzer_next_type') | capitalize }}

Results on screen in one line of text: exact output including quotes:
“Vandaag: Geen\nVolgende: 20 dagen\nType: Pmd”

"Vandaag: {{ states('sensor.afvalwijzer_today') | capitalize }}\nVolgende: {{ states('sensor.afvalwijzer_next_in_days') }} {{ 'dag' if states('sensor.afvalwijzer_next_in_days') == '1' else 'dagen' }}\nType: {{ states('sensor.afvalwijzer_next_type') | capitalize }}"

Gives the same result.

Testing with writing “thisone/nthistwo/nthisthree” Label shows me one line of text: thisone/nthistwo/nthisthree

In Esphome label wiki states the note: Newline escape sequences are handled automatically by the label widget. You can use \n to make a line break. For example: "line1\nline2\n\nline4" . For escape sequences like newline to be translated, enclose the string in double quotes .

What am i doing wrong here?
I am out of clues. Can anyone shed a light?

Thanks in advance

You aren’t inserting newlines, you are inserting a backslash followed by n, so that’s what you get. Just use \n, don’t double the backslash.

This is actually an HA question, nothing to do with ESPHome, and you can test it with the Developer Tools/Template Editor.

Thank you for your responce @clydebarrow, in HA it works correct, in jinja also. Could be HAS or Esphome but mostly me. For anyone who encounters the same problem i made a workaround again, its nog esphome or HAS, its me who cant figure it out. If someone has a better solution i’m open for sugestions.

// Parse possible "\\n" to real newlines
{
  std::string raw = id(msg_text);
  std::string parsed;
  parsed.reserve(raw.size());
  for (size_t i = 0; i < raw.size(); i++) {
    if (raw[i] == '\\' && i + 1 < raw.size() && raw[i + 1] == 'n') {
      parsed.push_back('\n');
      i++; // skip  'n' 
    } else {
      parsed.push_back(raw[i]);
    }
  }
  id(msg_text) = parsed;
}

It works just fine: HA template sensor:

{{ 'Line 1\nLine 2'}}

ESPHome config:

text_sensor:
  - platform: homeassistant
    entity_id: sensor.test_template_sensor
    id: ha_sensor
    on_value:
      - lvgl.label.update:
          id: label_id
          text: !lambda return x;


lvgl:
  widgets:
    label:
      id: label_id
      align: center
      text: not yet set

The result after API connection: