Derivative Sensor: how is the time based weighted calculation calculated?

Trying to figure out how this is typically calculated to see if it works for my use case but haven’t found how it works. Perplexity gave me this

Weighted Average Calculation

The weighting process takes into account both the change in value and the time elapsed:

  • Each data point within the time window contributes to the average based on its time proximity.
  • More recent data points have a higher weight in the calculation compared to older ones.
  • This approach helps to smooth out discrete values or filter short-duration noise in the sensor readings[1].

But not sure how the weight is calculated.

Figured it out via the code base It is just using deltaT/time window you choose in the configuration of the sensor which makes sense then just adds up all those derivatives * weight for the entire period and you have your weighted moving average derivative.


            def calculate_weight(
                start: datetime, end: datetime, now: datetime
            ) -> float:
                window_start = now - timedelta(seconds=self._time_window)
                if start < window_start:
                    weight = (end - window_start).total_seconds() / self._time_window
                else:
                    weight = (end - start).total_seconds() / self._time_window
                return weight