Skip to content

Correct statistic history for _trip_total_ entities #311

@virtualdj

Description

@virtualdj

Brief description

I think every entity that has _last_trip_total_ in its name should also set the last_reset attribute to let Home Assistant calculate a proper "total" statistic.

Breakdown

While I was exporting my last trip sensor data from Home Assistant, I notied something weird.
This is an example:

statistic_id	unit	start	sum	state	delta
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 12:00	0.171	1.476	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 13:00	0.171	1.476	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 14:00	0.171	1.476	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 15:00	0.171	1.476	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 16:00	-0.495	0.81	-0.666
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 17:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 18:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 19:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 20:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 21:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 22:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	07.01.2026 23:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 00:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 01:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 02:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 03:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 04:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 05:00	-0.495	0.81	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 06:00	0.225	1.53	0.72
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 07:00	0.225	1.53	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 08:00	0.225	1.53	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 09:00	0.225	1.53	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 10:00	0.225	1.53	0
sensor.golf_last_trip_total_electric_consumption	kWh	08.01.2026 11:00	0.225	1.53	0

While the chart is correct (notice the second to last column, state, that corresponds to the chart values):

History stats

I don't think the data above is, too! The third to last column is the sum and I don't think it is correct to have a negative number (-0.495) as I've not produced energy. The delta is wrong indeed.

The problem is that the VW backend provides the last trip data only when it has finished, i.e. it is not a real energy counter. According to the Home Assistant documentation here and here, I think that last_trip_total_xxx_consumption sensors should also set the last_reset attribute when their state value has changed. This should hopefully provide a proper statistics data, while the chart values should not change. What do you think?

Long-term & refuel totals

This certainly does not apply to the longterm_trip_total_ and refuel_trip_total_ sensors, because they reset within a larger period. However, from the examples of the HA documentation, probably they should be set to total_increasing instead to sum the delta when they reset to 0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions