ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
gree.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
7#ifdef USE_GREE_FEATURE_SWITCH
9#endif
10
11namespace esphome::gree {
12
13// Values for GREE IR Controllers
14// Temperature
15static constexpr uint8_t GREE_TEMP_MIN = 16; // Celsius
16static constexpr uint8_t GREE_TEMP_MAX = 30; // Celsius
17
18// Modes
19static constexpr uint8_t GREE_MODE_AUTO = 0x00;
20static constexpr uint8_t GREE_MODE_COOL = 0x01;
21static constexpr uint8_t GREE_MODE_HEAT = 0x04;
22static constexpr uint8_t GREE_MODE_DRY = 0x02;
23static constexpr uint8_t GREE_MODE_FAN = 0x03;
24
25static constexpr uint8_t GREE_MODE_OFF = 0x00;
26static constexpr uint8_t GREE_MODE_ON = 0x08;
27
28// Fan Speed
29static constexpr uint8_t GREE_FAN_AUTO = 0x00;
30static constexpr uint8_t GREE_FAN_1 = 0x10;
31static constexpr uint8_t GREE_FAN_2 = 0x20;
32static constexpr uint8_t GREE_FAN_3 = 0x30;
33
34// IR Transmission
35static constexpr uint32_t GREE_IR_FREQUENCY = 38000;
36static constexpr uint32_t GREE_HEADER_MARK = 9000;
37static constexpr uint32_t GREE_HEADER_SPACE = 4000;
38static constexpr uint32_t GREE_BIT_MARK = 620;
39static constexpr uint32_t GREE_ONE_SPACE = 1600;
40static constexpr uint32_t GREE_ZERO_SPACE = 540;
41static constexpr uint32_t GREE_MESSAGE_SPACE = 19000;
42
43// Timing specific for YAC features (I-Feel mode)
44static constexpr uint32_t GREE_YAC_HEADER_MARK = 6000;
45static constexpr uint32_t GREE_YAC_HEADER_SPACE = 3000;
46static constexpr uint32_t GREE_YAC_BIT_MARK = 650;
47
48// YAW1F shares the longer YAC1FB9 header and inter-block gap.
49static constexpr uint32_t GREE_YAC1FB9_HEADER_SPACE = 4500;
50static constexpr uint32_t GREE_YAC1FB9_MESSAGE_SPACE = 19980;
51// Gap between the YAW1F primary command and its fixed second message.
52static constexpr uint32_t GREE_YAW1F_FOLLOWUP_SPACE = 40000;
53
54// State Frame size
55static constexpr uint8_t GREE_STATE_FRAME_SIZE = 8;
56
57// Vertical air directions. Note that these cannot be set on all heat pumps
58static constexpr uint8_t GREE_VDIR_AUTO = 0x00;
59static constexpr uint8_t GREE_VDIR_MANUAL = 0x00;
60static constexpr uint8_t GREE_VDIR_SWING = 0x01;
61static constexpr uint8_t GREE_VDIR_UP = 0x02;
62static constexpr uint8_t GREE_VDIR_MUP = 0x03;
63static constexpr uint8_t GREE_VDIR_MIDDLE = 0x04;
64static constexpr uint8_t GREE_VDIR_MDOWN = 0x05;
65static constexpr uint8_t GREE_VDIR_DOWN = 0x06;
66// YX1FF vane-position byte while swinging
67static constexpr uint8_t GREE_YX1FF_VANE_SWING = 0x11;
68static constexpr uint8_t GREE_VDIR_SWING_DOWN = 0x07;
69static constexpr uint8_t GREE_VDIR_SWING_MIDDLE = 0x09;
70static constexpr uint8_t GREE_VDIR_SWING_UP = 0x0B;
71
72// Only available on YAC/YAG
73// Horizontal air directions. Note that these cannot be set on all heat pumps
74static constexpr uint8_t GREE_HDIR_AUTO = 0x00;
75static constexpr uint8_t GREE_HDIR_MANUAL = 0x00;
76static constexpr uint8_t GREE_HDIR_SWING = 0x01;
77static constexpr uint8_t GREE_HDIR_LEFT = 0x02;
78static constexpr uint8_t GREE_HDIR_MLEFT = 0x03;
79static constexpr uint8_t GREE_HDIR_MIDDLE = 0x04;
80static constexpr uint8_t GREE_HDIR_MRIGHT = 0x05;
81static constexpr uint8_t GREE_HDIR_RIGHT = 0x06;
82
83// Feature bits in byte 2
84static constexpr uint8_t GREE_MODE_BIT_TURBO = 0x10;
85static constexpr uint8_t GREE_MODE_BIT_LIGHT = 0x20;
86static constexpr uint8_t GREE_MODE_BIT_HEALTH = 0x40;
87static constexpr uint8_t GREE_MODE_BIT_XFAN = 0x80;
88
89// Byte 3 Fahrenheit bits
90static constexpr uint8_t GREE_FAHRENHEIT_BIT = 0x08;
91static constexpr uint8_t GREE_TEMP_HALF_DEGREE_BIT = 0x04; // Half a degree Celsius added to the temperature
92
93#ifdef USE_GREE_FAHRENHEIT
96uint8_t fahrenheit_half_steps(float target_celsius);
97#endif
98
99// Model-specific meanings for the same bit positions on YB1FA/YX1FF.
100static constexpr uint8_t GREE_FAN_TURBO_BIT = 0x10;
101static constexpr uint8_t GREE_MODEL_A_BIT = 0x40;
102
103// Only available on YX1FF
104// Sleep preset mode
105static constexpr uint8_t GREE_PRESET_NONE = 0x00;
106static constexpr uint8_t GREE_PRESET_SLEEP = 0x01;
107static constexpr uint8_t GREE_PRESET_SLEEP_BIT = 0x80;
108
109// Model codes
121
128
129static constexpr uint8_t gree_feature_bit(GreeFeature feature) { return GREE_MODE_BIT_TURBO << feature; }
130
131using GreeState = std::array<uint8_t, GREE_STATE_FRAME_SIZE>;
132
139 uint8_t feature_bits{0};
140 // The unit's panel shows Fahrenheit; half_degree adds half a degree Celsius to target_temperature
141 bool fahrenheit{false};
142 bool half_degree{false};
143};
144
146 public:
147 explicit GreeProtocol(Model model) : model_(model) {}
148
149 void encode(remote_base::RemoteTransmitData *data, const GreeState &state) const;
150#ifdef USE_GREE_RECEIVER
151 optional<GreeState> decode(remote_base::RemoteReceiveData data) const;
152#endif
153
154 static uint8_t calculate_checksum(const GreeState &state);
155#ifdef USE_GREE_RECEIVER
156 static bool valid_checksum(const GreeState &state);
157#endif
158
159 protected:
161};
162
164 public:
165 static GreeState encode(Model model, const GreeClimateData &data);
166#ifdef USE_GREE_RECEIVER
168 static optional<GreeClimateData> decode(Model model, const GreeState &state);
169#endif
170
171 protected:
176#ifdef USE_GREE_RECEIVER
177 static optional<GreeClimateData> decode_legacy(Model model, const GreeState &state);
178 static optional<GreeClimateData> decode_model_a(Model model, const GreeState &state);
179#endif
180};
181
182class GreeClimate final : public climate_ir::ClimateIR {
183 public:
190
191#ifdef USE_GREE_FEATURE_SWITCH
192 void setup() override;
193#endif
194 void set_model(Model model);
195#ifdef USE_GREE_FAHRENHEIT
196 void set_use_fahrenheit(bool use_fahrenheit) { this->use_fahrenheit_ = use_fahrenheit; }
197#endif
198 void set_feature_state(GreeFeature feature, bool enabled);
199 bool get_feature_state(GreeFeature feature) const;
200#ifdef USE_GREE_FEATURE_SWITCH
201 void register_feature_switch(GreeFeature feature, switch_::Switch *feature_switch);
202#endif
203
204 protected:
205 void control(const climate::ClimateCall &call) override;
206 // Transmit via IR the state of this climate controller.
207 void transmit_state() override;
208#ifdef USE_GREE_RECEIVER
209 bool on_receive(remote_base::RemoteReceiveData data) override;
210#endif
211
212#ifdef USE_GREE_FEATURE_SWITCH
214#ifdef USE_GREE_RECEIVER
216#endif
217
218 std::array<switch_::Switch *, 4> feature_switches_{};
219#endif
220
222 uint8_t feature_bits_{0};
223#ifdef USE_GREE_FAHRENHEIT
224 bool use_fahrenheit_{false};
225#endif
226};
227
228} // namespace esphome::gree
BedjetMode mode
BedJet operating mode.
This class is used to encode all control actions on a climate device.
Definition climate.h:31
static optional< GreeClimateData > decode_legacy(Model model, const GreeState &state)
Definition gree.cpp:355
static GreeState encode(Model model, const GreeClimateData &data)
Definition gree.cpp:234
static uint8_t encode_fan_mode(Model model, climate::ClimateFanMode fan_mode)
Definition gree.cpp:314
static uint8_t encode_operation_mode(climate::ClimateMode mode)
Definition gree.cpp:300
static uint8_t encode_vertical_swing(climate::ClimateSwingMode swing_mode)
Definition gree.cpp:344
static uint8_t encode_horizontal_swing(climate::ClimateSwingMode swing_mode)
Definition gree.cpp:334
static optional< GreeClimateData > decode_model_a(Model model, const GreeState &state)
Definition gree.cpp:422
static optional< GreeClimateData > decode(Model model, const GreeState &state)
Decode a frame whose checksum the protocol layer already checked.
Definition gree.cpp:293
void set_use_fahrenheit(bool use_fahrenheit)
Definition gree.h:196
void publish_feature_state_(GreeFeature feature)
Definition gree.cpp:534
std::array< switch_::Switch *, 4 > feature_switches_
Definition gree.h:218
void control(const climate::ClimateCall &call) override
Definition gree.cpp:546
void setup() override
Definition gree.cpp:509
bool on_receive(remote_base::RemoteReceiveData data) override
Definition gree.cpp:585
void register_feature_switch(GreeFeature feature, switch_::Switch *feature_switch)
Definition gree.cpp:530
void set_feature_state(GreeFeature feature, bool enabled)
Definition gree.cpp:478
void set_model(Model model)
Definition gree.cpp:461
bool get_feature_state(GreeFeature feature) const
Definition gree.cpp:504
void transmit_state() override
Definition gree.cpp:559
static bool valid_checksum(const GreeState &state)
Definition gree.cpp:229
static uint8_t calculate_checksum(const GreeState &state)
Definition gree.cpp:219
void encode(remote_base::RemoteTransmitData *data, const GreeState &state) const
Definition gree.cpp:171
GreeProtocol(Model model)
Definition gree.h:147
optional< GreeState > decode(remote_base::RemoteReceiveData data) const
Definition gree.cpp:190
Base class for all switches.
Definition switch.h:43
ClimateSwingMode swing_mode
Definition climate.h:11
ClimateFanMode fan_mode
Definition climate.h:3
bool state
Definition fan.h:2
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
ClimateMode
Enum for all modes a climate device can be in.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
@ GREE_FEATURE_LIGHT
Definition gree.h:124
@ GREE_FEATURE_XFAN
Definition gree.h:126
@ GREE_FEATURE_TURBO
Definition gree.h:123
@ GREE_FEATURE_HEALTH
Definition gree.h:125
std::array< uint8_t, GREE_STATE_FRAME_SIZE > GreeState
Definition gree.h:131
@ GREE_YAC1FB9
Definition gree.h:115
@ GREE_GENERIC
Definition gree.h:111
uint8_t fahrenheit_half_steps(float target_celsius)
Return k = 2 * temp_field + half_degree_bit (0..28) for a Celsius target.
Definition gree.cpp:36
static void uint32_t
climate::ClimateMode mode
Definition gree.h:134
climate::ClimateSwingMode swing_mode
Definition gree.h:137
climate::ClimateFanMode fan_mode
Definition gree.h:136
climate::ClimatePreset preset
Definition gree.h:138