Capitalize / Title in combination with "_" (understrike)

Dear all,

I’m using the following service:

service: input_text.set_value
data:
  value: >-
    {{ area_id(trigger.entity_id) | capitalize | replace("_", " ") |
    replace("og", "Obergeschoss") | replace("Kuche", "Küche") | replace("eg",
    "Erdgeschoss") }}
target:
  entity_id: input_text.alarmtrigger_area

to set the value of an input text helper with the area of the trigger ID.
The value itself can e.g. be “gallery_livingroom” whicht should be transformed to Gallery Livingroom.
With the code above it translates to “Gallery livingroom”. Due to the “_”, the title instead of capitalize likewise doens’t work since in the beginning it was considered a single word.
Any idea how to automatically capitalize both Gallery" and “Livingroom” (as an example, without hardcoding exactly these words).

Thank you a lot in advamce for your help!

Capitalize only does the first letter, title treats it like a title. Also, just move it to the end.

    {{ area_id(trigger.entity_id) | replace("_", " ") |
    replace("og", "Obergeschoss") | replace("Kuche", "Küche") | replace("eg",
    "Erdgeschoss") | title }}

Didn’t realize sequence is relevant - but makes sense :slight_smile: Thank you!

One more question: How to capitalize all characters of a word in case of e.g. only 2 characters in total?