Statistics graph for longtime energy consumption

I was hoping I could use the statistics graph to visualize my long-term energy consumption similar to the new energy dashboard, only for longer periods of time.

This would have the advantage of to visualize long term data without the need for bloating my database with unneeded detailed state data or using influx and grafana.

However, when I configure a statistics graph card with a “total energy sensor” (which works in the energy dashboard) I get an empty card.

When I configure a “daily energy sensor” it actually shows data, but only in an aggregated form (sum), with hourly bars.

I was hoping to see one bar for every day in range with the consumed power of the entity on that day much like the energy-dashboard.

I know I can achieve a similar effect with Mini-Graph, but only at the cost of a bloated database.

Am I “doing this wrong”, expecting to much or just to impatient :stuck_out_tongue_closed_eyes:

This.

Longer term statistics, weekly, monthly and yearly, are planned.

3 Likes

It’s not just the reporting period. It’s also the aggregation method. Right now the graph sums up the daily values. The only method that shows any values is “sum”
Today’s value is “yesterday + today” even when I use the " daily energy sensor".
Also the “total energy sensor” does not show anything.
I don’t have this sensor configured for recording. I thought the statistics graph is based on the new statistics table in the database, so recording should not be required.
Is this a misconception?



In this snapshot I have all the sensors (daily and total) included as well as all the aggregate function.
However, only these four graphs are shown

1 Like

Try adding it to the recorder and see. I’m guessing yes.

Ok, so this chart seems to rely on the regular state data as the graphs appear if I add the sensor to the recorder. But the aggregation does not really make sense.
So I guess I’ll just have to wait and hope for:

  • use of statistics table
  • more reporting periods
  • new stat types to just show the value for the selected period instead of summing up all values since the beginning of time

So if I understand correctly the statistics-graph cannot currently show a bar chart similar to the energy dashboard for any kind of sensor? Or can it be done with some additional configuration I haven’t figured out yet. This is a sensor created by utility_meter component I was trying to display like that.

Sure, check out the mini-graph-card or apexcharts.

Doesn’t support statistics, yet, though: https://github.com/RomRider/apexcharts-card/pull/208

1 Like

I am using mini-graph-card at the moment. I was wondering if the statistics-graph could be used. It seemed like it was meant to at least.

Sorry I thought you just wanted a bar graph.

The statistics graph are currently not usefull / correct with state_class = total or total_increasing.

  1. Statistics graph should work like energy module. It should not show an agregate, but should be per day / week / month as for energy.
  2. We should have in the statistics graph a selector day / week / month as in the energy module

Exemple of my electric consumption :
In “energy” module, with dedicated energy cards, I have this (and it is great) :

image

But with a same entity, in the statistics graph, I have this :upside_down_face:
image

I would like to use “total” statistics for other purpose.

So, my questions :

  • Is there a way to create a “energy like” graph with long term statistics?
  • Or should I wait for an upgrade of the statistics graph?
  • Or should I use infludb / grafana and not use long term statistics?
2 Likes

Im not sure what ur looking for, but is it this, or some, more advanced … i do also looking for every “options” to reduce my DB, load usage, in any means … not that i have problems so far, but who knows next year :slight_smile:

thou yes, i have to set this as “Show 30days” which is “from current” , a template could/would adapt how i would “see” my data … thou im not there yet :slight_smile: , how it’s stored in DB for longer terms, will also have to wait until i have an external, or internal maria DB

PS: i was also looking for a card, with the “option” to show “select-totalsumday” auto-add column
… maybe a html-template will be the solution, if noone have come with a better solution, when i get to this “priority” :slight_smile:

edit: actually this card uses “aggregate” and “sum” , but apparently not the functionality, to “separate” in “Daily/monthly” “groups” …

Hi. I was searchign for the same and probably found :slight_smile:

The statistics graph card has an option which is not available in GUI. So if you switch to Code Editor for the card you can choose one mroe graph type (expect min, max, mean, sum) - state. And it will do the trick. In case you have data in expected format.

stat_types:
  - state

The type can be found in documentation:

2 Likes

Excellent, thank you !! That is exactely what I was looking for. State should be in the UI…

1 Like

I had the same requirement. Unfortunately the solution above does not work for me. I managed to get it working using ApexCharts. Also possible with mini-graph-card by the way.

The key to make it work is the group by delta function.
apex1

Code for hourly - last 8 hours

type: custom:apexcharts-card
experimental:
  color_threshold: true
header:
  show: true
  title: Grid Consumption - Today
  show_states: true
  colorize_states: true
yaxis:
  - show: true
    min: 0
    decimals: 0
    apex_config:
      tickAmount: 3
graph_span: 8h
span:
  end: hour
series:
  - entity: sensor.total_grid_import
    type: column
    opacity: 0.8
    show:
      in_header: false
    group_by:
      func: delta
      duration: 1h
    color_threshold:
      - value: 0
        color: green
      - value: 2
        color: yellow
      - value: 4
        color: darkorange
      - value: 8
        color: red

Code for daily - last 7 days

type: custom:apexcharts-card
experimental:
  color_threshold: true
header:
  show: true
  title: Grid Consumption - Week
  show_states: true
  colorize_states: true
yaxis:
  - show: true
    min: 0
    decimals: 0
    apex_config:
      tickAmount: 3
graph_span: +7d
span:
  end: day
series:
  - entity: sensor.total_grid_import
    type: column
    opacity: 0.8
    show:
      in_header: false
    group_by:
      func: delta
      duration: 1d
    color_threshold:
      - value: 15
        color: green
      - value: 20
        color: yellow
      - value: 25
        color: darkorange
      - value: 30
        color: red

Hi, I’m using your example. Works great. Is there a method to make the mouse over window a bit smaller? I’m not able to see the values. Any help is appreciated.

Hi. I am late to the party and mostly clueless. Can anyone help me understand how to make this sensor?