My google-fu is failing me today. How do I customise the value of an entity in an entities list. I have a sensor, where the state can be living_room
and I want to display “Living room” as the value for that row in the entities list. I’m sure there’s an easy way to do that?
You’d have to make a template sensor using the existing sensor. Or use a frontend card that supports templates to do something similar.
… or use a custom:template-entity-row:
If this “nice friendly name” is used in many places - create template sensor (as Petro said).
If in one place only - a custom card might be enough.
Also, a dynamic friendly_name may be defined by Custom UI.
But then it may be used in UI only (i.e. on a client side, not in jinja templates executed on a server side) (also, even in UI it may not be used everywhere - for instance, Logbook card will not show these nice names).
Sorry, my fault - this is only about “friendly names”, not about “friendly states”.
Yes
Just answering a possible NEXT question “which card shall I use” ))
Thank you, everyone, for the quick replies. I decided to go with the template sensor, in this case. It’s more of a verbose solution than I anticipated, but it’ll do for a demo of ESPresense/Home Assistant integration, which is all I need right now. And I didn’t know about custom:template-entity-row, which might have been better…
I could have sworn I remember being able to put Jinja kind of things in-line in the actual visual editor, but I’m probably confusing this with Node Red.
Thanks again!
I marked both as a solution, because I was able to convert it to a template-entity-row easily, and that’s probably exactly what I need. I also pulled the logic out into a separate custom_template
, which makes it much more usable than the template sensor.
Thanks!
Only one post may be marked as a solution.
Since you chose a “template sensor” way - it is more fair to select this post as a solution.
Ah, I see! I thought I was able to mark both.
Well, in the end I did use a custom:template-entity-row
, so I’ll keep it that way. I ran off and implemented the template sensor first (after petro’s reply) and that did work, but I had to write a template sensor for each device. Then I came back, saw the other way, and implemented that instead, moving the duplicate logic to a custom_templates
module.
Either will work. It depends on the specifics.
Thank you!
That is why I do love HA - for alternatives.
Was searching for the same thing, found this: Templating - Home Assistant
{{ states("sun.sun") }} # below_horizon
{{ state_translated("sun.sun") }} # Below horizon
{{ "sun.sun" | state_translated }} # Below horizon