Curious Spontaneous Sensor Creation

I have a sensor : -

  - platform: template
    sensors:
      s_ha_num_entities:
        friendly_name: Entities
        value_template: "{{ states | count }}"

When I have finished with any major additions/alterations to my code I run a template in the yaml editor to mop up and write yaml for ALL my entities.
Thus when I next add anything it shows up under “Unused Entities”
So last time I moped up and there were no “Unused Entities”
I modified a (different to the above) template sensor, then refresshed the UI : -
1 “Unused Entities” - sensor.s_ha_num_entities_2
Each time I reload template entities I get a new sensor with the underscore number incremented each time, I now have 6 of them and : -

{{ states('sensor.s_ha_num_entities') }}  --> 1063
{{ states('sensor.s_ha_num_entities_2') }}  --> 1064
{{ states('sensor.s_ha_num_entities_3') }}  --> 1065
{{ states('sensor.s_ha_num_entities_4') }}  --> 1066
{{ states('sensor.s_ha_num_entities_5') }}  --> 1067
{{ states('sensor.s_ha_num_entities_6') }}  --> 1201

Even Weirder, The actual Number of entities is 1191 (on a freshly started system) So none of the results are correct (but you’d expect the increment over the first 5)

Can anyone replicate this behaviour ?

Just off to restart my system
:rofl:

HassOS on a NUC latest release core-2021.4.5, supervisor-2021.04.0, Home Assistant OS 5.13

Well…yes I can confirm that I see the same behavior as you are.

I created the exact template sensor that you did and every time I reload templates it adds another sensor with the entity_id incremented.

so I figured it was somehow keeping the old entity_id locked up somewhere in the registry and all that was needed was to go to the “entities” are and delete the other ones there. But you can’t. :frowning_face: It says that it “…can’t be managed from the UI…”.

However, luckily a server restart seems to do the trick. After that the only sensor left is the original one. All the other “_x” iterations are gone.

It’s strange that it does that for only that form of template sensor. I’ve never seen it on any others.

looks like it’s time for a bug report.