Automatically update Automations/Scripts when using "Show As" (Switch to Light)

Hi everyone,

With the recent amazing updates to Home Assistant, managing entities and changing their domain via the UI (like using the "Show As" feature to convert a switch to a light) has become incredibly easy.

However, there is still a major pain point when it comes to system maintenance: Broken Automations and Configurations.

Currently, when we change an entity's domain (from switch.my_device to light.my_device) or rename an Entity ID, any hardcoded references in automations, scripts, blueprints, dashboard cards, or Jinja templates are left unchanged. This breaks the logic, and in large smart homes with over 100 devices, finding and manually fixing every reference is tedious and prone to errors.

The Proposal: Dynamic System-Wide Refactoring

I would love to see a built-in "Refactoring" mechanism. When a user renames an Entity ID or changes its domain via "Show As":

  1. Automations & Scripts: HA should scan and automatically update the entity_id and, if applicable, upgrade the service call (e.g., changing switch.turn_on to light.turn_on if the target domain changed and a generic service wasn't used).
  2. Dashboards: Update card configurations to point to the new entity.
  3. Templates: A background parser (or a warning prompt) that catches references inside Jinja templates and suggests or applies the fix.

Why this matters:

This would elevate Home Assistant’s user experience to a professional level, making system tweaks entirely bulletproof. It ensures that changing how a device is displayed visually doesn't accidentally break core background logics.

Thanks for considering this!

2 Likes

Hi, feature requests have moved to Github discussions. They won't be seen here by the team.

But secondly, the Switch as X integration doesn't affect the original switch. So having a light entity as well does not break anything.

Renaming an entity id does. But this is how you replace a broken device with a new one while keeping automations, scripts etc intact. So while there may be merit in the idea, if you are careful about how you go about things, you can manage without refactoring.

The thing that makes everyone heasitant about system wide refactoring is the fact that not everything is done in the GUI. System wide refactoring would require automatic editing of user written files. This is both hard and very much unwanted by many people. That is why I think your chances of this happening are slim to none.

2 Likes

Would Spook get you where you need to be? It finds broken entities and points you at the automation with one click.

Install via HACS if you want to try it.

Ask here: home-assistant · Discussions · GitHub

Thanks @Edwin_D and @cambull for the detailed insights!

@Edwin_D, you make a very fair point about system-wide refactoring and user-written YAML files. I completely understand why editing user files automatically is risky and generally unwanted by the community. Also, the tip about keeping the Entity ID identical when replacing hardware is a great best practice that I will definitely adopt.

@cambull, I hadn't heard of Spook before! That sounds like exactly the kind of safety net I need for a larger setup to catch these orphan entities. I'll install it via HACS right away to help manage these transitions.

Appreciate the help, guys

2 Likes

I use spook too (is good at UI based things), in combination with Watchman, which does the same for yaml based files with regard to finding broken entities.