I’m trying to migrate some of my legacy type template sensors towards the newer modern style, and whilst it’s mostly working, I need a little help with fine-tuning.
That takes the device_tracker.darren_desktop entity’s state and creates a second sensor sensor.track_darren_desktop with the templated value and icon (to make it look clearer and nicer under a Lovelace card). The name appearing in the card is “Darren’s Desktop”, as per the friendly name.
Anyway I’ve got something close working under the modern style:
Which works as well, except the sensor name is sensor.darren_s_desktop and so different to the above.
What I’d like to have is the original sensor name (sensor.track_darren_desktop) and the Lovelace name as “Darren’s Desktop”. I know I can go into the entity under the GUI and change both entity ID and name to those, but I’d prefer to do it from the original configuration if possible.
Can it be done, or am I forced to create the sensors with their name and entity ID as the same and then tweak one or both in the GUI?
Or change your name to Track Darren Desktop, and then in the UI change the name to Darren’s Desktop. Or remove the name, and add the name in your customization area.
Thanks. I was wondering if there was a way to avoid having to do the UI tweaks (this is one example of a few dozen sensors used to track various devices) by fine-tuning the yaml file entry for them.
The legacy has the ID and the friendly name as distinct properties, but modern seems to use the name for both (I can’t see the unique_id actually doing anything except under the hood).
Understood. The “under the hood” bit was that HA is using it to follow it and enable changes via the UI.
So the basic answer is no, I can’t preset everything in the yaml file entry for the template and I need to edit at least one of the properties via the UI.
Fine with that (albeit some work), but wanted to ensure I hadn’t missed something as this is the first time I’m playing with the new modern way of doing them.
This won’t provide exactly what you want but I am posting it here for future reference. The result of this will be sensor.template_track_darren_desktop whose friendly_name is “Darren’s Desktop” (assuming I configured the quotes correctly).
Hmm. I have a vague recollection of trying that and it wasn’t successful but now I am uncertain. The documentation indicates it expects a template. I’ll try again when I have access to my system.
No, that’s done automatically by Home Assistant when it builds the sensor’s object_id and there’s no name defined.
It’s why I made the disclaimer that it wouldn’t give you exactly what you wanted; its just for reference purposes, mostly to show how friendly_name can be set in the sensor’s configuration. However, only if there is no name option present otherwise Home Assistant will default to using that for friendly_name. See the linked post to learn about how it behaves when various options (unique_id, name) are included/excluded.
Reconfigure all automations etc that use the sensors to the new template_ version.
Use the UI to change the object_id for each of the sensors and strip out the template_ (which is what I was trying to avoid in the first place).
Give up and go back to the legacy set-up, which works out of the box exactly as I want it to.
Any idea what the reasoning is for the automatic addition, as it’s somewhat frustrating. Is there a specific reason that it needs to be done differently in the two routes, as it seems to me that the “modern” version is less flexible than the legacy one?
Thanks for the help so far anyway. I think I’ll roll back to the legacy method at least for now, and will consider the best way of the other two for the future.
As you say, hopefully someone can cast light on why the prefix is being enforced on the id, as it seems very undesirable to me from the user viewpoint and will end up as a similar roadblock in the future if the legacy method is depreciated and later removed.
OK, got it doing what I wanted by using the customization section and letting that handle the friendly name. No unwanted Template_ in the sensor ID, and everything’s working fine.
Seems an oddity that I have to customise a sensor that I just created, but at least it’s working without having to manually tweak anything in the UI.
One note though, it does seem to work with name in the original template, the customize overrides it fine.
Will call this one completed, as a learning experience. Thanks again for the support chaps
That’s a slight edit as I’m using separate files for the customisation and templates (via !include in configuration.yaml), so I’ve sewn everything together for the above example.