Handling entities created by cloud services

I have this annoying problem with entities created by third party cloud services like Tuya. For example, they might create a switch that shows up in HA named switch.wp2_lowerbath_socket_1 which means absolutely nothing to me. So I would use HA to change that to something meaningful like switch.air_filter_motor. Now I use that in automations, scripts, etc and life is fine.

Until, for some reason that I lose the Tuya integration and have to reinstall it. Now my renamed entity points to nothing. How do you handle situations like this? Do you simply keep a document which details your entities you renamed them, so when you have to reload them you know what needs to be renamed?

For all entities I edit the name.

light.Zwavelight >> light.bedroom

media_player.rokuxxx >> media_player.roku_livingroom

Automation and UI don’t care about backend changes they just use the entity specified so my naming allows device swaps or complete rebuilds with only requirement being that I properly name entity

If done properly the entity_name properly sets name

Light.bedroom is “Bedroom” with light icon by default. If I prefer “Bedroom Light” entity name is light.bedroom_light.

In case of Zwave, naming “Bedroom Light” in Zwave_js creates enitity light.bedroom_light with name “Bedroom Light” in HA when integration added to HA. Similar is true for many 3rd party integrations. Naming device in the 3rd party software create a similar name in HA.

  • In the end, decide on a naming structure you want in HA
  • Name devices in their originating software/app/cloud
  • Correct entity in HA as needed

Been there. Not just Tuya either.

Haven’t found “the definitive solution”.

Have considered making template entities for important devices that I use in automation triggers. I have this for some. Not only for this issue. But because I replace devices a lot since I like to experiment.

Maybe it would be helpful to create a list of renamed entities somewhere, and then check to see if each one exists?

orig: remapped

switch.tuya_xxx_socket_1: switch.my_socket_1
switch.tuya_xxx_socket_2: switch.my_socket_2

Iterate thru the list and check to see if the remapped name exists?

What I’d really like to do is to be able to remap these devices with a script. If you can rename/remap an entity in the GUI, you should be able to do this in code. @firstof9 @raman325 do you think this is doable? You’ve worked in this area before. We would need some script like:

EntityRename(orig, renamed)

There’s nothing available to rename entities via an automation or script, and I highly doubt the core team would allow it with the argument that entity renaming should be a one time action. What do you mean by losing Tuya? Like the integration stops working and you have to readd it to resolve? That sounds like a bug to me and something worth posting an issue about. With the reauth flow an integration can prompt you to e.g provide a new set of login credentials

Let’s say I have to rebuild my system and manually copy over scripts, etc. I have to also reinstall Tuya, so my automations that use renamed devices are pointing to null. Having to manually use the GUI to fix this works, but dumping in a mapping file would be better.

Why would you rebuild your system from scratch? If you copy your config folder over and include the .storage folder, you’ll get everything from your existing system back as if nothing changed. HA isn’t like an operating system where the system accumulates cruft under the hood and a clean reinstallation fixes issues, so there’s no harm in taking this approach as any problems you may face based on your configuration would be related to a particular integration and removing it would resolve the issue.

It happens more often than you think. Especially when I’m setting up VMs for people and want to test them in my setup. But my point still stands, I’m not the only person who wishes there were a simple way to rename entities using an input file instead of using the tortured GUI approach. Heck, I would be happy with using the GUI if you could upload a file or cut and pasted some yaml.

@crlogic @raman325 I went ahead and created a feature request.

Voted :+1:

Having the same problem with Tuya when I needed to extend my trial. No the language switched from all my 129 entities. Not sure why home assistent is using names as all my tuya deviced have aan unique “Device Id” in the IoT platform.