Template sensor entity naming

Trying to use the ‘modern’ method for template sensors.

How do I get a sensor name without ‘template_’ stuck on the front … and get a nice friendly name for the entity to show on a card.

I’ve tried

template:
  - sensor:
      - unique_id: unique_id_10
        name: 'name 10'
        attributes:
          friendly_name: 'friendly name 10'
        state: >
          unique, name and friendly name 

Which
1) ignores the friendly name I defined and sets the attribute to 'name 10' 
2) a card shows entity with a name of 'name 10'
3) and entity_id of 'sensor.name_10'

Whereas
      - unique_id: unique_id_20
        attributes:
          friendly_name: 'friendly name 20'
        state: >
          unique and friendly name

Correctly gives the entity its friendly name on a card
But the entity_id is 'sensor.template_unique_id_20'

Running 2022.3.7 on a standard pi HA install.

The name becomes the sluggified entity_id and unique_id is for editing via the UI (as per the docs). If you don’t specify name you get a made-up one. There’s no friendly_name option for these sensors. You need to customise it.

@parautenbach , Clearly there is a ‘friendly_name’ option for these sensors as it works - as described in my second example. And whilst not explicitly listing ‘friendly_name’, the ability to add attributes to these sensors is in the docs.

As you say customise does seem the only, inelegant way, to achieve what should be allowed, imho, in the yaml definition of a sensor.

Clearly my item 1) is a bug.

Works in what way? Yes, you can add it, but the attributes section is just a generic (custom) dictionary of things. friendly_name has no special meaning here and it won’t be used automatically by anything. You can use it though for your own purposes.

If it was an option, it would be documented like this:

I have no opinion on its elegance. I use it just fine where needed. Do I agree that it’s inconsistent? Yes.

There are more opinions here: WTH don’t all integrations have a minimum set of standard options? - Month of “What the heck?!” - Home Assistant Community (home-assistant.io).

But to give my opinion: Friendly name is display purposes, and I’m in favour of splitting implementation from presentation, which is generally considered a best practice.

You might think it has no special meaning but the entities card likes it enough to replace the entity’s default name with the friendly_name I defined. lol

You can name it for display purposes in the entities card. Pretty much every card allows you to override the given name.

If you provide a name and a unique_id, the system will create the entity_id off the name. Then change the name to what you want in yaml and reload the template, the entity_id will remain the same, while the name will have an updated name.

The upshot is that you can’t define a desired object_id (like name_10) and desired friendly_name (that differs from the object_id, like friendly name 10) in one step; the process requires two steps.

1 Like

Or…just use the “old” template format and continue on as before when it worked as expected.

I dislike that we keep moving down the road to needing to make additional sensors or write more code to override decisions like these that make less sense than the original implementation.

as an example from the latest release:

image

I now need to create another sensor to be able to display an input_datetime in any semblance of a useful manner when the original display looked pretty close to the way the sensor I needed to make to fix it does now.

How can anyone think that input_datetime display format is OK? I mean, you can’t even see the entire year (which I think is important for a date entity) let alone the name of the thing you want to see.

And it’s WAY worse on my mobile device:

Completely useless…

Anyway…off-topic but related. Sorry.

1 Like

It’s a work in progress and the change to the cards fixed a ton of the “why can’t I theme XYZ in the UI”.

Good call…

Let’s hinder functionality to fix a “I want to create a pretty look” that ends up with less functionality and a terrible look as well.

What you don’t realize is that the datetime’s looked terrible on just about everything except chrome. Now it looks good just about everywhere.

desktop
image

mobile

FYI, those are unaltered base cards you see in those images I posted. Safari and chrome, with a normal theme.

it depends on your definition of “good” and “everywhere” is.

Obviously my results don’t look anything like the ones you posted.

Mine are too. nothing special. Chrome in an entities card.

Well, maybe you should look at your setup. What os are you running? What browser?

Windows 10 and Android 12

Chrome all the way down.

The controls start to look bad around 400 pixels or smaller in width. Are you zoomed in on your browser? Is your mobile device really old and is smaller than 400 pixels wide?

not at all.

Galaxy s21 Ultra

Well, something on your system (That’s viewing HA) is making the viewing window less than 400 pixels wide.

EDIT: If you figure out what that is, you could end up finding what the problem is.

I don’t think there is anything that I’m doing that would cause it since I’m just using standard views in Lovelace.

EDIT:

those screenshots are from 2 different machine (Windows and Android) with the same results so it’s not the device viewing HA that’s causing it.

And so am I, yet there are differences.