How to remove non-existing sensor?

Hi,
my HA shows sensor named sensor.bedroom_2_thermometer_battery as Unknown. I can’t delete it from UI because it gives me the blurb about not having unique something or other.

Thing is this sensor does not exist in any of the HA files apart from the database. Running

sudo grep -r "sensor.bedroom_2_thermometer_battery" .

only returns:

Binary file ./data/home-assistant_v2.db-wal matches
Binary file ./data/home-assistant_v2.db matches

Destroying the container, deleting the database then confirms the string does not exist within any of the files, however on recreating the container the sensor is still present and still only in the database files.

How can I find out where this entity comes from and more importantly delete it?

Try greping without the sensor. prefix, use the case insensitive mode and replace underscores with periods (regex for any character) so that names in configuration.yaml (that probably contain spaces instead of underscores) are matched, too:

sudo grep -r -i "bedroom.2.thermometer.battery" .
1 Like

Many thanks that was it!

./data/template.yaml:      - name: "bedroom 2 thermometer battery"

Have you searched inside /config/.storage? Possibly the non-existing sensor is inside /config/.storage/core.entity_registry.

However, be very CAREFUL when editing those hidden files as it can break Home Assistant from starting up.

Edit: too slow - problem solved.