Friendly Name of State

Is there a way to pull the friendly name of a sensor state?

I tried the following:

state_attr("sensor.backyard_feeder_state", "friendly_name"

and got this:

but I’d like it to look like this:

I’d like to avoid doing a ton of elif statements with the number of possible states:

That’s the friendly name of the entity.

Use a dictionary to correlate the actual state with a “friendly” version…

{% set d = { 
'ready_to_stream': 'Ready', 
'online': 'Online', 
'deep_sleep': 'Sleep', 
} %}
{{ d.get( states('sensor.backyard_feeder_state') ) }}

Good old ChatGTP

Thanks! that looks like a great solution to start with.

Here is the completed code:

type: custom:mushroom-template-card
primary: Feeder
secondary: |-
  {% set status = { 
    'deep_sleep': 'Deep Sleep',
    'factory_reset': 'Factory Reset',
    'firmware_update': 'Firmware Update',
    'offline': 'Offline',
    'off_grid': 'Off Grid',
    'online': 'Online',
    'out_of_feeder': 'Out of Feeder',
    'pending_factory_reset': 'Pending Factory Reset',
    'pending_removal': 'Pending Removal',
    'ready_to_stream': 'Ready',
    'streaming': 'Streaming',
    'taking_postcards': 'Taking Postcards',
    'unknown': 'Unknown'
  } %}
  {{ status.get( states('sensor.backyard_feeder_state') ) }}
icon: mdi:bird
entity: sensor.backyard_feeder_state
layout: horizontal
  action: more-info
icon_color: |
  {% set color_map = {
    'deep_sleep': 'lightblue',
    'factory_reset': 'purple',
    'firmware_update': 'yellow',
    'offline': 'red',
    'off_grid': 'red',
    'online': 'green',
    'out_of_feeder': 'orange',
    'pending_factory_reset': 'pink',
    'pending_removal': 'pink',
    'ready_to_stream': 'green',
    'streaming': 'blue',
    'taking_postcards': 'orange',
    'unknown': 'grey'
  } %}
  {{ color_map.get(states('sensor.backyard_feeder_state'), 'grey') }}