I am measuring power and energy consumption in my home with a bunch of different ZigBee power clamps, accessed through zigbee2mqtt. I am using devices which have several different clamps, so I can’t give the device itself a meaningful name in zigbee2mqtt. For example, the device “powerclamp3” provides “sensor.powerclamp3_power_b” which happens to measure our garage, so I gave it a descriptive name.
But I now realized that this may cause a problem at some point in the future when I need to replace the device or simply rearrange which clamps measure what. What I need are stable aliases like “sensor.garage_power” which I can point to the current source of that information.
I suppose I can do that with a template sensor. Are there better ways?
Is there a way to configure the original sensor so that its values are not recorded in the long-term statistics? That would be duplication that I won’t need.
If I do this, is there a way to salvage past statistics such that I have statistics for “sensor.garage_power” even though I only now defined that alias?
Umm, why not simply change the original entity ID? If ever you need to change the hardware, change the entity ID on the new sensor to the same as the old sensor.
That works as long as I don’t change the type of devices, i.e. always replace a device with two clamps with another that also has two clamps. It won’t work if I consolidate e.g. three devices with two clamps each and replace them with two devices with three clamps each.
I can give “sensor.new_powerclamp_power_a” the same descriptive name as the “sensor.old_powerclamp_power_b” that it is replacing, but unless I am mistaken, I then won’t have old statistics under that descriptive name.
Umm, why? As already mentioned, you can change any entity id and/or name at any time. One sensor entity does not care how many clamps the device it belongs to may or may not have.
Entity ids and names are completely separate from device names. If they do match, HASS will offer to rename entities when changing device names, but this is in no way obligatory.
LTS will transfer, if you change entity_id. Unless there already is the LTS for the new entity_id, in which case it will not transfer. That way you can take over from the old sensor, if you replace it.
I tried this with a new powerclamp that I installed this morning, so no LTS for it yet. After renaming the ID, only data recorded after renaming gets reported. So whatever logic exists for LTS doesn’t seem to get applied to the recent statistics.
I may try it for my older sensors next, but not in my life HA installation…
I think the unique_id of the new entity will need to match the unique_id of the old entity.
Now I’m confused. This seems to contradict what was said earlier about replacing hardware (= leading to a different unique_id) and then renaming the entity IDs of that new hardware to match the old IDs.
LTS will transfer, if you change entity_id. Unless there already is the LTS for the new entity_id, in which case it will not transfer. That way you can take over from the old sensor, if you replace it.
I tried this with two entities, one from a MQTT device and the other an integration:
The LTS was available afterwards, but not the more recent history data. I suppose that’s fine because the LTS does cover the most recent time interval, it’s just less detailed.
I then tried renaming “sensor.herd_powerclamp_energy_renamed” to “sensor.dach_energy_renamed” after removing that entity (the “take over” scenario). That worked less well: clicking on the renamed entity brings up the popup with the history data of today of the former “sensor.dach_energy_renamed” (so that seems to have worked) but the history graph under “more details” lacks LTS data and doesn’t match the popup display.