History stats for past n days

Hello all,

I’ve managed to use history_stats to show the duration a switch has been ‘on’ for today. However I would like to have a plot showing the ‘on’ duration each day for the past 7 days. Is there a neater way of doing this than copy and pasting the history_stats entity 7 times? And how can I make a lovelace card to show a graph of these 7 values?

From my experience so far, most plots in HA are continuous, so I’m not sure how to go about plotting specific values.

Any help much appreciated :slight_smile:

Thanks,
J

There also is a utility meter sensor that resets every period, which could be of use.

If you only want to “show” it you don’t need a sensor for each day. There are a few options to graph the maximum value for a week of days - Grafana (requires influxdb), Apexcharts (HA card), MIni-graph-card (HA Card).

Apexchart:

Screenshot 2022-05-03 at 09-16-57 Overview – Home Assistant

Mini-graph:

Screenshot 2022-05-03 at 09-17-37 Overview – Home Assistant

Grafana:

I think this is doing what I want - Mini-graph seems to be plotting daily durations. I’ll wait a few days to see if it’s updating how I’m expecting

Would you be able to share the config code to get the Mini-graph looking like that daily energy plot? I like alternating colours but I’ve not been able to find how to use them

The colour is due to the value:

aggregate_func: last
card_mod:
  class: top-level-graph
color_thresholds:
  - color: '#e45e65'
    value: 0
  - color: '#039BE5'
    value: 12
  - color: '#e0b400'
    value: 18
  - color: '#0da035'
    value: 24
color_thresholds_transition: hard
entities:
  - sensor.energy_inverter_daily
group_by: date
hour24: true
hours_to_show: 168
name: Daily Energy
show:
  extrema: true
  fill: fade
  graph: bar
  labels: false
smoothing: false
lower_bound: 0
type: custom:mini-graph-card
2 Likes