Skip to content

Commit f5fafea

Browse files
Merge pull request #159 from RobertJansen1/pin_yaml
v4.2
2 parents 29ec617 + abd19c7 commit f5fafea

File tree

7 files changed

+66
-13
lines changed

7 files changed

+66
-13
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Create a new device within ESPHome builder and combine the yaml with one of the
1313
# MHI-AC-Ctrl-ESPHome
1414
This project is a simple integration of the amazing work [absalom-muc](https://github.com/absalom-muc) has done with his project [MHI-AC-Ctrl](https://github.com/absalom-muc/MHI-AC-Ctrl).\
1515
It's supposed to simplify the [Home Assistant](https://www.home-assistant.io/) setup, while giving you OTA and auto-discovery with virtually zero effort and no MQTT needed, powered by [ESPHome](https://ESPHome.io/).\
16-
`MHI-AC-Ctrl-core.*` files were forked directly, with no modification, whereas your WiFi credentials should go into the `*.yaml` file, and `mhi_ac_ctrl.h` is the core of the integration.
16+
`MHI-AC-Ctrl-core.*` files were forked directly, with a small modification to allow for pin setting in yaml, whereas your WiFi credentials should go into the `*.yaml` file, and `mhi_ac_ctrl.h` is the core of the integration.
1717

1818
# Fan Modes Up/Down Left/Right
1919
Most newer MHI units (the ones supporting the WF-RAC WiFi module) support fine grained vane control for Left/Right and Up/Down.
@@ -52,13 +52,18 @@ This will allow for lower temperature heating or cooling.
5252
# Changelog:
5353
5454
55+
**v4.2** (2025-07)
56+
- Allow configuration of pins through yaml
57+
- Update calculation of Indoor Heat exchanger temperature 2 (capillary)
58+
- Don't spam unit with unchanged room_temp
59+
- **Deprecating set set_vertical_vanes and set_horizontal_vanes, will be removed in v4.3 use select functions for fan control**
5560
5661
**v4.1** (2025-07)
5762
- Changed climate.CLIMATE_SCHEMA to fix deprecation warning in 2025.5.0 and higher https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/issues/151
5863
- Make 0.5 degrees setpoint actually work https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/issues/88
5964
- Allow low temp heating and cooling (below 18 degrees) https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/issues/152
60-
- Allow fan speed from ESPHome web interface https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/issues/136
61-
- Deprecating set set_vertical_vanes and set_horizontal_vanes, will be removed in v4.2 use select functions for fan control
65+
- Allow fan speed from esphome web interface https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/issues/136
66+
- Deprecating set set_vertical_vanes and set_horizontal_vanes, will be removed in v4.3 use select functions for fan control
6267
6368
**v4.0** (2025-04)
6469
- Compatibility with ESPHOME 2025.2+

components/MhiAcCtrl/MHI-AC-Ctrl-core.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ const byte opdata[][2] PROGMEM = {
3131
#define NoFramesPerOpDataCycle 400 // number of frames used for a OpData request cycle; will be 20s (20 frames are 1s)
3232
#define minTimeInternalTroom 5000 // minimal time in ms used for Troom internal sensor changes for publishing to avoid jitter
3333

34-
// pin defintions
35-
#define SCK_PIN 14
36-
#define MOSI_PIN 13
37-
#define MISO_PIN 12
34+
// Declare extern variables for the pins the only change to the original code
35+
// This allows to set the pins in the configuration file
36+
extern int SCK_PIN;
37+
extern int MOSI_PIN;
38+
extern int MISO_PIN;
3839

3940
// constants for the frame
4041
#define SB0 0

components/MhiAcCtrl/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
CONF_ROOM_TEMP_TIMEOUT = 'room_temp_timeout'
1010
CONF_VANES_UD = 'initial_vertical_vanes_position'
1111
CONF_VANES_LR = 'initial_horizontal_vanes_position'
12+
CONF_SCK_PIN = "sck_pin"
13+
CONF_MOSI_PIN = "mosi_pin"
14+
CONF_MISO_PIN = "miso_pin"
1215

1316
CONF_VANES_POSITION = 'position'
1417
CONF_TEMPERATURE = 'temperature'
@@ -28,6 +31,9 @@
2831
cv.Optional(CONF_ROOM_TEMP_TIMEOUT, default=60): cv.int_range(min=0, max=3600),
2932
cv.Optional(CONF_VANES_UD): cv.int_range(min=0, max=5),
3033
cv.Optional(CONF_VANES_LR): cv.int_range(min=0, max=8),
34+
cv.Optional(CONF_SCK_PIN): cv.int_,
35+
cv.Optional(CONF_MOSI_PIN): cv.int_,
36+
cv.Optional(CONF_MISO_PIN): cv.int_,
3137
}).extend(cv.COMPONENT_SCHEMA)
3238

3339
async def to_code(config):
@@ -42,7 +48,12 @@ async def to_code(config):
4248
cg.add(var.set_vanes(config[CONF_VANES_UD]))
4349
if CONF_VANES_LR in config:
4450
cg.add(var.set_vanesLR(config[CONF_VANES_LR]))
45-
51+
if CONF_SCK_PIN in config:
52+
cg.add(var.set_sck_pin(config[CONF_SCK_PIN]))
53+
if CONF_MOSI_PIN in config:
54+
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
55+
if CONF_MISO_PIN in config:
56+
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
4657

