I have configured a rule that checks once every day to record the most expensive electricity price during the day, I then created a statistics sensor that calculates average of the expensive prices during past week:
- platform: statistics
name: Dear Electricity Prices Past Week
entity_id: input_number.dearest_electricity_price
state_characteristic: mean
unique_id: electricity_dear_threshold
max_age:
days: 7
I read the document about “mean”: The average value computed for all measurements. Be aware that this does not consider uneven time intervals between measurements. So my understand it that it simply calculate the average number for the past 7 days. However in the history I see below:
The blue line is daily update of expensive price, as expected it updates once per day. The yellow line is the average, to my surprise it’s not updated when the underlying value changes - in fact when the price for today is higher it changes multiple times in irregular intervals moving the average number up.
I’m not sure I understand why it does this and all I need is average of past 7 numbers. Am I doing something stupid here?
The mean value, often referred to as the average, is calculated by adding all the numbers in a dataset and then dividing by the total number of values. It represents the central point of the data and is a common measure used in statistics.
The Mean Value Theorem states that if a function f is continuous on the closed interval [a,b] and differentiable on the open interval (a,b), then there exists at least one point c in (a,b) such that the derivative at that point equals the average rate of change over the interval. The formula is given by:
f′(c)=b−af(b)−f(a)
The Mean Value Theorem for Integrals states that if a function is continuous on a closed interval, there exists at least one point in that interval where the function’s value equals its average value over the interval. Mathematically, this can be expressed as f(c)=b−a1∫abf(x)dx for some c in [a,b].
This link explains and shows all the various types and uses of mean
It does take in all data points spikes/dips if captured when polled and stored
Thank you for your reply!
In my example past 7 days there are 7 values, shouldn’t mean take sum of all values and divide by occurrences which is 7? What I’m puzzled is why the mean value changes intraday even though the underlying doesn’t change, maybe you have explained but I’m very slow at math…