File sensors duplicate themselves on restart

I have a sensor that I feed into home assistant via json file. Unfortunately, every time I restart home assistant, a new sensor is created or duplicated. How can I fix this? I myself have already tried a lot but could not fix it so that it works


Look in Settings → Devices & Services. Your file sensor has been imported into the UI as that is where it is set up now.

Comment out your file sensor YAML and restart HA.

If after the restart the remaining sensor has _2 at the end you can rename it. However you will probably have to delete the “restored” sensor without the _2 from the Devices & Services → Entities list first.

Ok thanks, it worked. One more quick question, how can I add a device_class to the sensor? Because I get an error when I do this

I don’t think you can adjust the device class of an entity in the sensor domain from the UI. Normally the integration providing this would do it for you.

As long as your sensor has the correct unit of measurement you can use manual customisation. See:

I have now deleted the file sensors from config.yaml after they are in homeassistant. But it is now displayed:
“This entity is no longer provided by the integration file. If the entity is no longer used, delete it in the settings”. Or have I done something wrong?

Do you have the file sensor in Devices & Services?

If so, what is its entity id?

What is the entity_id of the missing sensor in your dashboard?

Did you remove the duplicate from Devices & Services → Entities?

yes i have removed the duplicate. the id is without _. But I don’t quite understand how I can get it to not duplicate. Do I have to delete them from the configuration after they are displayed in home assistant? Thanks for your help in advance

Now that you have removed the yaml and restarted there should be no more duplicates created.

Unfortunately, it is duplicated every time homeassistant is restarted. If I delete the sensors from the config, all duplicates are gone, but if I then enter the sensors in the yaml file, all duplicates are back +1 more due to the restart.

Stop doing that.

The sensor is set up from the UI now, you do not need to use YAML.

You are getting duplicates because you already have a sensor set up in the UI, it was imported for you when you updated. Like I said in my first post:

At the moment both UI and YAML file sensors work to give people time to change over to using the UI but in a few months the YAML version will be removed completely from the core and it will stop working and only generate errors if you try to use YAML.

Only use the UI to set up file sensors. Do not use YAML for file sensors any more.