Using one energy sensor with multiple energy meters

Hi,
i have a strange problem that i’m not able to understand.

What i need?

  • I have two Tesla EV cars and one WallBox. I installed a shelly energy meter to monitor the power draw by the wallbox itself.
    I need to increase two energy meter entities based on the power draw from the wallbox but also taking in consideration what car is charging.
    The result need to be that i can have a overview of the power condumed (KWh) by the Tesla A and by the Tesla B.

What i have done?

To solve this problem i created two template sensor the give as output 0 when the car is not charging and the original sensor value when the respective car is charging.
Here an exemple of of the two “Car Sensor Template”

      consumo_wallbox_andrea:
        friendly_name: Consumo Wallbox Andrea
        unit_of_measurement: "W"
        value_template: >-
          {% if is_state('binary_sensor.tesla_wall_connector_vehicle_connected', 'on') and is_state('binary_sensor.tesla_andrea_charger', 'on') and is_state('binary_sensor.tesla_marco_charger', 'off') %}
            {{ states.sensor.consumo_energetico_wallbox.state }}
          {% else %}
            0
          {% endif %}
        icon_template: mdi:ev-station

After that i feed this two sensor to the platform “integration” sensor to convert this value to KWh.

  - platform: integration
    source: sensor.consumo_wallbox_andrea
    name: Consumo Wallbox Andrea kWh
    unit_prefix: k
    round: 2

The “integratrion sensor” is then used in the utility_meter entity.

utility_meter:
  kwh_wallbox_andrea_totale:
    name: kWh Wallbox Andrea Totale
    source: sensor.consumo_wallbox_andrea_kwh

Whats the problem?

Overall the system is kind of working as aspected but i have this strange behavior.
The current KWh value jumps all the way up as soon as the rispective car start charging and then, after this jump, the meter is counting correctly.

I was not able to find a solution and even a explanation to this issue…

Thanks