Template sensors are still there after they are being removed

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.

Individual files - I’m limited atm to browser access to the files (with no ‘find in file’ function) but it’s not that complex.

You said you used VSCode addon though?

… and they have gone!

Thought I’d check before forcing a browser cache refresh and the entities are no longer listed. I’ve done nothing - no restart, nothing edited, nothing deleted.

Only thing I can think of is it’s just over 24 hours since the history was purged. Timing?

(I don’t use vs code through my Android tablet, just on a pc which is remote to me atm)

Thanks for taking the time to assist - appreciated.

Same problem here. Experimented with some sensors in a template.yaml (without unique ids), now got it working with slightly other entity-names, but although the old senors are not mentioned anymore in the template.yaml, they still persist - well, at least somehow they do: I found them for example in the energy-dashboard in a dropdown-box when configuring a gasmeter. But: They are neither available in the entities tab nor when using “Recorder: Purge Entities" and selecting an entity nor in a new automation. Strange.

So I tried:

  • Restarting HA
  • Browser cache cleared
  • Entities tab: Not found there (even looking for hidden and disabled entities, too)
  • “Recorder: Purge Entities": I couldn’t select these sensors, they are just not appearing in the dropdown-box there. I entered them manually in YAML-mode and called the service, got a green checkmark, but they are still there. No errors in the logs.
  • Search all files in /config/ for the name of the entities → Found nothing. I tested that the files in .storage are searched as well.

It’s been a week since I removed the sensors from my template.yaml.

Any other ideas?

There’s nothing else it would be. If you waited a week, wait 3 more days.

[edited to reflect new knowledge that long term statistics never deletes temperature and energy in particular]

Experiencing the same behavior - moving some template sensors to the GUI as helpers, but they persist over reboots. Thought I was going crazy and found this thread.

I had done two batches of moving, and the first batch all worked great. Delete from config, restart, add as helpers (sometimes having to delete the old entity).

Four sensors didn’t behave well, and they are either energy or temperature. So I wonder if this is related to a reference from the energy dashboard, statistics, or something.

All are found in:
.storage/homeassistant.exposed_entities

And the two energy ones are also referenced in
.storage/energy: "stat_consumption"

Purging the entities ALMOST did fix it for me, but I suspect that some folks don’t wait long enough for the purge to finish - if you keep a lot of data, it would take a while…then the entities will be gone from most parts of the UI.

But in the end, while I couldn’t search out the entity in the developer state console, my old references to the entity in a dashboard still worked (stuck on the last value).

I used to think I had a way to handle better, but I can’t think of one, since I understand the challenge of the long term statistics - don’t want 2 years of history to drop over a typo.

Digging up this old post since I had the same issue and maybe found a solution.

So I did everything stated above (searched files, purged the entity). What helped in the end was to delete the helper through the UI (no, it was not originally defined via UI). Going to the settings of the helper in UI and hitting delete, removed the entity once and for all.

Hope that helps somebody…

1 Like

Solution for my case:
Problem

  • I deleted the entries in config.yaml, but the template sensors remained (for several month), even after above mentioned pruges. The sensors were shown in UI “Helpers”, the entity-id was empty.
  • I could not delete these entities in UI, because no delete button was shown.

My Workaround:

  • I could add a device to these sensors in the UI (I did use a speaker).
  • I opened the device in settings/device, where on this speaker I had a link for the template integration. There I could access the context action delete on these template sensors.