Change used energy calculation

I have a device on my energy meter which measures the total usage of my house.
Then I have a smart switch which measures the usage of one outlet.
Now is the case that in my energy dashboard both values are being added. But this is not correct because the smart switch usage is a part of the total usage. Is it possible to show this in the graph, like that the smart switch would have a different color inside the total usage bar?

You would have to subtract your smart plug energy from your total energy using a template sensor. You could then use the template sensor and your smart plug in the main energy graph.

Ah that sounds good. Didn’t even know that there was something like a template sensor. New to HA, I’ll try to google my way through it. Thanks!

Share the entity ids if you have trouble with it and we can help out.

My smart plug broke, so I had to wait for a new one.
Now my template sensor is showing up as an entity, but it’s not in the list when I try to add it to the energy dashboard. Do I need to add something to the template sensor so the energy dashboard knows that it can use that sensor too?

- sensor:
      - name: "Usage without smartplug kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state: >
          {% set x = states('sensor.smart_plug_electric_consumption_kwh') | float %}
          {% set y = states('sensor.cumulative_active_import') | float %}
          {{ y-x | round(0) }}

state_class: total_increasing

Thanks that did the trick. Now it says ‘statistics_not_defined’ probably because it has no data yet?
Is there a way to use the saved data from the ‘sensor.cumulative_active_import’ sensor I use? Because now I’ve lost all my previous data this way.

Yes it takes an hour or so for the stats to be generated.

No there is no import facility. However if you name the new device the same as the old one it will continue to use the old data.

Thanks I first renamed the current sensor to something else. And then I renamed my new template sensor to the same name. Now I still have my history!

I thought it worked, but I accidentally selected the renamed sensor. So in the end I still lost my history even though I gave it the same name in the template.