Automations: every time an entity/device is deleted leaving an automation that contained it now broken, warn the user

Fictitious Scenario:
Added a smart door lock (lock.front_door), created an automation that notifies me that the door has been left unlocked when I left my home zone, in addition to this, it turns a lamp in the lounge red, so that when other people in the house arrive, they know the door was left unlocked. Two weeks later, the lock dies so I install a dumb lock and delete the integration from HA.

What happens now: nothing happens. The automation just sits there being broken, cluttering the UI, and because I have 120+ automations it’s a nightmare to find it. Because the integration/device has been removed, I also cannot use the filter by device/entity or go to the device on the integrations page and see the automation linked (because the integration page for the device doesn’t exist, since I removed the device when the integration was deleted). As you add/remove/replace smart devices, your automations can soon stop working. Since automations are supposed to make life “set and forget”, sometimes you don’t realize it. Actually this happened to me - my zigbee relay lost connection to my ZHA stick, so my bathroom extractor fan was running 24/7. It was only meant to turn on when the bathroom lights were on, I just never noticed until a month later because I walked by and heard the faint noise while the lights were off. All this time, it was wasting electricity. If I had a notification to let me know that an automation could not run for X reason, I could’ve investigated. Having to check logs is not user-friendly. HA should proactively warn me. If someone would find this bothersome, make it optional with a toggle “warn when notifications cannot run”.

What I propose:

  1. HA should keep track of changes in automations. Whenever an automation is affected by any entity that was included in the automation, be it a trigger, conditional, or action, whether it was amended or removed, it should notify me. Put a notification on the sidebar along the lines of [Your automation “Door - reminder you forgot to close it” has been changed. Entity lock.XYZ was removed"] with an action button to [Delete automation] or [Amend Automation].

  2. Have a filter on the Automations section of Settings titled something like “Show broken automations with unavailable/missing devices”. Since the automations UI is now based on “cards” for each trigger, condition, or action, highlight with a red border which “card” represents the missing/unavailable entity so the person can quickly see what is missing to make it work again. Since HA was keeping track of it, also show the name of the entity that was previously there. Right now, using the fictitious example above, previously it was “lock.front_door” but now it shows an empty field/unknown. It would be useful to know what was there because sometimes when you create an automation, you have an idea of how to make it work but it depends on what entity you used, if you lose this detail (when the entity is deleted) then it might be difficult to remember what should be there.

even just a readout to list them all. I’ve been slowly catching the lingering bad entities in the logs.

I use the watchman custom component in order to list all missing or currently unavailable entities and services.

So, the right way to do i is go to the device page in configuration where you can see what scrips, scenes and automations use the device before you delete. They are not hard to find.

And for those who are not afraid of YAML: a quick search through the automations.yaml, scripts.yaml and scenes.yaml will find them all quite easily too.

And watchman is indeed great if you didn’t check beforehand.