Calculate delta of the last 5 minutes for a sensor

I’d like to calculate the odo diff of my vehicle for the last 5 minutes.
For this I am using the statistics platform.

This is the source sensor for a test trip with a 5 minute window marked in orange:

in the orange section odo diff is about 7km

This is the result of the statistics sensor - it only reports 1:

This is the yaml for the sensor. There must be something wrong with it.

- platform: statistics
  name: "Strecke diff 5min"
  entity_id: sensor.vehicle_odo
  state_characteristic: change
  max_age:
    minutes: 5
  sampling_size: 2
  precision: 1

You are going to have more than 2 samples in 5 minutes. Make the sample size sufficiently large to account for the maximum number of samples you get in 5 minutes. There is a buffer fill ratio attribute of the sensor you can check. You want this to be close to 1 (100%) but never actually reaching 1.

So I’d have to set sampling_size to 15, when I assume the car is capable of going 180km/h?
That would be 180 / 60 * 5 = 15. Unfortunately I don’t get fractions of kilometers reported.

edit: is there another way to calculate such delta values?

1 Like