Get the current duration an entity is in a certain state

Hello,
Does anyone know I can get the time (duration) between two states from an entity?
I have a car charger and want tell how long the last charging session was.
I have an entity called “sensor.laddbox_status” that have the state ‘Charging’ when it charges.

I want to get the duration to be updated in realtime ( and not when the charge is over)
I tried history_stats with this code below but it seem to give me the after the charge has ended.

sensor:
  - platform: history_stats
    name: Laddbox charging time2
    entity_id: sensor.laddbox_status
    state: "Charging"
    type: time
    start: "{{ states.sensor.laddbox_status.last_updated - timedelta(minutes=1) }}"
    end: "{{ now() }}"