home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.73k stars 30.46k forks source link

"Cannot migrate history for entity_id ... because the new entity_id is already in use" #114559

Open choenig opened 6 months ago

choenig commented 6 months ago

The problem

When I rename an entity_id I (always) get the following WARNING:

2024-04-01 10:25:01.312 WARNING (Recorder) [homeassistant.components.recorder.entity_registry] Cannot migrate history for entity_id `sensor.fire_tablet_free_memory_2` to `sensor.fire_tablet_2_free_memory` because the new entity_id is already in use

I don't know, what is already in use means in this context, but from looking at the states_meta table I see that the new name now has the maximum metadata_id which definitely means that it has not been used in the states-table.

4184    sensor.fire_tablet_2_free_memory
sqlite> SELECT max(metadata_id) FROM "states_meta";
4184

When renaming entities in the past (via ui or via script), I always had the issue, that the history did not move along the new name, but was kept under the old name. Just now I started looking into it and saw the message in the log.

I don't know if this is a bug or has to do with my setup.

Looking at https://github.com/home-assistant/core/pull/89963 I could not determine a reason for this behaviour.

Any help or guidance is appreciated :)

br /christian

What version of Home Assistant Core has the issue?

core-2024.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

recorder

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-04-01 10:25:01.312 WARNING (Recorder) [homeassistant.components.recorder.entity_registry] Cannot migrate history for entity_id `sensor.fire_tablet_free_memory_2` to `sensor.fire_tablet_2_free_memory` because the new entity_id is already in use

Additional information

No response

choenig commented 6 months ago

In a development installation of homeassistant (docker, too) I just renamed an entity (shelly_plug_s_7ae92a_power_0_foo -> shelly_plug_s_7ae92a_power_0_foobar) with the same result. The debug log looks like:

2024-04-03 11:40:36.625 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event entity_registry_updated[L]: action=update, entity_id=sensor.shelly_plug_s_7ae92a_power_0_foobar, changes=entity_id=sensor.shelly_plug_s_7ae92a_power_0_foo, old_entity_id=sensor.shelly_plug_s_7ae92a_power_0_foo>
2024-04-03 11:40:36.627 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.shelly_plug_s_7ae92a_power_0_foobar, old_state=None, new_state=<state sensor.shelly_plug_s_7ae92a_power_0_foobar=4.45; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Shelly Plug S 7AE92A Power 0 @ 2024-04-03T11:40:36.627362+02:00>>
2024-04-03 11:40:36.628 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: <Event entity_registry_updated[L]: action=update, entity_id=sensor.shelly_plug_s_7ae92a_power_0_foobar, changes=entity_id=sensor.shelly_plug_s_7ae92a_power_0_foo, old_entity_id=sensor.shelly_plug_s_7ae92a_power_0_foo>
2024-04-03 11:40:36.630 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: <Event state_changed[L]: entity_id=sensor.shelly_plug_s_7ae92a_power_0_foobar, old_state=None, new_state=<state sensor.shelly_plug_s_7ae92a_power_0_foobar=4.45; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Shelly Plug S 7AE92A Power 0 @ 2024-04-03T11:40:36.627362+02:00>>
2024-04-03 11:40:36.632 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: UpdateStatisticsMetadataTask(statistic_id='sensor.shelly_plug_s_7ae92a_power_0_foo', new_statistic_id='sensor.shelly_plug_s_7ae92a_power_0_foobar', new_unit_of_measurement=<UndefinedType._singleton: 0>)
2024-04-03 11:40:36.666 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: UpdateStatesMetadataTask(entity_id='sensor.shelly_plug_s_7ae92a_power_0_foo', new_entity_id='sensor.shelly_plug_s_7ae92a_power_0_foobar')
2024-04-03 11:40:36.667 WARNING (Recorder) [homeassistant.components.recorder.entity_registry] Cannot migrate history for entity_id `sensor.shelly_plug_s_7ae92a_power_0_foo` to `sensor.shelly_plug_s_7ae92a_power_0_foobar` because the new entity_id is already in us

The above snippet is a grep for foobar with the websocket-logging removed.

ncd7 commented 6 months ago

Same.

MoontoC commented 6 months ago

mariadb & hass 2024.4., 2024.5., 2024.6.* Same.

choenig commented 5 months ago

Maybe @bdraco, the author of the original patch, has any idea what's causing this?

LucasCZE commented 4 months ago

I just encountered the same issue. HA 2024.5.5, Docker image.

gufri commented 4 months ago

Hi Guys,

I have a similiar issue with some Shelly Blu Motion Sensors: Logger: homeassistant.components.recorder.entity_registry Quelle: components/recorder/entity_registry.py:76 Integration: Recorder (Dokumentation, Probleme) Erstmals aufgetreten: 1. Juni 2024 um 17:29:51 (3 Vorkommnisse) Zuletzt protokolliert: 1. Juni 2024 um 17:29:51

Cannot migrate history for entity_id `sensor.sbmo_003z_142e_battery` to `sensor.bewegungsmelder_garage_battery` because the new entity_id is already in use
Cannot migrate history for entity_id `sensor.sbmo_003z_142e_illuminance` to `sensor.bewegungsmelder_garage_illuminance` because the new entity_id is already in use
Cannot migrate history for entity_id `binary_sensor.sbmo_003z_142e_motion` to `binary_sensor.bewegungsmelder_garage_motion` because the new entity_id is already in use

Had some issues with including the sensors and changed several times the names.

Anyone any idea? Thanks!

catsmanac commented 3 months ago

similar to #115747 !?

choenig commented 3 months ago

similar to #115747 !?

yep, duplicate siblings :)

catsmanac commented 3 months ago

Ok, now they are tight to the hip I guess.

issue-triage-workflows[bot] commented 2 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

jasoncodes commented 2 weeks ago

I can still reliably reproduce this on 2024.10.0 with the following steps:

  1. Create two helper entities in the UI named "test1" and "test2"
  2. Delete "test1"
  3. Change the Entity ID of "test2" to that of the deleted "test1"
  4. Observe warning in the logs.
  5. Delete "test2"

I’ve been following this issue for a while and ran into this bug only last week when replacing some YAML entities with entities via the UI. Definitely still an issue.