ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ezo_pmp.h
Go to the documentation of this file.
1#pragma once
2
7
8#ifdef USE_BINARY_SENSOR
10#endif
11
12#ifdef USE_SENSOR
14#endif
15
16#ifdef USE_TEXT_SENSOR
18#endif
19
20namespace esphome::ezo_pmp {
21
22class EzoPMP : public PollingComponent, public i2c::I2CDevice {
23 public:
24 void dump_config() override;
25
26 void loop() override;
27 void update() override;
28
29#ifdef USE_SENSOR
30 void set_current_volume_dosed(sensor::Sensor *current_volume_dosed) { current_volume_dosed_ = current_volume_dosed; }
31 void set_total_volume_dosed(sensor::Sensor *total_volume_dosed) { total_volume_dosed_ = total_volume_dosed; }
32 void set_absolute_total_volume_dosed(sensor::Sensor *absolute_total_volume_dosed) {
33 absolute_total_volume_dosed_ = absolute_total_volume_dosed;
34 }
35 void set_pump_voltage(sensor::Sensor *pump_voltage) { pump_voltage_ = pump_voltage; }
36 void set_last_volume_requested(sensor::Sensor *last_volume_requested) {
37 last_volume_requested_ = last_volume_requested;
38 }
39 void set_max_flow_rate(sensor::Sensor *max_flow_rate) { max_flow_rate_ = max_flow_rate; }
40#endif
41
42#ifdef USE_BINARY_SENSOR
43 void set_is_dosing(binary_sensor::BinarySensor *is_dosing) { is_dosing_ = is_dosing; }
44 void set_is_paused(binary_sensor::BinarySensor *is_paused) { is_paused_ = is_paused; }
45#endif
46
47#ifdef USE_TEXT_SENSOR
48 void set_dosing_mode(text_sensor::TextSensor *dosing_mode) { dosing_mode_ = dosing_mode; }
49 void set_calibration_status(text_sensor::TextSensor *calibration_status) { calibration_status_ = calibration_status; }
50#endif
51
52 // Actions for EZO-PMP
53 void find();
54 void dose_continuously();
55 void dose_volume(double volume);
56 void dose_volume_over_time(double volume, int duration);
57 void dose_with_constant_flow_rate(double volume, int duration);
58 void set_calibration_volume(double volume);
60 void clear_calibration();
61 void pause_dosing();
62 void stop_dosing();
64 void exec_arbitrary_command(const std::basic_string<char> &command);
65
66 protected:
69 bool is_waiting_ = false;
70 bool is_first_read_ = true;
71
72 uint16_t next_command_ = 0;
73 double next_command_volume_ = 0; // might be negative
75
76 uint16_t next_command_queue_[10];
82
83 uint16_t current_command_ = 0;
84 bool is_paused_flag_ = false;
85 bool is_dosing_flag_ = false;
86
87 std::string arbitrary_command_{};
88
89 void send_next_command_();
92 void queue_command_(uint16_t command, double volume, int duration, bool should_schedule);
93 void pop_next_command_();
94 uint16_t peek_next_command_();
95
96#ifdef USE_SENSOR
103#endif
104
105#ifdef USE_BINARY_SENSOR
108#endif
109
110#ifdef USE_TEXT_SENSOR
113#endif
114};
115
116// Action Templates
117template<typename... Ts> class EzoPMPFindAction : public Action<Ts...> {
118 public:
119 EzoPMPFindAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
120
121 void play(const Ts &...x) override { this->ezopmp_->find(); }
122
123 protected:
125};
126
127template<typename... Ts> class EzoPMPDoseContinuouslyAction : public Action<Ts...> {
128 public:
130
131 void play(const Ts &...x) override { this->ezopmp_->dose_continuously(); }
132
133 protected:
135};
136
137template<typename... Ts> class EzoPMPDoseVolumeAction : public Action<Ts...> {
138 public:
139 EzoPMPDoseVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
140
141 void play(const Ts &...x) override { this->ezopmp_->dose_volume(this->volume_.value(x...)); }
142 TEMPLATABLE_VALUE(double, volume)
143
144 protected:
145 EzoPMP *ezopmp_;
146};
147
148template<typename... Ts> class EzoPMPDoseVolumeOverTimeAction : public Action<Ts...> {
149 public:
151
152 void play(const Ts &...x) override {
153 this->ezopmp_->dose_volume_over_time(this->volume_.value(x...), this->duration_.value(x...));
154 }
155 TEMPLATABLE_VALUE(double, volume)
157
158 protected:
160};
161
162template<typename... Ts> class EzoPMPDoseWithConstantFlowRateAction : public Action<Ts...> {
163 public:
165
166 void play(const Ts &...x) override {
167 this->ezopmp_->dose_with_constant_flow_rate(this->volume_.value(x...), this->duration_.value(x...));
168 }
169 TEMPLATABLE_VALUE(double, volume)
171
172 protected:
174};
175
176template<typename... Ts> class EzoPMPSetCalibrationVolumeAction : public Action<Ts...> {
177 public:
178 EzoPMPSetCalibrationVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
179
180 void play(const Ts &...x) override { this->ezopmp_->set_calibration_volume(this->volume_.value(x...)); }
181 TEMPLATABLE_VALUE(double, volume)
182
183 protected:
184 EzoPMP *ezopmp_;
185};
186
187template<typename... Ts> class EzoPMPClearTotalVolumeDispensedAction : public Action<Ts...> {
188 public:
190
191 void play(const Ts &...x) override { this->ezopmp_->clear_total_volume_dosed(); }
192
193 protected:
195};
196
197template<typename... Ts> class EzoPMPClearCalibrationAction : public Action<Ts...> {
198 public:
200
201 void play(const Ts &...x) override { this->ezopmp_->clear_calibration(); }
202
203 protected:
205};
206
207template<typename... Ts> class EzoPMPPauseDosingAction : public Action<Ts...> {
208 public:
210
211 void play(const Ts &...x) override { this->ezopmp_->pause_dosing(); }
212
213 protected:
215};
216
217template<typename... Ts> class EzoPMPStopDosingAction : public Action<Ts...> {
218 public:
220
221 void play(const Ts &...x) override { this->ezopmp_->stop_dosing(); }
222
223 protected:
225};
226
227template<typename... Ts> class EzoPMPChangeI2CAddressAction : public Action<Ts...> {
228 public:
229 EzoPMPChangeI2CAddressAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
230
231 void play(const Ts &...x) override { this->ezopmp_->change_i2c_address(this->address_.value(x...)); }
232 TEMPLATABLE_VALUE(int, address)
233
234 protected:
235 EzoPMP *ezopmp_;
236};
237
238template<typename... Ts> class EzoPMPArbitraryCommandAction : public Action<Ts...> {
239 public:
240 EzoPMPArbitraryCommandAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
241
242 void play(const Ts &...x) override { this->ezopmp_->exec_arbitrary_command(this->command_.value(x...)); }
243 TEMPLATABLE_VALUE(std::string, command)
244
245 protected:
246 EzoPMP *ezopmp_;
247};
248
249} // namespace esphome::ezo_pmp
uint8_t address
Definition bl0906.h:4
This class simplifies creating components that periodically check a state.
Definition component.h:585
Base class for all binary_sensor-type classes.
void play(const Ts &...x) override
Definition ezo_pmp.h:242
void play(const Ts &...x) override
Definition ezo_pmp.h:231
void play(const Ts &...x) override
Definition ezo_pmp.h:201
void play(const Ts &...x) override
Definition ezo_pmp.h:131
void play(const Ts &...x) override
Definition ezo_pmp.h:141
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(int
void play(const Ts &...x) override
Definition ezo_pmp.h:152
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(int
void play(const Ts &...x) override
Definition ezo_pmp.h:121
sensor::Sensor * total_volume_dosed_
Definition ezo_pmp.h:98
void exec_arbitrary_command(const std::basic_string< char > &command)
Definition ezo_pmp.cpp:544
void dose_volume(double volume)
Definition ezo_pmp.cpp:496
uint16_t current_command_
Definition ezo_pmp.h:83
void set_is_paused(binary_sensor::BinarySensor *is_paused)
Definition ezo_pmp.h:44
binary_sensor::BinarySensor * is_paused_
Definition ezo_pmp.h:107
int next_command_duration_queue_[10]
Definition ezo_pmp.h:78
void set_current_volume_dosed(sensor::Sensor *current_volume_dosed)
Definition ezo_pmp.h:30
sensor::Sensor * max_flow_rate_
Definition ezo_pmp.h:101
void set_pump_voltage(sensor::Sensor *pump_voltage)
Definition ezo_pmp.h:35
void set_dosing_mode(text_sensor::TextSensor *dosing_mode)
Definition ezo_pmp.h:48
uint16_t next_command_queue_[10]
Definition ezo_pmp.h:76
std::string arbitrary_command_
Definition ezo_pmp.h:87
void dump_config() override
Definition ezo_pmp.cpp:40
void set_max_flow_rate(sensor::Sensor *max_flow_rate)
Definition ezo_pmp.h:39
double next_command_volume_queue_[10]
Definition ezo_pmp.h:77
void set_calibration_volume(double volume)
Definition ezo_pmp.cpp:514
void set_absolute_total_volume_dosed(sensor::Sensor *absolute_total_volume_dosed)
Definition ezo_pmp.h:32
void set_total_volume_dosed(sensor::Sensor *total_volume_dosed)
Definition ezo_pmp.h:31
void set_calibration_status(text_sensor::TextSensor *calibration_status)
Definition ezo_pmp.h:49
void change_i2c_address(int address)
Definition ezo_pmp.cpp:540
void queue_command_(uint16_t command, double volume, int duration, bool should_schedule)
Definition ezo_pmp.cpp:461
void loop() override
Definition ezo_pmp.cpp:80
binary_sensor::BinarySensor * is_dosing_
Definition ezo_pmp.h:106
sensor::Sensor * last_volume_requested_
Definition ezo_pmp.h:102
void set_is_dosing(binary_sensor::BinarySensor *is_dosing)
Definition ezo_pmp.h:43
void dose_volume_over_time(double volume, int duration)
Definition ezo_pmp.cpp:502
void set_last_volume_requested(sensor::Sensor *last_volume_requested)
Definition ezo_pmp.h:36
uint16_t peek_next_command_()
Definition ezo_pmp.cpp:453
sensor::Sensor * absolute_total_volume_dosed_
Definition ezo_pmp.h:99
text_sensor::TextSensor * dosing_mode_
Definition ezo_pmp.h:111
sensor::Sensor * pump_voltage_
Definition ezo_pmp.h:100
sensor::Sensor * current_volume_dosed_
Definition ezo_pmp.h:97
void dose_with_constant_flow_rate(double volume, int duration)
Definition ezo_pmp.cpp:508
void update() override
Definition ezo_pmp.cpp:48
text_sensor::TextSensor * calibration_status_
Definition ezo_pmp.h:112
void play(const Ts &...x) override
Definition ezo_pmp.h:211
void play(const Ts &...x) override
Definition ezo_pmp.h:221
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
Base-class for all sensors.
Definition sensor.h:47
uint8_t duration
Definition msa3xx.h:0
static void uint32_t
uint16_t x
Definition tt21100.cpp:5