Please describe the idea
Hi,
I noticed a performance difference when using sensors that only provide recorder history instead of long-term statistics.
Utility Meter sensors in Home Assistant use Long-Term Statistics and load almost instantly in the header of the Statistics Graph Chart Card when using the preset last instant.
However, when I use a Template Sensor helper, the card takes noticeably longer to load. Template sensors only expose recorder history, so I assume the card needs to process a much larger dataset.
My use case is calculating my own energy consumption with a template:
consumption = production - returned_to_grid
This works correctly, but when this sensor is used in the card header (for example daily or monthly values with aggregation: last), loading the card becomes slower compared to sensors that use statistics.
Since template sensors cannot provide long-term statistics, I was wondering if the card could potentially optimize history-based sensors when using aggregation: last. For example by:
- only requesting the last datapoint of the selected period
- reducing the amount of history that needs to be processed
- or caching the result
Utility meter sensors load almost instantly, so it would be great if history-only sensors could behave similarly in this case.
Loading takes 10 to 20 seconds everytime:
type: custom:statistics-graph-chart-card
card_header: Maandverbruik
card_background_color: rgba(36, 37, 41, 0.3)
card_border: false
show_tooltip_total: false
animate_graph: true
stacked: true
points_per_hour: 1
height: 300
show_full_period: true
x_grid_style: long-dash
y_grid_style: long-dash
show_date_picker: true
date_picker_group: "1"
date_picker_modes:
- month
state_layout: horizontal
group_by: date
entities:
- entity: sensor.dagverbruik_p1_import
statistic_id: null
name: Import
color: "#ff3cdd"
graph_type: bar
aggregate_func: last
state_size: 24px
show_trend_icon: false
primary_state_as: sum
name_position: below
state_color: "#ffffff"
- entity: sensor.dagverbruik_p1_export
statistic_id: null
name: Export
color: "#36ec22"
graph_type: bar
aggregate_func: last
icon_size: 22px
state_size: 24px
invert: true
show_trend_icon: false
primary_state_as: sum
name_position: below
state_color: "#ffffff"
align_state: center
- entity: sensor.eigenverbruik_maand
statistic_id: null
name: Eigen verbruik
color: "#04a2ff"
graph_type: bar
aggregate_func: last
icon_size: 22px
state_size: 24px
invert: true
show_trend_icon: false
primary_state_as: last
name_position: below
state_color: "#ffffff"
align_state: right
points_per_hour: 1
show_graph: false
show_line: false
show_fill: false
annotations: []
grid_options:
columns: 15
rows: auto
Please describe the idea
Hi,
I noticed a performance difference when using sensors that only provide recorder history instead of long-term statistics.
Utility Meter sensors in Home Assistant use Long-Term Statistics and load almost instantly in the header of the Statistics Graph Chart Card when using the preset last instant.
However, when I use a Template Sensor helper, the card takes noticeably longer to load. Template sensors only expose recorder history, so I assume the card needs to process a much larger dataset.
My use case is calculating my own energy consumption with a template:
consumption = production - returned_to_grid
This works correctly, but when this sensor is used in the card header (for example daily or monthly values with aggregation: last), loading the card becomes slower compared to sensors that use statistics.
Since template sensors cannot provide long-term statistics, I was wondering if the card could potentially optimize history-based sensors when using aggregation: last. For example by:
Utility meter sensors load almost instantly, so it would be great if history-only sensors could behave similarly in this case.
Loading takes 10 to 20 seconds everytime: