Rename entity WITHOUT keeping history, but keep history attached to old entity?

So, I’ve learned that back in 2023, HA added the behavior of renaming the history to follow the renaming of a sensor entity.

This is normally what I want, however I’m now in an interesting situation - I do NOT want the history to follow renaming an entity - basically I actually want the old behavior just this once.

The scenario: I used a smart plug all winter to track my steam humidifier’s energy usage. I want to retain that usage in my database so that I can start adding to it next winter (e.g. the total kWh used, when it was on/off, etc.) However, I want to repurpose the smart plug for a new purpose during the summer (a large tower fan).

So, let’s assume that I have “sensor.humidifier_power” (watts) and “sensor.humidifier_summation_delivered” (total kWh). I also have “switch.humidifier” which should contain the history for when the humidifier was on or off.

I now want to rename the smart plug to, say, “switch.towerfan”, and its other entities along with it. But I do NOT want the history to follow.

Later on, next winter, I might use the same plug again for the humidifier, or I might have a new smart plug, or maybe an in-wall energy monitoring plug, or who knows what. But at that time I’d like to rename whatever entity that ends up being to “switch.humidifier” and so on, and have it pick up the history for the humidifier where it left off.

I’ve read about templates, but this seems to just link to the original entity - the usage of the fan would still get associated with the humidifier’s data. I might be able to do an ugly hack with some kind of conditional filtering, but that seems very kludgy and hacky at best. Basically, I just want my smart plug to get a new ID and new history stream, but have the ability to reconnect it back to its old history stream in the future (and back again to the new stream later than that).

I can’t just reset the pairing for the Zigbee switch, because it just auto-reassociates with its existing entities. I do know that you can delete an entity, setup a new one and rename it to the old entity and it should pick up the history in that case, but I don’t know if this works when I’m using the same plug (i.e. I’m not doing a replacement, I’m doing a repurposing).

Ideally, it’d be great if there was a checkbox “migrate history” when renaming an entity, but until something like that gets implemented if it ever does, is there a way to accomplish this? I’m OK with editing the database directly if I have to, but I don’t want to just go “poking around” in there without having some understanding of what I need to rename. I’ve read about “metadata_id”, which might suggest that simply renaming the entity in the database won’t actually create a whole new history stream.

While I don’t want to speak on behalf of the devs, this is such a niche use case that I’m not sure it’s worth developing and debugging code and forcing the entire rest of the user base to have to check yet another box.

Better bet for you is to simply leave that plug where it is and spend $9 on another one.

1 Like