diff --git a/components/cn105/Globals.h b/components/cn105/Globals.h index 4cb8371..68a5095 100644 --- a/components/cn105/Globals.h +++ b/components/cn105/Globals.h @@ -189,7 +189,7 @@ struct wantedHeatpumpSettings : heatpumpSettings { hasChanged = false; hasBeenSent = false; //nb_deffered_requests = 0; - //lastChange = 0; + //lastChange = 0; } wantedHeatpumpSettings& operator=(const wantedHeatpumpSettings& other) { @@ -203,7 +203,7 @@ struct wantedHeatpumpSettings : heatpumpSettings { wantedHeatpumpSettings& operator=(const heatpumpSettings& other) { if (this != &other) { // self-assignment protection - heatpumpSettings::operator=(other); // Copie des membres de base + heatpumpSettings::operator=(other); // Copie des membres de base } return *this; } @@ -247,7 +247,7 @@ struct heatpumpStatus { float outsideAirTemperature; bool operating; // if true, the heatpump is operating to reach the desired temperature heatpumpTimers timers; - int compressorFrequency; + float compressorFrequency; bool operator==(const heatpumpStatus& other) const { return roomTemperature == other.roomTemperature && diff --git a/components/cn105/cn105.cpp b/components/cn105/cn105.cpp index c54ce7d..ba6acb4 100644 --- a/components/cn105/cn105.cpp +++ b/components/cn105/cn105.cpp @@ -36,7 +36,7 @@ CN105Climate::CN105Climate(uart::UARTComponent* uart) : this->powerRequestWithoutResponses = 0; // power request is not supported by all heatpump #112 - this->remote_temp_timeout_ = 4294967295; // uint32_t max + this->remote_temp_timeout_ = 4294967295; // uint32_t max this->generateExtraComponents(); this->loopCycle.init(); this->wantedSettings.resetSettings(); @@ -71,7 +71,7 @@ void CN105Climate::set_remote_temp_timeout(uint32_t timeout) { if (timeout == 4294967295) { ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to never."); } else { - //ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to %lu", timeout); + //ESP_LOGI(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to %lu", timeout); log_info_uint32(LOG_ACTION_EVT_TAG, "set_remote_temp_timeout is set to ", timeout); this->pingExternalTemperature(); @@ -84,7 +84,7 @@ void CN105Climate::set_debounce_delay(uint32_t delay) { log_info_uint32(LOG_ACTION_EVT_TAG, "set_debounce_delay is set to ", delay); } -int CN105Climate::get_compressor_frequency() { +float CN105Climate::get_compressor_frequency() { return currentStatus.compressorFrequency; } bool CN105Climate::is_operating() { @@ -173,7 +173,7 @@ bool CN105Climate::isHeatpumpConnectionActive() { // if (lrTimeMs > MAX_DELAY_RESPONSE_FACTOR * this->update_interval_) { // ESP_LOGV(TAG, "Heatpump has not replied for %ld s", lrTimeMs / 1000); // ESP_LOGV(TAG, "We think Heatpump is not connected anymore.."); - // this->disconnectUART(); + // this->disconnectUART(); // } return (lrTimeMs < MAX_DELAY_RESPONSE_FACTOR * this->update_interval_); diff --git a/components/cn105/cn105.h b/components/cn105/cn105.h index 079c65c..cf90a9c 100644 --- a/components/cn105/cn105.h +++ b/components/cn105/cn105.h @@ -59,10 +59,10 @@ class CN105Climate : public climate::Climate, public Component, public uart::UAR sensor::Sensor* outside_air_temperature_sensor_ = nullptr; // Outside air temperature - // sensor to monitor heatpump connection time + // sensor to monitor heatpump connection time uptime::HpUpTimeConnectionSensor* hp_uptime_connection_sensor_ = nullptr; - int get_compressor_frequency(); + float get_compressor_frequency(); bool is_operating(); // checks if the field has changed diff --git a/components/cn105/hp_readings.cpp b/components/cn105/hp_readings.cpp index 5dfe151..aa1f8ef 100644 --- a/components/cn105/hp_readings.cpp +++ b/components/cn105/hp_readings.cpp @@ -118,7 +118,7 @@ void CN105Climate::processDataPacket() { if (this->checkSum()) { // checkPoint of a heatpump response - this->lastResponseMs = CUSTOM_MILLIS; //esphome::CUSTOM_MILLIS; + this->lastResponseMs = CUSTOM_MILLIS; //esphome::CUSTOM_MILLIS; // processing the specific command processCommand(); @@ -172,7 +172,7 @@ void CN105Climate::getSettingsFromResponsePacket() { heatpumpSettings receivedSettings{}; ESP_LOGD("Decoder", "[0x02 is settings]"); //02 00 00 01 08 0A 00 07 00 00 03 AA 00 00 00 00 94 - //this->last_received_packet_sensor->publish_state("0x62-> 0x02: Data -> Settings"); + //this->last_received_packet_sensor->publish_state("0x62-> 0x02: Data -> Settings"); receivedSettings.connected = true; // we're here so we're connected (actually not used property) receivedSettings.power = lookupByteMapValue(POWER_MAP, POWER, 2, data[3], "power reading"); receivedSettings.iSee = data[4] > 0x08 ? true : false; @@ -228,6 +228,7 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() { //ESP_LOGD("Decoder", "[0x03 room temperature]"); //this->last_received_packet_sensor->publish_state("0x62-> 0x03: Data -> Room temperature"); + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // FC 62 01 30 10 03 00 00 0E 00 94 B0 B0 FE 42 00 01 0A 64 00 00 A9 // RT OT RT SP ?? ?? ?? CT CT @@ -236,11 +237,12 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() { // SP = room setpoint temperature? // CT = increasing counter (unknown function) - if (data[5] != 0x00) - receivedStatus.outsideAirTemperature = (float)(data[5] - 128) / 2; - else - receivedStatus.outsideAirTemperature = -1; - + if (data[5] != 0x00) { + receivedStatus.outsideAirTemperature = (float)(data[5] - 128) / 2; + } else { + receivedStatus.outsideAirTemperature = -1; + } + if (data[6] != 0x00) { int temp = data[6]; temp -= 128; @@ -256,10 +258,18 @@ void CN105Climate::getRoomTemperatureFromResponsePacket() { receivedStatus.operating = currentStatus.operating; receivedStatus.compressorFrequency = currentStatus.compressorFrequency; this->statusChanged(receivedStatus); - } + void CN105Climate::getOperatingAndCompressorFreqFromResponsePacket() { //FC 62 01 30 10 06 00 00 1A 01 00 00 00 00 00 00 00 00 00 00 00 3C + //MSZ-RW25VGHZ-SC1 / MUZ-RW25VGHZ-SC1 + //FC 62 01 30 10 06 00 00 00 01 00 08 05 50 00 00 42 00 00 00 00 B7 + // OP CF CF ?? CT ?? + // OP = operating status (1 = compressor running, 0 = standby) + // CF = compressor frequency in 16-bit integer, 1 decimal accuracy + // (frequency in float = value / 10) + // CT = slowly increasing counter, unknown function + // ?? = unknown bytes that appear to have a fixed/constant value heatpumpStatus receivedStatus{}; ESP_LOGD("Decoder", "[0x06 is status]"); //this->last_received_packet_sensor->publish_state("0x62-> 0x06: Data -> Heatpump Status"); @@ -267,7 +277,10 @@ void CN105Climate::getOperatingAndCompressorFreqFromResponsePacket() { // reset counter (because a reply indicates it is connected) this->nonResponseCounter = 0; receivedStatus.operating = data[4]; - receivedStatus.compressorFrequency = data[3]; + if (data[5] || data[6]) + receivedStatus.compressorFrequency = (float)((data[5] << 8) | data[6]) / 10; + else + receivedStatus.compressorFrequency = (float)data[3]; // no change with this packet to roomTemperature receivedStatus.roomTemperature = currentStatus.roomTemperature; @@ -296,7 +309,7 @@ void CN105Climate::getDataFromResponsePacket() { case 0x02: /* setting information */ ESP_LOGD(LOG_CYCLE_TAG, "2b: Receiving settings response"); this->getSettingsFromResponsePacket(); - // next step is to get the room temperature case 0x03 + // next step is to get the room temperature case 0x03 ESP_LOGD(LOG_CYCLE_TAG, "3a: Sending room °C request (0x03)"); this->buildAndSendRequestPacket(RQST_PKT_ROOM_TEMP); break; @@ -305,7 +318,7 @@ void CN105Climate::getDataFromResponsePacket() { /* room temperature reading */ ESP_LOGD(LOG_CYCLE_TAG, "3b: Receiving room °C response"); this->getRoomTemperatureFromResponsePacket(); - // next step is to get the heatpump status (operating and compressor frequency) case 0x06 + // next step is to get the heatpump status (operating and compressor frequency) case 0x06 ESP_LOGD(LOG_CYCLE_TAG, "4a: Sending status request (0x06)"); this->buildAndSendRequestPacket(RQST_PKT_STATUS); break; @@ -345,7 +358,7 @@ void CN105Climate::getDataFromResponsePacket() { /* Power */ ESP_LOGD(LOG_CYCLE_TAG, "5b: Receiving Power/Standby response"); this->getPowerFromResponsePacket(); - //FC 62 01 30 10 09 00 00 00 02 02 00 00 00 00 00 00 00 00 00 00 50 + //FC 62 01 30 10 09 00 00 00 02 02 00 00 00 00 00 00 00 00 00 00 50 // reset the powerRequestWithoutResponses to 0 as we had a response this->powerRequestWithoutResponses = 0; @@ -401,9 +414,9 @@ void CN105Climate::processCommand() { ESP_LOGI(TAG, "--> Heatpump did reply: connection success! <--"); //this->isHeatpumpConnected_ = true; this->setHeatpumpConnected(true); - // let's say that the last complete cycle was over now + // let's say that the last complete cycle was over now this->loopCycle.lastCompleteCycleMs = CUSTOM_MILLIS; - this->currentSettings.resetSettings(); // each time we connect, we need to reset current setting to force a complete sync with ha component state and receievdSettings + this->currentSettings.resetSettings(); // each time we connect, we need to reset current setting to force a complete sync with ha component state and receievdSettings break; default: break; @@ -424,7 +437,7 @@ void CN105Climate::statusChanged(heatpumpStatus status) { this->currentStatus.outsideAirTemperature = status.outsideAirTemperature; this->current_temperature = currentStatus.roomTemperature; - this->updateAction(); // update action info on HA climate component + this->updateAction(); // update action info on HA climate component this->publish_state(); if (this->compressor_frequency_sensor_ != nullptr) { @@ -440,7 +453,7 @@ void CN105Climate::statusChanged(heatpumpStatus status) { void CN105Climate::publishStateToHA(heatpumpSettings settings) { - if ((this->wantedSettings.mode == nullptr) && (this->wantedSettings.power == nullptr)) { // to prevent overwriting a user demand + if ((this->wantedSettings.mode == nullptr) && (this->wantedSettings.power == nullptr)) { // to prevent overwriting a user demand checkPowerAndModeSettings(settings); } @@ -474,7 +487,7 @@ void CN105Climate::publishStateToHA(heatpumpSettings settings) { void CN105Climate::heatpumpUpdate(heatpumpSettings settings) { - // settings correponds to current settings + // settings correponds to current settings ESP_LOGV(LOG_SETTINGS_TAG, "Settings received"); this->debugSettings("current", this->currentSettings); diff --git a/components/cn105/hp_writings.cpp b/components/cn105/hp_writings.cpp index 3db8404..808da38 100644 --- a/components/cn105/hp_writings.cpp +++ b/components/cn105/hp_writings.cpp @@ -51,7 +51,7 @@ void CN105Climate::sendFirstConnectionPacket() { // ESP_LOGD(TAG, "t°: %f", currentStatus.roomTemperature); // ESP_LOGD(TAG, "operating: %d", currentStatus.operating); -// ESP_LOGD(TAG, "compressor freq: %d", currentStatus.compressorFrequency); +// ESP_LOGD(TAG, "compressor freq: %f", currentStatus.compressorFrequency); // this->updateAction(); // this->publish_state(); @@ -275,10 +275,10 @@ void CN105Climate::sendWantedSettings() { #ifdef USE_ESP32 std::lock_guard guard(wantedSettingsMutex); this->sendWantedSettingsDelegate(); -#else +#else this->emulateMutex("WRITE_SETTINGS", std::bind(&CN105Climate::sendWantedSettingsDelegate, this)); -#endif +#endif } else { ESP_LOGD(TAG, "will sendWantedSettings later because we've sent one too recently..."); @@ -379,4 +379,4 @@ void CN105Climate::sendRemoteTemperature() { this->pingExternalTemperature(); -} \ No newline at end of file +} diff --git a/components/cn105/utils.cpp b/components/cn105/utils.cpp index 5803f55..e611305 100644 --- a/components/cn105/utils.cpp +++ b/components/cn105/utils.cpp @@ -125,13 +125,13 @@ void CN105Climate::debugSettings(const char* settingName, heatpumpSettings setti void CN105Climate::debugStatus(const char* statusName, heatpumpStatus status) { #ifdef USE_ESP32 - ESP_LOGI(LOG_STATUS_TAG, "[%s]-> [room C°: %.1f, operating: %s, compressor freq: %2d Hz]", + ESP_LOGI(LOG_STATUS_TAG, "[%s]-> [room C°: %.1f, operating: %s, compressor freq: %.1f Hz]", statusName, status.roomTemperature, status.operating ? "YES" : "NO ", status.compressorFrequency); #else - ESP_LOGI(LOG_STATUS_TAG, "[%-*s]-> [room C°: %.1f, operating: %-*s, compressor freq: %2d Hz]", + ESP_LOGI(LOG_STATUS_TAG, "[%-*s]-> [room C°: %.1f, operating: %-*s, compressor freq: %.1f Hz]", 15, statusName, status.roomTemperature, 3, status.operating ? "YES" : "NO ", @@ -280,7 +280,7 @@ void CN105Climate::logDelegate() { } else { ESP_LOGI("testMutex", "Mutex est déjà verrouillé"); } -#endif +#endif } void CN105Climate::testCase1() {