ESPHome  2022.8.0
Public Member Functions | Protected Attributes
esphome::sensor::SlidingWindowMovingAverageFilter Class Reference

Simple sliding window moving average filter. More...

#include <filter.h>

Inheritance diagram for esphome::sensor::SlidingWindowMovingAverageFilter:

Public Member Functions

 SlidingWindowMovingAverageFilter (size_t window_size, size_t send_every, size_t send_first_at)
 Construct a SlidingWindowMovingAverageFilter. More...
optional< float > new_value (float value) override
void set_send_every (size_t send_every)
void set_window_size (size_t window_size)
- Public Member Functions inherited from esphome::sensor::Filter
virtual void initialize (Sensor *parent, Filter *next)
 Initialize this filter, please note this can be called more than once. More...
void input (float value)
void output (float value)

Protected Attributes

std::deque< float > queue_
size_t send_every_
size_t send_at_
size_t window_size_
- Protected Attributes inherited from esphome::sensor::Filter
friend Sensor
Filternext_ {nullptr}
Sensorparent_ {nullptr}

Detailed Description

Simple sliding window moving average filter.

Essentially just takes takes the average of the last window_size values and pushes them out every send_every.

Definition at line 165 of file filter.h.

Constructor & Destructor Documentation

◆ SlidingWindowMovingAverageFilter()

esphome::sensor::SlidingWindowMovingAverageFilter::SlidingWindowMovingAverageFilter ( size_t  window_size,
size_t  send_every,
size_t  send_first_at 

Construct a SlidingWindowMovingAverageFilter.

window_sizeThe number of values that should be averaged.
send_everyAfter how many sensor values should a new one be pushed out.
send_first_atAfter how many values to forward the very first value. Defaults to the first value on startup being published on the first raw value, so with no filter applied. Must be less than or equal to send_every.

Definition at line 176 of file filter.cpp.

Member Function Documentation

◆ new_value()

optional< float > esphome::sensor::SlidingWindowMovingAverageFilter::new_value ( float  value)

Implements esphome::sensor::Filter.

Definition at line 181 of file filter.cpp.

◆ set_send_every()

void esphome::sensor::SlidingWindowMovingAverageFilter::set_send_every ( size_t  send_every)

Definition at line 179 of file filter.cpp.

◆ set_window_size()

void esphome::sensor::SlidingWindowMovingAverageFilter::set_window_size ( size_t  window_size)

Definition at line 180 of file filter.cpp.

Field Documentation

◆ queue_

std::deque<float> esphome::sensor::SlidingWindowMovingAverageFilter::queue_

Definition at line 183 of file filter.h.

◆ send_at_

size_t esphome::sensor::SlidingWindowMovingAverageFilter::send_at_

Definition at line 185 of file filter.h.

◆ send_every_

size_t esphome::sensor::SlidingWindowMovingAverageFilter::send_every_

Definition at line 184 of file filter.h.

◆ window_size_

size_t esphome::sensor::SlidingWindowMovingAverageFilter::window_size_

Definition at line 186 of file filter.h.

The documentation for this class was generated from the following files: