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.