Statistics - bug in calculation... ignores start of week

I have a sensor that tallies the energy over the week. It resets on Sunday 00:00:00.
The sensor itself shows the correct values and pattern.
Using a statistic graph (energy with weekly values over several weeks) brings the wrong results:

  • it counts from Monday to Sunday
  • it should count from Sunday to Saturday. (my case)

The result is wrong using the statistical card and Plotly (which uses the card).
An Apex graph (where we can define more variables) it calculate correctly.

Here are the sensors, stats, graphs etc
(I opened a bug report - but if I am doing anything wrong please do help!
→ I suspect somewhere deep in the system Monday is defined as start day… because I had it so when I created HA first time; I then changed the day to Sunday and I added the CRON as can be seen… but it is ignored

I have defined in my Profile Sunday as first day. (I don’t suppose it is defined anywhere else)

from the YAML file

  unique_id: "mt1681-weeky"
  source: sensor.bitshake_smartmeterreader_mt681_total_in
  name: From netz weekly
  cron: "0 0 * * 7"

and the “origin”

  unit_of_measurement: "kWh"
  device_class: energy
  state_class: total_increasing

This brings the correct measures over time:

Statistic Graph
The statistic graph counts the days from Monday till Saturday although I defined the cron and start of the week on Sunday.

Code for the graph:

chart_type: bar
period: week
type: statistics-graph
  - sensor.from_netz_weekly
title: Consumed Weekly
days_to_show: 28
hide_legend: false
  - change

Graphs - it can be seen the date is wrong eg 8th instead of 7th

How it should be (with Apex)

What is the first day of the week set to in your profile?

You will have to set this for every device you use to view home assistant.

Hi Tom,
Thanks for answering.

I have Sunday set… in my iPad, iPhone and Mac….
So everywhere!

Ist here a way eg in Terminal to see what HA has defined?

I went to terminal and displayed the cal eg for this month… amd Sunday is first day… but perhaps HA has an internal setting.

My guess is that it was set when I created the instance and then the stats do not care for the setting in profile

Any ideas how to check in Terminal?

Then it is a bug with the Statistics card.

I reported it now…
I reported against Frontend, and got a response that it is core; here is what I got as response:

the backend statistics aggregation calculation for weeks is not configurable, it just uses simply the python time.weekday() function to compute the start of the week, so that’s hardcoded to monday.

Oh my, my, my

I have a whole bunch of stuff based on calculations of the week start (energy spent, reports I do, etc… )

Report it as a core issue.