Add deslugify as template filter

now we have the |slugify filter made possible by @ZephireNZ ’ PR Add slugify as a template filter by ZephireNZ · Pull Request #58724 · home-assistant/core · GitHub allowing for the below template:

 filter:
   template: |
     {% set hue_group = states('input_select.hue_group_v2') %}
     {% set ns = namespace(scenes=[]) %}
     {%- for s in states.scene
           if hue_group == s.attributes.group_name %}
             {% set ns.scenes = ns.scenes + [{'entity':s.entity_id,
                  'name': s.object_id.split(hue_group|slugify +'_')[1]|capitalize|replace('_',' ') }] %}
     {%- endfor %}
     {{ns.scenes}}

(which I use in a template-entity-row setup, but could ofc also be used in core) with much simpler configs like:

    sequence:
      service: >
        script.lighting_{{states('input_select.activity_lighting')|slugify}}

or

          {% set radio = states('input_select.wakeup_radio') %}
          {% if radio in ['Woonkamer','Library','Hall','Master bedroom','Office','Studenten'] %}
             media_player.googlehome_{{radio|slugify}}

I was hoping a reversed ‘deslugify’ would be introduced accompanying that.

slugify: |lower|replace(' ','_')

de-slugify: |capitalize|replace('_',' ')

seems so very obvious to have that, hope it gets some consideration.

slugify: |lower|replace(' ','_')

That is not what slugify does. It does a lot more.

As a matter of fact, it is considered inreversable. With than in mind I do not see how a “deslugify” would ever exists.

wasnt aware it did more than that Frenck, I now see eg awesome-slugify · PyPI and understand what you’re saying.

was hoping to replace the often used string manipulation |capitalize|replace('_',' ')

if you’re saying that wont be, than thats a pity, but I can see your Pov on the matter :wink:

will close if you say so. Wait, guess you need to do that…