ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ecocomfort2_hub.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_ESP32
5
9#include "ecocomfort2_child.h"
10
11#ifdef USE_SENSOR
13#endif
14#ifdef USE_BINARY_SENSOR
16#endif
17#ifdef USE_TEXT_SENSOR
19#endif
20#ifdef USE_TIME
22#endif
23#ifdef USE_NUMBER
25#endif
26#ifdef USE_SWITCH
28#endif
29#ifdef USE_SELECT
31#endif
32
33namespace esphome::ecocomfort2 {
34
36
37// C_OPER byte 0: operating mode
38static constexpr uint8_t OPER_OFF = 0x00;
39static constexpr uint8_t OPER_IN = 0x01;
40static constexpr uint8_t OPER_OUT = 0x02;
41static constexpr uint8_t OPER_IN_OUT = 0x03;
42static constexpr uint8_t OPER_SENSOR_OR_AUTO = 0x04;
43
44// Speed byte: speed in the low nibble, flags in the high nibble.
45// C_OPER carries FLAG_AUTO; the unit reports FLAG_BOOST in byte 1 of C_STATE.
46static constexpr uint8_t SPEED_OFF = 0x00;
47static constexpr uint8_t SPEED_SLEEP = 0x01;
48static constexpr uint8_t SPEED_VEL1 = 0x02;
49static constexpr uint8_t SPEED_VEL2 = 0x03;
50static constexpr uint8_t SPEED_VEL3 = 0x04;
51static constexpr uint8_t SPEED_MASK = 0x0F;
52static constexpr uint8_t FLAG_AUTO = 0x10;
53static constexpr uint8_t FLAG_BOOST = 0x40;
54
55// The thresholds come first, in the order of their C_CONFIGURATION bytes
70
71#ifdef USE_ECOCOMFORT2_SETTINGS
75 uint16_t handle{0};
76 bool needed : 1 {false}; // An entity uses this characteristic
77 bool known : 1 {false}; // Read since connecting
78 bool in_flight : 1 {false};
79 bool dirty : 1 {false}; // A write followed the read in flight, so its answer is stale
80};
81#endif
82
85#ifdef USE_SENSOR
86 SUB_SENSOR(temperature)
87 SUB_SENSOR(humidity)
88 SUB_SENSOR(voc)
89 SUB_SENSOR(direction)
90#endif
91#ifdef USE_BINARY_SENSOR
92 SUB_BINARY_SENSOR(connected)
93 SUB_BINARY_SENSOR(boost)
94#endif
95#ifdef USE_TEXT_SENSOR
96 SUB_TEXT_SENSOR(firmware)
97#endif
98
99 public:
100 void setup() override;
101 void update() override;
102 void dump_config() override;
103 float get_setup_priority() const override { return setup_priority::BLUETOOTH; }
104
105 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
106 esp_ble_gattc_cb_param_t *param) override;
107 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
108
109#ifdef ECOCOMFORT2_CHILD_COUNT
110 void register_child(Ecocomfort2Client *obj);
111#endif
112#ifdef USE_TIME
114 void set_time(time::RealTimeClock *time) { this->time_ = time; }
115#endif
116#ifdef USE_ECOCOMFORT2_SETTINGS
117 // The writes below publish every entity they affect with the value sent; a refused change publishes nothing
118#ifdef USE_NUMBER
119 void set_number(NumberSetting setting, number::Number *number) {
120 this->numbers_[static_cast<uint8_t>(setting)] = number;
122 true;
123 }
124 void write_number(NumberSetting setting, float value);
125#endif
126#ifdef USE_SWITCH
127 void set_switch(SwitchSetting setting, switch_::Switch *sw) {
128 this->switches_[static_cast<uint8_t>(setting)] = sw;
129 this->config_char_.needed = true;
130 }
131 void write_switch(SwitchSetting setting, bool state);
132#endif
133#ifdef USE_SELECT
134 void set_select(SelectSetting setting, select::Select *select) {
135 this->selects_[static_cast<uint8_t>(setting)] = select;
136 this->config_char_.needed = true;
137 }
138 void write_select(SelectSetting setting, size_t index);
139#endif
140#endif // USE_ECOCOMFORT2_SETTINGS
141
143 bool is_ready() const { return this->node_state == espbt::ClientState::ESTABLISHED && this->parent_->is_paired(); }
144
146 void write_oper(uint8_t mode, uint8_t speed);
147
149 uint8_t get_mode() const { return this->mode_; }
150 uint8_t get_speed() const { return this->speed_; }
151
152 protected:
153 static constexpr uint32_t AUTH_TIMEOUT_ID = 0;
154 static constexpr uint32_t READBACK_TIMEOUT_ID = 1;
155 static constexpr uint32_t AUTH_TIMEOUT_MS = 10000;
156 static constexpr uint32_t READBACK_DELAY_MS = 300;
157
158 void on_paired_();
159 void set_connected_(bool connected);
160 void publish_unknown_();
161 bool read_char_(uint16_t handle);
162 bool write_char_(uint16_t handle, uint8_t *data, uint16_t len);
163 bool read_ok_(const esp_ble_gattc_cb_param_t *param);
164 void on_oper_(const uint8_t *data, uint16_t len);
165 void on_state_(const uint8_t *data, uint16_t len);
166 void on_info_(const uint8_t *data, uint16_t len);
167#ifdef USE_TIME
168 void sync_clock_();
169#endif
170#ifdef USE_ECOCOMFORT2_SETTINGS
171 void read_settings_();
172 void request_settings_(SettingsChar &settings);
174 bool settings_known_(const SettingsChar &settings);
175 void on_config_(const uint8_t *data, uint16_t len);
176 void on_advanced_(const uint8_t *data, uint16_t len);
178 void write_config_(uint8_t index, uint8_t value, uint8_t stored);
179 void write_offsets_(int16_t temperature, int16_t humidity);
180 bool write_settings_(SettingsChar &settings, uint8_t *data, uint16_t len);
181 void publish_config_();
182 void publish_offsets_();
183#endif
184
185#ifdef ECOCOMFORT2_CHILD_COUNT
187#endif
188#ifdef USE_TIME
190#endif
191 uint16_t char_handle_oper_{0};
193 uint16_t char_handle_info_{0};
195 uint8_t mode_{OPER_OFF};
196 uint8_t speed_{SPEED_OFF};
197#ifdef USE_ECOCOMFORT2_SETTINGS
198#ifdef USE_NUMBER
200#endif
201#ifdef USE_SWITCH
203#endif
204#ifdef USE_SELECT
206#endif
209 // C_CONFIGURATION bytes 0-4 as last read or written: role, three thresholds, season and free cooling
210 uint8_t config_bytes_[5]{};
211 // C_ADVANCED_SETTINGS temperature and humidity offsets, in hundredths
212 int16_t offsets_[2]{};
213#endif // USE_ECOCOMFORT2_SETTINGS
214};
215
216} // namespace esphome::ecocomfort2
217
218#endif // USE_ESP32
BedjetMode mode
BedJet operating mode.
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
This class simplifies creating components that periodically check a state.
Definition component.h:532
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:304
Hub component for Ecocomfort 2.0 VMC via BLE.
bool settings_known_(const SettingsChar &settings)
static constexpr uint32_t READBACK_DELAY_MS
bool write_char_(uint16_t handle, uint8_t *data, uint16_t len)
void on_advanced_(const uint8_t *data, uint16_t len)
void write_config_(uint8_t index, uint8_t value, uint8_t stored)
Write one C_CONFIGURATION byte, leaving the others as they are, and keep stored as its local copy.
static constexpr uint32_t AUTH_TIMEOUT_ID
void on_state_(const uint8_t *data, uint16_t len)
void on_config_(const uint8_t *data, uint16_t len)
void on_info_(const uint8_t *data, uint16_t len)
void write_offsets_(int16_t temperature, int16_t humidity)
StaticVector< Ecocomfort2Client *, ECOCOMFORT2_CHILD_COUNT > children_
bool settings_answer_current_(SettingsChar &settings)
switch_::Switch * switches_[static_cast< uint8_t >(SwitchSetting::SWITCH_SETTING_COUNT)]
void request_settings_(SettingsChar &settings)
bool write_settings_(SettingsChar &settings, uint8_t *data, uint16_t len)
static constexpr uint32_t READBACK_TIMEOUT_ID
select::Select * selects_[static_cast< uint8_t >(SelectSetting::SELECT_SETTING_COUNT)]
bool read_ok_(const esp_ble_gattc_cb_param_t *param)
void on_oper_(const uint8_t *data, uint16_t len)
number::Number * numbers_[static_cast< uint8_t >(NumberSetting::NUMBER_SETTING_COUNT)]
static constexpr uint32_t AUTH_TIMEOUT_MS
Base-class for all numbers.
Definition number.h:29
Base-class for all selects.
Definition select.h:28
Base class for all switches.
Definition switch.h:43
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
FanDirection direction
Definition fan.h:5
int speed
Definition fan.h:3
bool state
Definition fan.h:2
constexpr float BLUETOOTH
Definition component.h:48
uint32_t value
Definition hal.cpp:41
const void size_t len
Definition hal.h:68
static void uint32_t
One settings characteristic. Only one read is in flight at a time; a write sent meanwhile makes its a...
uint16_t temperature
Definition sun_gtil2.cpp:12
spi_device_handle_t handle