In my case here, I’m using cards: custom:auto-entities + custom:mushroom-chips-card , however this is a general question as im hoping it can apply to any card type.
Im trying to shorten the names for lights for the dashboard, as using the Lutron Casetta integration, the entities get added as: , example: “Exterior Pool House Lights” (too long in many dashboard cases)
is there a way to apply regex (regex capture-groups im thinking), or another way to shorten these names as they are displayed on the dashboard?
(or worst case is there a way i can hard-code these entity/lights names somewhere and reference those hard-coded names perhaps?)
below is the related dashboard code , and an image showing what im referring to.
(even if one can point me in the right direction, i can figure out how to implement, and will update this post w solution)
You can use a similar method as me, using filter template and replace with regex… in my case they have in common in the names Contact Sensor, then the rooms name
for those curious, this is what i finally went with (with help from chatGPT and alot of fourms searching - ie to get syntax right as This is my first time using jinja2)
{% for entity in states.light if '_screen' not in entity.entity_id and entity.state == 'on' %}
{%- set name = state_attr(entity.entity_id, "friendly_name") -%}
{%- set name = name | regex_replace(find='Exterior ', replace='') -%}
{%- set name = name | regex_replace(find=' Light', replace='') -%}
{%- set name = name | regex_replace(find=' Mains', replace='') -%}
{%- set name = name | regex_replace(find='s 3x', replace='') -%}
{%- set name = name | regex_replace(find=' 1x', replace='') -%}
{%- set name = name | regex_replace(find='Family Room ', replace='') -%}
{{
{
'type': 'template',
'content_info': name,
'icon': 'mdi:lightbulb',
'icon_color': 'orange',
'content': name,
'entity': entity.entity_id
}
}},
{%- endfor %}
and the full dashboard yaml (using custom:auto-entities + custom:mushroom-chips-card ):
cards:
- type: custom:auto-entities
show_empty: false
card_param: chips
card:
type: custom:mushroom-chips-card
alignment: left
tap-action:
action: more-info
filter:
template: |
{% for entity in states.light if '_screen' not in entity.entity_id and entity.state == 'on' %}
{%- set name = state_attr(entity.entity_id, "friendly_name") -%}
{%- set name = name | regex_replace(find='Exterior ', replace='') -%}
{%- set name = name | regex_replace(find=' Light', replace='') -%}
{%- set name = name | regex_replace(find=' Mains', replace='') -%}
{%- set name = name | regex_replace(find='s 3x', replace='') -%}
{%- set name = name | regex_replace(find=' 1x', replace='') -%}
{%- set name = name | regex_replace(find='Family Room ', replace='') -%}
{{
{
'type': 'template',
'content_info': name,
'icon': 'mdi:lightbulb',
'icon_color': 'orange',
'content': name,
'entity': entity.entity_id
}
}},
{%- endfor %}
sort:
method: friendly_name
reverse: false
end result (at the top are the chips and names shorter/cleaner!):
The pattern in regex_replace can contain multiple strings.
{% for entity in states.light if '_screen' not in entity.entity_id and entity.state == 'on' %}
{%- set name = entity.name | regex_replace('Exterior|Family room| ?Light| ?Mains|s 3x| ?1x', '') | trim -%}
{{
{
'type': 'template',
'content_info': name,
'icon': 'mdi:lightbulb',
'icon_color': 'orange',
'content': name,
'entity': entity.entity_id
}
}},
{%- endfor %}
Copy-paste it into the Template Editor and confirm the generated names are correct. Let me know if it produces anything undesirable (like double spaces within the name) and I’ll adjust the regex pattern.