ESPHome 2026.12.0-dev
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 SLOT_LIST(Ecocomfort2Client, children_, register_child, ECOCOMFORT2_CHILD_COUNT)
110#ifdef USE_TIME
112 void set_time(time::RealTimeClock *time) { this->time_ = time; }
113#endif
114#ifdef USE_ECOCOMFORT2_SETTINGS
115 // The writes below publish every entity they affect with the value sent; a refused change publishes nothing
116#ifdef USE_NUMBER
117 void set_number(NumberSetting setting, number::Number *number) {
118 this->numbers_[static_cast<uint8_t>(setting)] = number;
120 true;
121 }
122 void write_number(NumberSetting setting, float value);
123#endif
124#ifdef USE_SWITCH
125 void set_switch(SwitchSetting setting, switch_::Switch *sw) {
126 this->switches_[static_cast<uint8_t>(setting)] = sw;
127 this->config_char_.needed = true;
128 }
129 void write_switch(SwitchSetting setting, bool state);
130#endif
131#ifdef USE_SELECT
132 void set_select(SelectSetting setting, select::Select *select) {
133 this->selects_[static_cast<uint8_t>(setting)] = select;
134 this->config_char_.needed = true;
135 }
136 void write_select(SelectSetting setting, size_t index);
137#endif
138#endif // USE_ECOCOMFORT2_SETTINGS
139
141 bool is_ready() const { return this->node_state == espbt::ClientState::ESTABLISHED && this->parent_->is_paired(); }
142
144 void write_oper(uint8_t mode, uint8_t speed);
145
147 uint8_t get_mode() const { return this->mode_; }
148 uint8_t get_speed() const { return this->speed_; }
149
150 protected:
151 static constexpr uint32_t AUTH_TIMEOUT_ID = 0;
152 static constexpr uint32_t READBACK_TIMEOUT_ID = 1;
153 static constexpr uint32_t AUTH_TIMEOUT_MS = 10000;
154 static constexpr uint32_t READBACK_DELAY_MS = 300;
155
156 void on_paired_();
157 void set_connected_(bool connected);
158 void publish_unknown_();
159 bool read_char_(uint16_t handle);
160 bool write_char_(uint16_t handle, uint8_t *data, uint16_t len);
161 bool read_ok_(const esp_ble_gattc_cb_param_t *param);
162 void on_oper_(const uint8_t *data, uint16_t len);
163 void on_state_(const uint8_t *data, uint16_t len);
164 void on_info_(const uint8_t *data, uint16_t len);
165#ifdef USE_TIME
166 void sync_clock_();
167#endif
168#ifdef USE_ECOCOMFORT2_SETTINGS
169 void read_settings_();
170 void request_settings_(SettingsChar &settings);
172 bool settings_known_(const SettingsChar &settings);
173 void on_config_(const uint8_t *data, uint16_t len);
174 void on_advanced_(const uint8_t *data, uint16_t len);
176 void write_config_(uint8_t index, uint8_t value, uint8_t stored);
177 void write_offsets_(int16_t temperature, int16_t humidity);
178 bool write_settings_(SettingsChar &settings, uint8_t *data, uint16_t len);
179 void publish_config_();
180 void publish_offsets_();
181#endif
182
183#ifdef USE_TIME
185#endif
186 uint16_t char_handle_oper_{0};
188 uint16_t char_handle_info_{0};
190 uint8_t mode_{OPER_OFF};
191 uint8_t speed_{SPEED_OFF};
192#ifdef USE_ECOCOMFORT2_SETTINGS
193#ifdef USE_NUMBER
195#endif
196#ifdef USE_SWITCH
198#endif
199#ifdef USE_SELECT
201#endif
204 // C_CONFIGURATION bytes 0-4 as last read or written: role, three thresholds, season and free cooling
205 uint8_t config_bytes_[5]{};
206 // C_ADVANCED_SETTINGS temperature and humidity offsets, in hundredths
207 int16_t offsets_[2]{};
208#endif // USE_ECOCOMFORT2_SETTINGS
209};
210
211} // namespace esphome::ecocomfort2
212
213#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:542
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)
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:49
uint32_t value
Definition hal.cpp:59
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