1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
| #include "MHI-AC-Ctrl-core.h"
#define ROOM_TEMP_MQTT 1
/*
Using .5 degrees with remote control. It is working as follows:
- set the setpoint with the RC to the setpoint (=x) you want to add .5 degree and wait >7 sec
(or skip this step if you already on the setpoint where you want to add .5 degree; current setpoint must be x.0 degrees)
- increase the setpoint with the RC with 1 degree (=x+1)
- slowly count to 7 (wait 6-9 seconds)
- decrease the setpoint with the RC with 1 degree (=x)
After about 5 seconds the setpoint on the AC will be x.5 degrees
If the setpoint was already n.5 degrees before, you have to do the first step first!
Of course when using the RC buttons again after above cycle, the setpoint will be again without .5 degrees.
This cycle will only work with the RC. Using climate control target temperature in between will abort this cycle.
Also doing the same steps with climate control target temperature won't add .5 degrees.
Of course you can still set the setpoint to y.5 degrees with climate control target temperature.
*/
#define ENHANCED_RESOLUTION_RC true // uncomment this to enable above function.
static const char* TAG = "mhi_ac_ctrl";
unsigned long room_temp_api_timeout_ms = millis();
#ifdef ENHANCED_RESOLUTION_RC
unsigned long previous_setpoint_set_time_Millis = millis();
float previous_setpoint = 0;
bool previous_setpoint_1_degree_up = false;
#endif
class MhiAcCtrl : public climate::Climate,
public Component,
public CallbackInterface_Status {
public:
void setup() override
{
ESP_LOGD("mhi_ac_ctrl", "setup() started");
power_status = unknown;
this->power_ = power_off;
this->current_temperature = NAN;
// restore set points
auto restore = this->restore_state_();
if (restore.has_value()) {
restore->apply(this);
} else {
// restore from defaults
this->mode = climate::CLIMATE_MODE_OFF;
// initialize target temperature to some value so that it's not NAN
this->target_temperature = clamp(this->current_temperature, this->minimum_temperature_, this->maximum_temperature_);
this->fan_mode = climate::CLIMATE_FAN_AUTO;
this->swing_mode = climate::CLIMATE_SWING_OFF;
}
// Never send nan to HA
if (isnan(this->target_temperature))
this->target_temperature = 20;
error_code_.set_icon("mdi:alert-circle");
outdoor_temperature_.set_icon("mdi:thermometer");
outdoor_temperature_.set_unit_of_measurement("°C");
outdoor_temperature_.set_accuracy_decimals(2);
return_air_temperature_.set_icon("mdi:thermometer");
return_air_temperature_.set_unit_of_measurement("°C");
return_air_temperature_.set_accuracy_decimals(2);
thi_r1_.set_icon("mdi:thermometer");
thi_r1_.set_unit_of_measurement("°C");
thi_r1_.set_accuracy_decimals(2);
thi_r2_.set_icon("mdi:thermometer");
thi_r2_.set_unit_of_measurement("°C");
thi_r2_.set_accuracy_decimals(2);
thi_r3_.set_icon("mdi:thermometer");
thi_r3_.set_unit_of_measurement("°C");
thi_r3_.set_accuracy_decimals(2);
tho_r1_.set_icon("mdi:thermometer");
tho_r1_.set_unit_of_measurement("°C");
tho_r1_.set_accuracy_decimals(2);
tdsh_.set_icon("mdi:air-filter");
tdsh_.set_unit_of_measurement("°C");
tdsh_.set_accuracy_decimals(1);
opdata_Tsetpoint_.set_icon("mdi:thermometer");
opdata_Tsetpoint_.set_unit_of_measurement("°C");
opdata_Tsetpoint_.set_accuracy_decimals(1);
fan_speed_.set_icon("mdi:fan");
outdoor_unit_fan_speed_.set_icon("mdi:fan");
indoor_unit_fan_speed_.set_icon("mdi:fan");
compressor_frequency_.set_icon("mdi:sine-wave");
compressor_frequency_.set_unit_of_measurement("Hz");
compressor_frequency_.set_accuracy_decimals(1);
indoor_unit_total_run_time_.set_icon("mdi:clock");
indoor_unit_total_run_time_.set_unit_of_measurement("h");
compressor_total_run_time_.set_icon("mdi:clock");
compressor_total_run_time_.set_unit_of_measurement("h");
current_power_.set_icon("mdi:current-ac");
current_power_.set_unit_of_measurement("A");
current_power_.set_accuracy_decimals(2);
defrost_.set_icon("mdi:snowflake-melt");
vanes_pos_.set_icon("mdi:air-filter");
mhi_ac_ctrl_core.MHIAcCtrlStatus(this);
mhi_ac_ctrl_core.init();
}
void loop() override
{
if(millis() - room_temp_api_timeout_ms >= id(room_temp_api_timeout)*1000) {
mhi_ac_ctrl_core.set_troom(0xff); // use IU temperature sensor
room_temp_api_timeout_ms = millis();
ESP_LOGD("mhi_ac_ctrl", "did not receive a room_temp_api value, using IU temperature sensor");
}
int ret = mhi_ac_ctrl_core.loop(100);
if (ret < 0)
ESP_LOGW("mhi_ac_ctrl", "mhi_ac_ctrl_core.loop error: %i", ret);
}
void dump_config() override
{
LOG_CLIMATE("", "MHI-AC-Ctrl Climate", this);
ESP_LOGCONFIG(TAG, " Min. Temperature: %.1f°C", this->minimum_temperature_);
ESP_LOGCONFIG(TAG, " Max. Temperature: %.1f°C", this->maximum_temperature_);
ESP_LOGCONFIG(TAG, " Supports HEAT: %s", YESNO(true));
ESP_LOGCONFIG(TAG, " Supports COOL: %s", YESNO(true));
}
void cbiStatusFunction(ACStatus status, int value) override
{
float tmp_value;
float offset = mhi_ac_ctrl_core.get_troom_offset();
static int mode_tmp = 0xff;
ESP_LOGD("mhi_ac_ctrl", "received status=%i value=%i power=%i", status, value, this->power_);
if (this->power_ == power_off) {
// Workaround for status after reboot
this->mode = climate::CLIMATE_MODE_OFF;
this->publish_state();
}
switch (status) {
case status_power:
// After powerdown AC (230V), fan status is only showing 1, 2 or 3. 4 and Auto is not shown when changing with RC.
// Only when setting fan to Auto one time after powerdown AC, it will show 4 and Auto.
// Below will take care of this.
if (power_status == unknown) { // First time after startup esp
ESP_LOGD("mhi_ac_ctrl", "power_status: unknown; received status_power: %i", value);
if (value == power_off) { // Only when status is power off, set fan to Auto.
ESP_LOGD("mhi_ac_ctrl", "Set fan to Auto to fix fan status after powerdown (230V) AC");
mhi_ac_ctrl_core. set_fan(7);
}
} else if (power_status == off)
ESP_LOGD("mhi_ac_ctrl", "power_status: off; received status_power: %i", value);
else if (power_status == on)
ESP_LOGD("mhi_ac_ctrl", "power_status: on; received status_power: %i", value);
if (value == power_on) {
this->power_ = power_on;
// output_P(status, (TOPIC_POWER), PSTR(PAYLOAD_POWER_ON));
cbiStatusFunction(status_mode, mode_tmp);
power_status = on;
} else {
// output_P(status, (TOPIC_POWER), (PAYLOAD_POWER_OFF));
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_OFF));
this->power_ = power_off;
this->mode = climate::CLIMATE_MODE_OFF;
this->publish_state();
power_status = off;
}
break;
case status_mode:
mode_tmp = value;
case opdata_mode:
case erropdata_mode:
switch (value) {
case mode_auto:
// if (status != erropdata_mode)
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_AUTO));
// else
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_STOP));
// break;
if (status != erropdata_mode && this->power_ > 0) {
this->mode = climate::CLIMATE_MODE_HEAT_COOL;
} else {
this->mode = climate::CLIMATE_MODE_OFF;
}
break;
case mode_dry:
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_DRY));
this->mode = climate::CLIMATE_MODE_DRY;
break;
case mode_cool:
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_COOL));
this->mode = climate::CLIMATE_MODE_COOL;
break;
case mode_fan:
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_FAN));
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
break;
case mode_heat:
// output_P(status, PSTR(TOPIC_MODE), PSTR(PAYLOAD_MODE_HEAT));
this->mode = climate::CLIMATE_MODE_HEAT;
break;
default:
ESP_LOGD("mhi_ac_ctrl", "unknown status mode value %i", value);
}
this->publish_state();
break;
case status_fan:
switch (value) {
case 0:
this->fan_mode = climate::CLIMATE_FAN_LOW;
fan_speed_.publish_state("1");
break;
case 1:
this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
fan_speed_.publish_state("2");
break;
case 2:
this->fan_mode = climate::CLIMATE_FAN_MEDIUM;
fan_speed_.publish_state("3");
break;
case 6:
this->fan_mode = climate::CLIMATE_FAN_HIGH;
fan_speed_.publish_state("4");
break;
case 7:
this->fan_mode = climate::CLIMATE_FAN_AUTO;
fan_speed_.publish_state("Auto");
break;
}
this->publish_state();
break;
case status_vanes:
switch (value) {
case vanes_swing:
// output_P(status, PSTR(TOPIC_VANES), PSTR(PAYLOAD_VANES_SWING));
this->swing_mode = climate::CLIMATE_SWING_VERTICAL;
break;
default:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_VANES), strtmp);
this->swing_mode = climate::CLIMATE_SWING_OFF;
}
vanes_pos_.publish_state(value);
this->publish_state();
break;
case status_troom:
// dtostrf((value - 61) / 4.0, 0, 2, strtmp);
// output_P(status, PSTR(TOPIC_TROOM), strtmp);
this->current_temperature = ((value - 61) / 4.0);
this->current_temperature = this->current_temperature - mhi_ac_ctrl_core.get_troom_offset();
ESP_LOGD("mhi_ac_ctrl", "status_troom received: %f with already substracted offset: %f", this->current_temperature, mhi_ac_ctrl_core.get_troom_offset());
this->publish_state();
break;
case status_tsetpoint:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_TSETPOINT), strtmp);
tmp_value = (value & 0x7f)/ 2.0;
#ifdef ENHANCED_RESOLUTION_RC
if (((round(tmp_value) - tmp_value) == 0.0f ) ) { // only when x.0 degrees
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: Start checking setpoint cycle. Previous setpoint: %f New setpoint: %f", previous_setpoint, tmp_value);
if (!previous_setpoint_1_degree_up) { // if cycle is not started
if ( (tmp_value - previous_setpoint) == 1 ) { // new setpoint is 1 degree higher; start cycle
previous_setpoint_1_degree_up = true; // start cycle
previous_setpoint_set_time_Millis = millis();
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: Setpoint cycle detect started");
} else {
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: No setpoint cycle");
}
} else { // cycle was started before
if (((tmp_value - previous_setpoint) == -1) & (millis() - previous_setpoint_set_time_Millis <= 10*1000 ) ) { // new setpoint 1 degree lower when cycle detected in 10s
// cycle +1 and -1 degree detected -> use setpoint + 0.5 degree
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: Setpoint cycle detected. Add .5 degrees to setpoint");
previous_setpoint_1_degree_up = false; // end cycle
mhi_ac_ctrl_core.set_tsetpoint((byte)(2 * (tmp_value + 0.5))); // adjust setpoint
} else { // no -1 degree or outside time cycle
previous_setpoint_1_degree_up = false; // reset cycle
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: Setpoint cycle reset");
}
}
} else { // when x.5 degrees
previous_setpoint_1_degree_up = false; // reset cycle when setpoint is x.5 degrees
ESP_LOGD("mhi_ac_ctrl", "status_tsetpoint: Setpoint cycle reset because of setpoint is x.5 degrees");
}
previous_setpoint = tmp_value;
#endif
offset = round(tmp_value) - tmp_value; // Calculate offset when setpoint is changed
mhi_ac_ctrl_core.set_troom_offset(offset);
ESP_LOGD("mhi_ac_ctrl", "set_troom_offset: %f Target temperature: %f", offset, tmp_value);
this->target_temperature = (value & 0x7f)/ 2.0;
this->publish_state();
break;
case erropdata_tsetpoint:
case opdata_tsetpoint:
// dtostrf((value & 0x7f)/ 2.0, 0, 1, strtmp);
// output_P(status, PSTR(TOPIC_TSETPOINT), strtmp);
opdata_Tsetpoint_.publish_state((value & 0x7f) / 2.0);
break;
case status_errorcode:
case erropdata_errorcode:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_ERRORCODE), strtmp);
error_code_.publish_state(value);
break;
case opdata_return_air:
case erropdata_return_air:
// dtostrf((value - 61) / 4.0, 0, 2, strtmp);
// output_P(status, PSTR(TOPIC_RETURNAIR), strtmp);
return_air_temperature_.publish_state((value - 61) / 4.0);
break;
case opdata_thi_r1:
case erropdata_thi_r1:
// 20221116 activated
// itoa(0.327f * value - 11.4f, strtmp, 10); // only rough approximation
// output_P(status, PSTR(TOPIC_THI_R1), strtmp);
thi_r1_.publish_state(value * 0.327f - 11.4f);
//this->publish_state();
break;
case opdata_thi_r2:
case erropdata_thi_r2:
// 20221116 activated
// itoa(0.327f * value - 11.4f, strtmp, 10); // formula for calculation not known
// output_P(status, PSTR(TOPIC_THI_R2), strtmp);
thi_r2_.publish_state(value * 0.327f - 11.4f);
//this->publish_state();
break;
case opdata_thi_r3:
case erropdata_thi_r3:
// 20221116 activated
// itoa(0.327f * value - 11.4f, strtmp, 10); // only rough approximation
// output_P(status, PSTR(TOPIC_THI_R3), strtmp);
thi_r3_.publish_state(value * 0.327f - 11.4f);
//this->publish_state();
break;
case opdata_iu_fanspeed:
case erropdata_iu_fanspeed:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_IU_FANSPEED), strtmp);
indoor_unit_fan_speed_.publish_state(value);
break;
case opdata_total_iu_run:
case erropdata_total_iu_run:
// itoa(value * 100, strtmp, 10);
// output_P(status, PSTR(TOPIC_TOTAL_IU_RUN), strtmp);
indoor_unit_total_run_time_.publish_state(value * 100);
break;
case erropdata_outdoor:
case opdata_outdoor:
// dtostrf((value - 94) * 0.25f, 0, 2, strtmp);
// output_P(status, PSTR(TOPIC_OUTDOOR), strtmp);
outdoor_temperature_.publish_state((value - 94) * 0.25f);
break;
case opdata_tho_r1:
case erropdata_tho_r1:
// 20221116 activated
// itoa(0.327f * value - 11.4f, strtmp, 10); // formula for calculation not known
// output_P(status, PSTR(TOPIC_THO_R1), strtmp);
tho_r1_.publish_state(value * 0.327f - 11.4f);
break;
case opdata_comp:
case erropdata_comp:
// dtostrf(
// highByte(value) * 25.6f + 0.1f * lowByte(value), 0, 2, strtmp); // to be confirmed
// output_P(status, PSTR(TOPIC_COMP), strtmp);
compressor_frequency_.publish_state(highByte(value) * 25.6f + 0.1f * lowByte(value));
break;
case erropdata_td:
case opdata_td:
// if (value < 0x12)
// strcpy(strtmp, "<=30");
// else
// itoa(value / 2 + 32, strtmp, 10);
// output_P(status, PSTR(TOPIC_TD), strtmp);
break;
case opdata_ct:
case erropdata_ct:
// 20221116 changed
// dtostrf(value * 14 / 51.0f, 0, 2, strtmp);
// output_P(status, PSTR(TOPIC_CT), strtmp);
//this->current_power = (value * 14 / 51.0f);
//this->publish_state();
current_power_.publish_state(value * 14 / 51.0f);
break;
case opdata_tdsh:
// itoa(value, strtmp, 10); // formula for calculation not known
// output_P(status, PSTR(TOPIC_TDSH), strtmp);
// 20221118 publish uitgezet en nu alleen via een YAML techSenor te publiseren
//this->tdsh_ = {value * 0.327f - 11.4f};
tdsh_.publish_state(value * 0.327f - 11.4f);
break;
case opdata_protection_no:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_PROTECTION_NO), strtmp);
break;
case opdata_ou_fanspeed:
case erropdata_ou_fanspeed:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_OU_FANSPEED), strtmp);
outdoor_unit_fan_speed_.publish_state(value);
break;
case opdata_defrost:
// if (value)
// output_P(status, PSTR(TOPIC_DEFROST), PSTR(PAYLOAD_OP_DEFROST_ON));
// else
// output_P(status, PSTR(TOPIC_DEFROST), PSTR(PAYLOAD_OP_DEFROST_OFF));
defrost_.publish_state(value != 0);
break;
case opdata_total_comp_run:
case erropdata_total_comp_run:
// itoa(value * 100, strtmp, 10);
// output_P(status, PSTR(TOPIC_TOTAL_COMP_RUN), strtmp);
compressor_total_run_time_.publish_state(value * 100);
break;
case opdata_ou_eev1:
case erropdata_ou_eev1:
// itoa(value, strtmp, 10);
// output_P(status, PSTR(TOPIC_OU_EEV1), strtmp);
break;
// case opdata_tsetpoint:
// case erropdata_tsetpoint:
case opdata_0x94:
case opdata_unknown:
// skip these values as they are not used currently
break;
}
}
std::vector<Sensor *> get_sensors() {
return {
&error_code_,
&outdoor_temperature_,
&return_air_temperature_,
&outdoor_unit_fan_speed_,
&indoor_unit_fan_speed_,
¤t_power_,
&compressor_frequency_,
&indoor_unit_total_run_time_,
&compressor_total_run_time_,
&vanes_pos_
};
}
std::vector<Sensor *> get_tech_sensors() {
return {
&thi_r1_,
&thi_r2_,
&thi_r3_,
&tho_r1_,
&tdsh_,
&opdata_Tsetpoint_
};
}
std::vector<BinarySensor *> get_binary_sensors() {
return { &defrost_ };
}
std::vector<TextSensor *> get_text_sensors() {
return { &fan_speed_ };
}
void set_room_temperature(float value) {
value = value + mhi_ac_ctrl_core.get_troom_offset() ; // increase Troom with current offset to compensate higher setpoint
if ((value > -10) & (value < 48)) {
room_temp_api_timeout_ms = millis(); // reset timeout
byte tmp = value*4+61;
mhi_ac_ctrl_core.set_troom(tmp);
ESP_LOGD("mhi_ac_ctrl", "set room_temp_api: %f %i with already added offset: %f Resulting set_troom: %f", value, (byte)tmp, mhi_ac_ctrl_core.get_troom_offset(), (float)((tmp - 61) / 4.0));
}
}
void set_vanes(int value) {
mhi_ac_ctrl_core.set_vanes(value);
ESP_LOGD("mhi_ac_ctrl", "set vanes: %i", value);
}
void set_fan(int value) {
mhi_ac_ctrl_core.set_fan(value);
ESP_LOGD("mhi_ac_ctrl", "set fan: %i", value);
}
protected:
/// Transmit the state of this climate controller.
void control(const climate::ClimateCall& call) override
{
if (call.get_mode().has_value()) {
this->mode = *call.get_mode();
power_ = power_on;
switch (this->mode) {
case climate::CLIMATE_MODE_OFF:
power_ = power_off;
break;
case climate::CLIMATE_MODE_COOL:
mode_ = mode_cool;
break;
case climate::CLIMATE_MODE_HEAT:
mode_ = mode_heat;
break;
case climate::CLIMATE_MODE_DRY:
mode_ = mode_dry;
break;
case climate::CLIMATE_MODE_FAN_ONLY:
mode_ = mode_fan;
break;
case climate::CLIMATE_MODE_HEAT_COOL:
default:
mode_ = mode_auto;
break;
}
mhi_ac_ctrl_core.set_power(power_);
mhi_ac_ctrl_core.set_mode(mode_);
}
if (call.get_target_temperature().has_value()) {
this->target_temperature = *call.get_target_temperature();
tsetpoint_ = (float)clamp(this->target_temperature, minimum_temperature_, maximum_temperature_);
mhi_ac_ctrl_core.set_tsetpoint((byte)(2 * tsetpoint_));
ESP_LOGD("mhi_ac_ctrl", "Control target_temperature: %f set_tsetpoint: %f", this->target_temperature, tsetpoint_);
#ifdef ENHANCED_RESOLUTION_RC
ESP_LOGD("mhi_ac_ctrl", "control: Setpoint cycle reset");
previous_setpoint_1_degree_up = false; // Never use cycle detection when setpoint is set by MQTT
#endif
}
if (call.get_fan_mode().has_value()) {
this->fan_mode = *call.get_fan_mode();
switch (*this->fan_mode) {
case climate::CLIMATE_FAN_LOW:
fan_ = 0;
break;
case climate::CLIMATE_FAN_MEDIUM:
fan_ = 1;
break;
case climate::CLIMATE_FAN_HIGH:
fan_ = 6;
break;
case climate::CLIMATE_FAN_AUTO:
default:
fan_ = 7;
break;
}
mhi_ac_ctrl_core.set_fan(fan_);
}
if (call.get_swing_mode().has_value()) {
this->swing_mode = *call.get_swing_mode();
switch (this->swing_mode) {
case climate::CLIMATE_SWING_VERTICAL:
mhi_ac_ctrl_core.set_vanes(vanes_);
vanes_ = vanes_swing;
break;
default:
case climate::CLIMATE_SWING_OFF:
vanes_ = vanes_unknown;
mhi_ac_ctrl_core.set_vanes(vanes_);
break;
}
}
this->publish_state();
}
/// Return the traits of this controller.
climate::ClimateTraits traits() override
{
auto traits = climate::ClimateTraits();
traits.set_supports_current_temperature(true);
traits.set_supported_modes({ CLIMATE_MODE_OFF, CLIMATE_MODE_HEAT_COOL, CLIMATE_MODE_COOL, CLIMATE_MODE_HEAT, CLIMATE_MODE_DRY, CLIMATE_MODE_FAN_ONLY });
traits.set_supports_two_point_target_temperature(false);
traits.set_visual_min_temperature(this->minimum_temperature_);
traits.set_visual_max_temperature(this->maximum_temperature_);
traits.set_visual_temperature_step(this->temperature_step_);
traits.set_supported_fan_modes({ CLIMATE_FAN_AUTO, CLIMATE_FAN_LOW, CLIMATE_FAN_MEDIUM, CLIMATE_FAN_HIGH });
traits.set_supported_swing_modes({ CLIMATE_SWING_OFF, CLIMATE_SWING_VERTICAL });
return traits;
}
float minimum_temperature_ { 18.0f };
float maximum_temperature_ { 30.0f };
float temperature_step_ { 0.5f };
ACPower power_;
ACMode mode_;
float tsetpoint_;
uint fan_;
ACVanes vanes_;
MHI_AC_Ctrl_Core mhi_ac_ctrl_core;
Sensor error_code_;
Sensor outdoor_temperature_;
Sensor return_air_temperature_;
Sensor outdoor_unit_fan_speed_;
Sensor indoor_unit_fan_speed_;
Sensor compressor_frequency_;
Sensor indoor_unit_total_run_time_;
Sensor compressor_total_run_time_;
Sensor current_power_;
BinarySensor defrost_;
Sensor vanes_pos_;
Sensor thi_r1_;
Sensor thi_r2_;
Sensor thi_r3_;
Sensor tho_r1_;
Sensor tdsh_;
Sensor opdata_Tsetpoint_;
TextSensor fan_speed_;
enum POWER_STATUS
{
unknown,
off,
on
} power_status;
}; |