When using physical hardware (e.g., a door-open sensor), it can (and will) break down. In that case, we replace it with a new one.
I don’t want to lose its history or have to change its reference in all the automations, dashboards, etc., in Home Assistant.
So I’d like an abstraction layer that can then be used everywhere. If a sensor is replaced, only the abstraction layer is affected?
How do I do this in HA?
Best regards
Installation method: Home Assistant OS
Core: 2026.5.1
Supervisor : 2026.05.0
Operating System : 17.3
Frontend : 20260429.3
The common way is to always use entities in automations etc. instead of device triggers, conditions or actions. When using entities, you specify the entity id in the automations. You can rename the entity id, so a replace is simply renaming the old entity to something else, and give the new one the old entity id. From then on all automations operate on the new entity.
Infortunately, someone thought it wise to start renaming history together with the entity id: before that happened the new entity inherited the old history. Sadly nowadays this is no longer the case.
There are suggestions that deleting the old entity and renaming without restarting HA will inherit history, but I have not seen that working yet.
Another, (though cumbersome) workaround is to create a group with one entity and act on that.
When using device triggers, conditions and actions, you are basically royally €#(%=/-#. If the device is gone, automations, scripts and scenes become broken and totally unreadable too. So this is why the cookbook has this article:
If you remove a device and then later add it with the same device name then typically you would end up with the same entity IDs and all is good.
Entity IDs are the abstraction you want, and thus it helps to name your devices what they control, not what the device is that is doing the controlling.
Probably the simplest solution of all is, just to put the sensor into a group (even if you only have one sensor).
Groups track their history, so if all you want is present or clear the group is good enough and you can replace or add multiple sensors later and the history will remain.