Statistics graph card doesn't show expected values

I followed this great post to calculate the cost of one of my device, based on accumulated wattage and price for that time. I compared the entities numbers to what my power measuring device (a Shelly 3EM) reports, and the numbers are in-line. But the Statistics graph card is not showing the right values.

See my graph here:

chart_type: bar
period: hour
type: statistics-graph
entities:
  - sensor.jacuzzi_cost_in_sek_per_hour
stat_types:
  - max
title: Jacuzzi cost per hour
days_to_show: 1

If I go to the details of my entity I get the following (correct behavior, the 13:00-13:59 cost is around 0.91):


,
After exporting the data, I can see that the entity numbers are correct and they reset every hour, as expected at xx:00:00:

sensor.jacuzzi_cost_in_sek_per_hour,3.405043,2025-02-04T10:59:42.353Z
sensor.jacuzzi_cost_in_sek_per_hour,**3.421137**,2025-02-04T10:59:54.333Z
sensor.jacuzzi_cost_in_sek_per_hour,0.0,2025-02-04T11:00:00.033Z
sensor.jacuzzi_cost_in_sek_per_hour,0.020969,2025-02-04T11:00:09.336Z
...
sensor.jacuzzi_cost_in_sek_per_hour,4.558339,2025-02-04T11:59:17.061Z
sensor.jacuzzi_cost_in_sek_per_hour,**4.576615**,2025-02-04T11:59:31.430Z
sensor.jacuzzi_cost_in_sek_per_hour,0.0,2025-02-04T12:00:00.014Z
sensor.jacuzzi_cost_in_sek_per_hour,0.039598,2025-02-04T12:00:01.473Z
....
sensor.jacuzzi_cost_in_sek_per_hour,0.944552,2025-02-04T12:59:31.373Z
sensor.jacuzzi_cost_in_sek_per_hour,**0.945888**,2025-02-04T12:59:46.389Z
sensor.jacuzzi_cost_in_sek_per_hour,0.0,2025-02-04T13:00:00.031Z
sensor.jacuzzi_cost_in_sek_per_hour,0.002672,2025-02-04T13:00:01.410Z

The actual values from my Shelly:
|11:00|3.42|
|12:00|4.59|
|13:00|0.91|
|14:00|1.04|

So 11:00 and 12:00 are correct, with respectivly 3.42 and 4.59(~4.57) SEK, but then you can see in the statistics graph that 13:00 and 15:00 are showing up the same number as the prebious hour. Same thing the previous night at 02:00 and 05:00.

Could it be that the entity resets a few miliseconds too late and the graph still shows the “old” value, a ms before resetting?
How can I fix that?

Yes, exactly. The value was still heldover from the previous hour at 12:00:00.00001, so that value is included in the max for the hour as far as statistics is concerned.

Possibly you may want a different state class for this. If you want to see the hourly cost, your sensor should be a total class, not measurement. Then you would view the change per hour, instead of the max per hour.

If that’s not an option, the only other thing I can think of is to pass it through the template that forces the value to 0 between X:59 and X:01.

This makes the graph confusing.
According to docs, LTS is supposed to be updated after every hour.
So a user expects to see a value calculated at 12:00 (plus a few milliseconds) at a “12:00” point of a graph. In fact, a previous value is shown for something like “11:59”.