ESPHome 2025.5.0
Loading...
Searching...
No Matches
combination.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <vector>
7
8namespace esphome {
9namespace combination {
10
12 public:
13 float get_setup_priority() const override { return esphome::setup_priority::DATA; }
14
16 virtual void log_source_sensors() = 0;
17
18 protected:
21 void log_config_(const LogString *combo_type);
22};
23
26 public:
28 void setup() override;
29
30 void add_source(Sensor *sensor);
31
34 virtual void handle_new_value(float value) = 0;
35
37 void log_source_sensors() override;
38
39 protected:
40 std::vector<Sensor *> sensors_;
41};
42
43// Base class for opertions that require one parameter to compute the combination
45 public:
46 void add_source(Sensor *sensor, std::function<float(float)> const &stddev);
47 void add_source(Sensor *sensor, float stddev);
48
50 void log_source_sensors() override;
51
52 protected:
53 std::vector<std::pair<Sensor *, std::function<float(float)>>> sensor_pairs_;
54};
55
57 public:
58 void dump_config() override;
59 void setup() override;
60
61 void set_process_std_dev(float process_std_dev) {
62 this->update_variance_value_ = process_std_dev * process_std_dev * 0.001f;
63 }
64 void set_std_dev_sensor(Sensor *sensor) { this->std_dev_sensor_ = sensor; }
65
66 protected:
67 void update_variance_();
68 void correct_(float value, float stddev);
69
70 // Optional sensor for publishing the current error
72
73 // Tick of the last update
74 uint32_t last_update_{0};
75 // Change of the variance, per ms
77
78 // Best guess for the state and its variance
79 float state_{NAN};
80 float variance_{INFINITY};
81};
82
84 public:
85 void dump_config() override { this->log_config_(LOG_STR("linear")); }
86 void setup() override;
87
88 void handle_new_value(float value);
89};
90
92 public:
93 void dump_config() override { this->log_config_(LOG_STR("max")); }
94
95 void handle_new_value(float value) override;
96};
97
99 public:
100 void dump_config() override { this->log_config_(LOG_STR("mean")); }
101
102 void handle_new_value(float value) override;
103};
104
106 public:
107 void dump_config() override { this->log_config_(LOG_STR("median")); }
108
109 void handle_new_value(float value) override;
110};
111
113 public:
114 void dump_config() override { this->log_config_(LOG_STR("min")); }
115
116 void handle_new_value(float value) override;
117};
118
120 public:
121 void dump_config() override { this->log_config_(LOG_STR("most_recently_updated")); }
122
123 void handle_new_value(float value) override;
124};
125
127 public:
128 void dump_config() override { this->log_config_(LOG_STR("range")); }
129
130 void handle_new_value(float value) override;
131};
132
134 public:
135 void dump_config() override { this->log_config_(LOG_STR("sum")); }
136
137 void handle_new_value(float value) override;
138};
139
140} // namespace combination
141} // namespace esphome
void log_config_(const LogString *combo_type)
Logs the sensor for use in dump_config.
float get_setup_priority() const override
Definition combination.h:13
virtual void log_source_sensors()=0
Logs all source sensor's names.
Base class for operations that do not require an extra parameter to compute the combination.
Definition combination.h:25
void setup() override
Adds a callback to each source sensor.
virtual void handle_new_value(float value)=0
Computes the combination.
void log_source_sensors() override
Logs all source sensor's names in sensors_.
void log_source_sensors() override
Logs all source sensor's names in sensor_pairs_.
void add_source(Sensor *sensor, std::function< float(float)> const &stddev)
std::vector< std::pair< Sensor *, std::function< float(float)> > > sensor_pairs_
Definition combination.h:53
void set_process_std_dev(float process_std_dev)
Definition combination.h:61
void correct_(float value, float stddev)
Base-class for all sensors.
Definition sensor.h:57
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7