4758
@automation.register_action(
4859
"climate.mhi.set_vertical_vanes",

components/MhiAcCtrl/mhi_platform.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
#include "mhi_platform.h"
22

3+
int SCK_PIN = 14;
4+
int MOSI_PIN = 13;
5+
int MISO_PIN = 12;
36
namespace esphome {
47
namespace mhi {
58

69
static const char* TAG = "mhi.platform";
710

11+
812
void MhiPlatform::setup() {
913

14+
if (this->sck_pin_ >= 0) { //
15+
SCK_PIN = this->sck_pin_;
16+
}
17+
if (this->mosi_pin_ >= 0) { //
18+
MOSI_PIN = this->mosi_pin_;
19+
}
20+
if (this->miso_pin_ >= 0) { //
21+
MISO_PIN = this->miso_pin_;
22+
}
23+
1024
this->mhi_ac_ctrl_core_.MHIAcCtrlStatus(this);
1125
this->mhi_ac_ctrl_core_.init();
1226
this->mhi_ac_ctrl_core_.set_frame_size(this->frame_size_); // set framesize. Only 20 (legacy) or 33 (includes 3D auto and vertical vanes) possible
@@ -78,12 +92,22 @@ void MhiPlatform::set_room_temperature(float value) {
7892

7993
void MhiPlatform::transfer_room_temperature(float value) {
8094
if (isnan(value)) {
81-
mhi_ac_ctrl_core_.set_troom(0xff); // reset target, use internal sensor
95+
if (!isnan(this->last_room_temperature_)) {
96+
ESP_LOGD(TAG, "set room_temp_api: value is NaN, using internal sensor");
97+
mhi_ac_ctrl_core_.set_troom(0xff); // reset target, use internal sensor
98+
this->last_room_temperature_ = NAN; // reset last room temperature
99+
}
100+
return;
101+
}
102+
103+
if (fabs(value - last_room_temperature_) < 0.01) {
104+
return;
82105
}
83106

84107
if ((value > -10) & (value < 48)) {
85108
byte tmp = value * 4 + 61;
86-
this->mhi_ac_ctrl_core_.set_troom(value * 4 + 61);
109+
this->mhi_ac_ctrl_core_.set_troom(value * 4 + 61);
110+
this->last_room_temperature_ = value; // store last room temperature
87111
ESP_LOGD(TAG, "set room_temp_api: %f %i %i", value, (byte)(value * 4 + 61), (byte)tmp);
88112
}
89113
}

components/MhiAcCtrl/mhi_platform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,23 @@ class MhiPlatform :
3434
void set_vanesLR(int value);
3535
void set_3Dauto(bool value);
3636
void set_external_room_temperature_sensor(sensor::Sensor* sensor);
37+
void set_sck_pin(int pin) { this->sck_pin_ = pin; };
38+
void set_mosi_pin(int pin) { this->mosi_pin_ = pin; };
39+
void set_miso_pin(int pin) { this->miso_pin_ = pin; };
3740
void add_listener(MhiStatusListener* listener);
3841

3942

4043
private:
4144
void transfer_room_temperature(float value);
45+
float last_room_temperature_ = NAN;
4246

4347
int frame_size_;
4448
unsigned long room_temp_api_timeout_start_ = millis();
4549
unsigned long room_temp_api_timeout_;
4650
bool room_temp_api_active_ = false;
51+
int sck_pin_ = -1;
52+
int mosi_pin_ = -1;
53+
int miso_pin_ = -1;
4754

4855
MHI_AC_Ctrl_Core mhi_ac_ctrl_core_;
4956

components/MhiAcCtrl/sensor/mhi_sensors.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ void MhiSensors::update_status(ACStatus status, int value) {
138138
// output_P(status, PSTR(TOPIC_THI_R1), strtmp);
139139
break;
140140
case opdata_thi_r2:
141-
// Indoor Heat exchanger temperature 2 (capillary)
141+
// Indoor Heat exchanger temperature 2 (capillary)
142+
// 2025-07-08: Renewed calculation, needs to be confirmed
143+
// previously it was 0.327f * value - 11.4f, which is not correct
142144
if (this->indoor_unit_thi_r2_ != NULL) {
143-
this->indoor_unit_thi_r2_ -> publish_state(0.327f * value - 11.4f);
145+
this->indoor_unit_thi_r2_ -> publish_state(0.275f * value - 47.0f);
144146
}
145147
break;
146148
case erropdata_thi_r2:

examples/full.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ api:
4545
- climate.mhi.set_external_room_temperature:
4646
temperature: !lambda "return temperature_value;"
4747

48-
# Version 4.1
48+
# Version 4.2
4949

5050
MhiAcCtrl:
5151
# Only 20 (legacy) or 33 (includes 3D auto and vertical vanes) possible.
5252
# If you encounter mhi_ac_ctrl_core.loop error: -2 errors, change the frame_size to 20
5353
frame_size: 33
54+
sck_pin: 14
55+
mosi_pin: 13
56+
miso_pin: 12
5457
initial_vertical_vanes_position: 5
5558
initial_horizontal_vanes_position: 8
5659
# Update the following to change the default room temp timeout

0 commit comments

Comments
 (0)