I am hoping someone could help with some unexpected results from 2 statistics sensors I have created.
I am pretty confident that the configuration is correct as per documentation, but results are incorrect.
I have 2 x sensors that I want to use to display the Maximum value for the past 1 hour and for the past 24 hours.
The Lovelace dashboard does display values, but not what I am expecting. Been running for a few days already and recorder settings are all default.
Config and screenshots are below.
From the graphs, you can clearly see that Max values, but the dashboard does not display as per graph.
# Solar Inverter 1 Load Power Stats Max Last Hour
- platform: statistics
name: solar_inverter_inverter_1_load_power_stats_max_last_hour
entity_id: sensor.solar_inverter_inverter_1_load_power
state_characteristic: value_max
max_age:
minutes: 60
# Solar Inverter 1 Load Power Stats Max Last Day
- platform: statistics
name: solar_inverter_inverter_1_load_power_stats_max_last_day
entity_id: sensor.solar_inverter_inverter_1_load_power
state_characteristic: value_max
max_age:
hours: 24
The sampling size must be grater than the max age divided by the sampling interval of the sensor.
So if you have a sensor that updates every 30 seconds and want an average for the last hour:
1x60x60 / 30 = 120 samples minimum.
Or for a full day
24x60x60 / 30 = 2880 samples minimum
The statistics sensor has an attribute buffer_usage_ratio. Setting the sampling_size so that this is close to 1 but never equals 1 (buffer full) will give the best results with most efficient use of memory.
In short you need to know how often sensor.solar_inverter_inverter_1_load_power updates so you can set the sampling_size value.
For a buffer fill of 90%:
sampling_size = 1.1 * max_age in seconds / source sensor sampling interval in seconds