Apexchart Create weekly graph starting from zero

Hi all, i’m trying to make a simple graph showing two lines

  • one showing this weeks accumulated heat usage
  • one showing past weeks accumulated heat usage

We already have this for solar energy
just a raph showing current total next to yesterday total
but for this we use a “total_energy_today” sensor.

For my heat consumption i only have a sensor with total value that keeps growing.
If i simply plot the data in a graph like this:

type: custom:apexcharts-card
graph_span: 7d
span:
  start: week
header:
  show: true
  title: usage week
  show_states: false
  colorize_states: true
series:
  - entity: sensor.smartgateways_kamstir_heat_energy
    name: this week
    float_precision: 3
    type: line
  - entity: sensor.smartgateways_kamstir_heat_energy
    name: past week
    offset: '-7d'

I then get two graphs but starting at the total value of the beginning of that week.
I want them both to start from zero and accumulate
(sorry, new user, so i can only post 1 image yet)

but what i want is for both of them to start at zero and show the growing total.
I tried using the “statistics” option, adding this to the series:

    statistics:
      type: sum
      period: 5minute
      align: start

but that doesn’t do what i want. it takes the sum from the first value in the DB not the first value of the requested series, so it doesn’t start at zero.

is there a way to create this kind of graph with this value that keeps growing?
is there for example a way to transform the data by substracting the first value of the series so each line starts at zero? if i hardcode that, i get the graph i want. but it has to be dynamic ofcourse.

  - entity: sensor.smartgateways_kamstir_heat_energy
    name: this week
    float_precision: 3
    type: line
    transform: "return x - 5.771;"
  - entity: sensor.smartgateways_kamstir_heat_energy
    name: past week
    float_precision: 3
    offset: '-7d'
    transform: "return x - 5.146;"

this is what i want :slight_smile:
image

Or is it only possible when i create a custom “weekly_total” sensor?

I would create a utility_meter sensor for that that resets as per your liking, hour/day/week…

Utility Meter - Home Assistant (home-assistant.io)

EDIT: sorry, this will probably not work for “last week” but that you can do with adding the same plus an offset

Indeed, i created the utility sensors foor day/week/month.
now have to wait for them to collect data.

To bad it can not be done with default data.