Current power from total energy

Hi,
I have an EV and installed a charge pole. I only find a sensor of the charge pole that gives the total energy charged into the EV. I wanted to calculate the charge power by using a derivative helper:

template:
  - trigger:
      - platform: time_pattern
        seconds: "/10"
    sensor:
      - name: "EVAC Laadvermogen Actief"
        unique_id: evac_laadvermogen_actief
        unit_of_measurement: "kW" # Vul "W" in als je derivative al in Watts is
        device_class: power
        state_class: measurement
        state: >
          {% set s = states.sensor.evac_geladen_energie_kwh %}
          {% if s is defined and s is not none and s.last_updated is not none %}
            {% set age = (now() - s.last_updated).total_seconds() %}
            {% if age < 120 %}
              {{ states('sensor.evac_laadvermogen_derivative') | float(0) | round(1) }}
            {% else %}
              0.0
            {% endif %}
          {% else %}
            0.0
          {% endif %}

The calculation is not correct since it always shows 0 W.

Can someone help me out?

Tx/Alain

I had the same “always 0” headache when I built a charging-power sensor from my charge point’s total energy reading, and in my case the entity id in the template didn’t exactly match the real sensor — double-check the exact entity_id in Developer Tools > States, because a mismatch silently falls through to your 0.0 branch.

I’d also sanity-check the derivative helper itself first: point it directly at the total energy sensor with the time unit set to hours so kWh becomes kW, and put it on a dashboard card to confirm it produces live values before adding the age guard back. Once I did that, mine tracked the charger within a watt or two.