ESPHome  2022.11.3
Public Member Functions | Protected Attributes
esphome::sensor::ExponentialMovingAverageFilter Class Reference

Simple exponential moving average filter. More...

#include <filter.h>

Inheritance diagram for esphome::sensor::ExponentialMovingAverageFilter:
esphome::sensor::Filter

Public Member Functions

 ExponentialMovingAverageFilter (float alpha, size_t send_every, size_t send_first_at)
 
optional< float > new_value (float value) override
 
void set_send_every (size_t send_every)
 
void set_alpha (float alpha)
 
- 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

bool first_value_ {true}
 
float accumulator_ {NAN}
 
size_t send_every_
 
size_t send_at_
 
float alpha_
 
- Protected Attributes inherited from esphome::sensor::Filter
friend Sensor
 
Filternext_ {nullptr}
 
Sensorparent_ {nullptr}
 

Detailed Description

Simple exponential moving average filter.

Essentially just takes the average of the last few values using exponentially decaying weights. Use alpha to adjust decay rate.

Definition at line 194 of file filter.h.

Constructor & Destructor Documentation

◆ ExponentialMovingAverageFilter()

esphome::sensor::ExponentialMovingAverageFilter::ExponentialMovingAverageFilter ( float  alpha,
size_t  send_every,
size_t  send_first_at 
)

Definition at line 212 of file filter.cpp.

Member Function Documentation

◆ new_value()

optional< float > esphome::sensor::ExponentialMovingAverageFilter::new_value ( float  value)
overridevirtual

Implements esphome::sensor::Filter.

Definition at line 214 of file filter.cpp.

◆ set_alpha()

void esphome::sensor::ExponentialMovingAverageFilter::set_alpha ( float  alpha)

Definition at line 235 of file filter.cpp.

◆ set_send_every()

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

Definition at line 234 of file filter.cpp.

Field Documentation

◆ accumulator_

float esphome::sensor::ExponentialMovingAverageFilter::accumulator_ {NAN}
protected

Definition at line 205 of file filter.h.

◆ alpha_

float esphome::sensor::ExponentialMovingAverageFilter::alpha_
protected

Definition at line 208 of file filter.h.

◆ first_value_

bool esphome::sensor::ExponentialMovingAverageFilter::first_value_ {true}
protected

Definition at line 204 of file filter.h.

◆ send_at_

size_t esphome::sensor::ExponentialMovingAverageFilter::send_at_
protected

Definition at line 207 of file filter.h.

◆ send_every_

size_t esphome::sensor::ExponentialMovingAverageFilter::send_every_
protected

Definition at line 206 of file filter.h.


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