piitaya / lovelace-mushroom

Build a beautiful Home Assistant dashboard easily
Apache License 2.0
3.5k stars 328 forks source link

[Feature]: Get entity values such as name or icon in Template card #1029

Open ov1d1u opened 1 year ago

ov1d1u commented 1 year ago

Requirements

Is your feature request related to a problem?

I know that I could use {{ state_attr('switch.entity_id', 'icon') }} for icon in a template card, but this requires a request to the HA backend (which causes some rendering issues) and it doesn't return an icon reflecting the current state of the entity. It would be nice to directly reference the entity icon (and other things, such the entity's name) in the template card fields.

Describe the solution you'd like

I'm not sure how the best solution would look here. I made an implementation here for my personal use which detects if the icon value is not a template and contains a . (dot) and if it does, it uses stateIcon with that value. I know it is a stupid solution (I just discovered this project yesterday so I'm not really experienced with the code) so something better needs to be designed. I'm not primarily a TypeScript developer, but I'm willing to contribute with a solution.

Describe alternatives you've considered

No response

Additional context

No response

BBE-FR commented 1 year ago

I have an issue that is very close, trying to built a weather mushroom card using either entity or template card (I want it bigger that the wonderful weather chip...)

8jmm3 commented 1 year ago

This would be a great feature as I also frequently find myself resorting to using icon: "{{ state_attr(entity, 'icon') }}". I find that this doesn't always work though as some entities don't appear to expose an icon attribute. In particular I'm having problems with a weather entity. It would be great if the card could behave more like the Mushroom Entity card when not using a template value.

Along the same lines, I have trouble with the entity state using the Template card, again with a weather entity. If I have something like secondary: {{ states(entity) }} it might display partlycloudy rather than Partly Cloudy, as it would appear using the Mushroom Entity card.

For the icon, options I can think of might include:

Do something similar for the primary: and secondary: values: