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:
![image](https://community-assets.home-assistant.io/original/4X/f/5/1/f51498a7caa9fd1356296ed74dbcab46ffdb847d.png)
but I’d like it to look like this:
![image](https://community-assets.home-assistant.io/original/4X/c/2/2/c22c38e1bc24ab85e510f77116ca932765882d3f.png)
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') ) }}
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
tap_action:
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') }}