How do I recover when a sensor gets duplicated "somehow"

Note: this was initially posted in Third Party Addons with a different title. I moved it as it seemed to have wider relevance.

I use the EmonCMS integration to bring in a variety of home sensors. The physical sensors are OK and emonCMS is displaying them correctly, however the integration of one feed has changed without any manual intervention.

The sensors have been created using the following config

sensor:
  - platform: emoncms
    api_key: !secret opencms_api_key
    url: http://mycms.foo.bar
    id: 1
    unit_of_measurement: "°C"
    sensor_names:
      22: "Bedroom1 Temperature"
      24: "Livingroom Temperature"
      25: "External Temperature"
      33: "Bedroom2 Temperature"
      37: "Shack Temperature"

The mis-performing one is feed 25 “External Temperature”

When added initially, sensor.external_temperature was created as expected (the same for the others).

At some point in the last couple of days sensor.external_temperature became unavailable and a whole lot of automations broke. When I explored, I found a new sensor sensor.external_temperature_2 had been created and is now carrying feed 25.

Question: - How do I revert the configuration so the feed is back on sensor.external_temperature without losing the historical data?

Did you try deleting sensor.external_termperature then renaming sensor.external_termperature2 to sensor.external_termperature?

I did start down that track, but I can’t find a way to delete sensor.external_temperature. I didn’t create it using yaml, it was auto-created.

I would like to avoid this anyway because I’ll lose the historical data.

Maybe there’s a way you can export your historic data, delete then re-add the integration, and finally re-import the data. Unofrtunately how to actually to that is beyond me.

From searches on here, it appears that others have also reported problems deleting entities that weren’t created via yaml or the front end.

I know the data is there in one of the hidden config files, but I’m loath to edit them directly.