Template sensors are still there after they are being removed

I created a number of template sensors in the new template format:

template:
  - sensor:
    - name: <sensor name>
      state: 
         {{ states("<other sensor name>") }}

Because I don’t need those sensors anymore I’ve removed the sensors from the yaml file.
After a restart of HA the template sensors are still there and I cannot delete them from the GUI. Probably because they don’t have a unique id.
Also those sensors can’t be found in the files in the .storage directory.
How to delete those sensors?
I’m using the latest version of HA 2022.6.6

Nope, if they don’t have a unique_id and you delete them from yaml, they will be removed.

Because they will only be in the registry if you supply a unique_id.

Remove them from yaml. You have them somewhere else in your yaml and you didn’t actually remove them.

They are not in the yaml anymore. That’s the strange thing. If I search in all files in the /config I don’t find those sensors not in the yaml and also not in the .storage folder
It seems something has changed. Normally in the past those sensors where indeed removed if you remove them from the yaml files.

I had the same problem with a template sensor a few weeks ago. It was just there. I actually decided to let it be, however could not😁

Solution was to use purge.entities from developer tools.

Agree, it should be gone, and normally they are. There must be some special cases where it “lives” in the history/recorder.

Those 10 sensors start with “asn_”.

If I search for “asn_” in all files in /config I get:

image

With purge entities you mean with the service “Recorder: Purge Entities”?

1 Like

Yes, and chose the entity.

I tried to purge only one template sensor with the service “Recorder: Purge Entities" and now all 10 template sensors are gone. Very strange. There is definitely wrong behaviour!
But anyway my problem is being solved!

1 Like

I have the same problem but purge entities doesn’t remove it! This is driving me crazy!
Should the purge work instantly, or over time?

4 Likes

I am also having this issue. I had several sensor templates I want to remove and turn into template sensors. I have cleared them from my sensor.yaml file, restarted HA but they are still there. I have used recorder.purge_entities but they don’t seem to be going away.

Actually, it looks like they have now gone. I used the Developer Tools → Services. Then called the recorder.purge_entities and selected the entity sensors to remove. After 5 minutes I restarted HA and they were gone. Not sure if this is the correct process or not, but it seems to have worked…

I also have this problem. I removed two template sensors from the template.yaml & noticed the entities still existed. So, tried to delete them but, as no unique id, can’t.
Then I ran the purge entities service, checked that all history had been deleted & restarted HA (multiple times). I had also checked that there were no related items & that no other references to the sensors remained in the template.yaml

However, the entities still persist. Fyi, both still have state values (‘enabled’ ; they were template sensors that converted the ‘on/off’ state of a switch to text ‘enabled/disabled’) but, of course, they are not updating.

Anyone have other suggestions ? I guess it’s not a big issue (just 2 entities) but it’s annoying.

The entities are referenced somewhere. Check everywhere in your config.

I understand where you’re coming from - but I’ve searched thoroughly through the UI. I’ve also searched through core.config_entities & core.entity_registry (in .storage) - nothing.

Looking further just now, found both in .storage/homeassistant.exposed_entities. So, went back to the UI and again looked through the Voice Assistant exposed entities and they are not there.

Is there somewhere else to look? I assume directly editing the ha.exposed_entities file isn’t a good idea (& would that fix it anyway?).

Yes, look in configuration.yaml and all included files referenced in configuration.yaml.

A quick and easy way to do this is use a find in files function. Notepad++ and VSCode both have the ability to do this.

Sorry, perhaps I wasn’t sufficiently explicit - 1st thing I did after noticing they were still listed in developer tools states was to search all yamls (config, automation, templates, etc etc - all of them, with a txt editor & through VS code) - nothing. Also, as previously noted, HA reports the entity as having no related items.

Right, but are you manually doing that? I.e. going to each file and just using the find function? Or are you using a find in files function that points at your config folder?

If the entity does not exist in any file in your config folder, it’s in your database. Lastly, it could also just show up in your browser cache.

lastly, keep in mind that VSCode addon ignores the .storage folder. So you’ll have to manually open the storage folder via “open folder”, then do your find in files there.