How to keep old energy statistics history when changing the main meter sensor?

I do not know how to solve this for past data. However, I solved it using template sensors that function as proxies or copies of the real sensors.
Consider for example my electricity consumption. The original sensor is called sensor.tasmota_mt175_bezug. With that I made a template sensor:

- name: "Stromzähler Bezug"
  unique_id: "strom_bezug"
  unit_of_measurement: "kWh"
  device_class: "energy"
  state_class: "total_increasing"
  availability: "{{ states('sensor.tasmota_mt175_bezug') | is_number }}"
  state: >-
    {{ float(states('sensor.tasmota_mt175_bezug')) }}

Now I can use that in my energy dashboard, feed it to a utility meter, or whatever. If the source sensor changes, I do not have to remove it from the energy dashboard. I just have to substitute the old sensor for the new one in that template sensor shown above.

I’d be happy to hear about better solutions though :slight_smile:

2 Likes