ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
combination.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <functional>
8
9namespace esphome {
10namespace combination {
11
13 public:
15 virtual void log_source_sensors() = 0;
16
17 protected:
20 void log_config_(const LogString *combo_type);
21};
22
25 public:
27 void setup() override;
28
29 void add_source(Sensor *sensor);
30
33 virtual void handle_new_value(float value) = 0;
34
36 void log_source_sensors() override;
37
38 protected:
39 std::vector<Sensor *> sensors_;
40};
41
42// Base class for opertions that require one parameter to compute the combination
44 public:
45 void set_source_count(size_t count) { this->sensor_sources_.init(count); }
46 void add_source(Sensor *sensor, std::function<float(float)> const &compute);
47 void add_source(Sensor *sensor, float value);
48
50 void log_source_sensors() override;
51
52 protected:
58
60};
61
63 public:
64 void dump_config() override;
65 void setup() override;
66
67 void set_process_std_dev(float process_std_dev) {
68 this->update_variance_value_ = process_std_dev * process_std_dev * 0.001f;
69 }
70 void set_std_dev_sensor(Sensor *sensor) { this->std_dev_sensor_ = sensor; }
71
72 protected:
73 void update_variance_();
74 void correct_(float value, float stddev);
75
76 // Optional sensor for publishing the current error
78
79 // Tick of the last update
81 // Change of the variance, per ms
83
84 // Best guess for the state and its variance
85 float state_{NAN};
86 float variance_{INFINITY};
87};
88
90 public:
91 void dump_config() override { this->log_config_(LOG_STR("linear")); }
92 void setup() override;
93
94 void handle_new_value(float value);
95};
96
98 public:
99 void dump_config() override { this->log_config_(LOG_STR("max")); }
100
101 void handle_new_value(float value) override;
102};
103
105 public:
106 void dump_config() override { this->log_config_(LOG_STR("mean")); }
107
108 void handle_new_value(float value) override;
109};
110
112 public:
113 void dump_config() override { this->log_config_(LOG_STR("median")); }
114
115 void handle_new_value(float value) override;
116};
117
119 public:
120 void dump_config() override { this->log_config_(LOG_STR("min")); }
121
122 void handle_new_value(float value) override;
123};
124
126 public:
127 void dump_config() override { this->log_config_(LOG_STR("most_recently_updated")); }
128
129 void handle_new_value(float value) override;
130};
131
133 public:
134 void dump_config() override { this->log_config_(LOG_STR("range")); }
135
136 void handle_new_value(float value) override;
137};
138
140 public:
141 void dump_config() override { this->log_config_(LOG_STR("sum")); }
142
143 void handle_new_value(float value) override;
144};
145
146} // namespace combination
147} // namespace esphome
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Definition helpers.h:522
void log_config_(const LogString *combo_type)
Logs the sensor for use in dump_config.
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:24
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 sensors' names in sensor_sources_.
void add_source(Sensor *sensor, std::function< float(float)> const &compute)
void set_process_std_dev(float process_std_dev)
Definition combination.h:67
void correct_(float value, float stddev)
Base-class for all sensors.
Definition sensor.h:47
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
static void uint32_t