Checking configuration for non existent entities

I’ve just (!) discovered that if you put non existent entities in some parts of the configuration (in automations, sensor templates, recorder, history for example), the config checker will not raise any error…
And so, some of my automations where no more working because some of my entity’s names have changed in the past…

Is there a way to check all configuration files for non-existent entities?

No one?

I’m using HA for 2 years now and my config is quite big now…

There is no way. Get inventive, look at automations that haven’t fired in a while. Then search your config for the entity_id’s that are used. You’ll need a software that searches multiple files for a string, like notepad++ or visual studio code.

Paste this into the Template Editor and it will display a list of your sensors sorted by last_updated (reverse order; oldest is shown first).

{{ states.sensor | sort(attribute='last_updated', reverse=True) | join('\n\n ') }}

For other entities, such as binary_sensor, replace states.sensor with states.binary_sensor.

This will give you some insight into which entities haven’t been updated recently and may provide clues as to which ones are defunct (i.e. non-existent).

1 Like

My assumption was that these entities don’t even exist in the states page. I’m not sure if this will work.

That’s it, these entities don’t exist in the states page.

You can test this by renaming an entity in one of your automation and hit “check config”. Everything will be fine but your automation won’t work…

Another example, as I’m excluding/including a lot of entities in the history, recorder and logbook config, these lists are full of old entities.

Then try this:

{{ states.automation | sort(attribute='attributes.last_triggered') | join('\n\n ') }}

It will list your automations in order of last_triggered. If you have automations that triggered a very long time ago, it may indicate they are using a State Trigger for a non-existent entity.

Thank you @petro and @123 for your ideas.
I’ve managed to copy/paste/edit, select only lines starting with entity_id, remove duplicates, etc. Then got all my existing entities from the template editor and search for differences between both extracts. Then search in all yams files.
My configuration seems clean now (15 entities where non-existant).

Not as easy as using HA!

Strange that this doesn’t get more attention. I am having the same issue. Moving from deconz to zigbee2mqtt. Renaming my devices to a common standard.
Would love the have an utility for it.
I will need to go the same way and filter out all entities and see if there is a match.

hi,
may be, this could help …

1 Like

I may be wrong but there is a message logged now when an automation contains a non existent entity