From 54e289a8605c2a3e96b8584b4d1a81aa81bdfee2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Mar 2023 12:02:08 +0100 Subject: [PATCH] Fix climate component --- .../climate/TrumaRoomClimate.cpp | 106 +++++++++++++----- components/truma_inetbox/helpers.cpp | 24 +++- components/truma_inetbox/helpers.h | 1 + examples/Readme.md | 5 + examples/combi.yaml | 59 ++++++++++ examples/combi_E.yaml | 64 +++++++++++ 6 files changed, 224 insertions(+), 35 deletions(-) create mode 100644 examples/Readme.md create mode 100644 examples/combi.yaml create mode 100644 examples/combi_E.yaml diff --git a/components/truma_inetbox/climate/TrumaRoomClimate.cpp b/components/truma_inetbox/climate/TrumaRoomClimate.cpp index f140cd6..0438fb1 100644 --- a/components/truma_inetbox/climate/TrumaRoomClimate.cpp +++ b/components/truma_inetbox/climate/TrumaRoomClimate.cpp @@ -10,24 +10,37 @@ void TrumaRoomClimate::setup() { // Publish updated state this->target_temperature = temp_code_to_decimal(status_heater->target_temp_room); this->current_temperature = temp_code_to_decimal(status_heater->current_temp_room); - this->mode = (status_heater->operating_status >= OperatingStatus::OPERATING_STATUS_START_OR_COOL_DOWN) - ? climate::CLIMATE_MODE_HEAT - : climate::CLIMATE_MODE_OFF; + this->mode = std::isnan(this->target_temperature) ? climate::CLIMATE_MODE_OFF : climate::CLIMATE_MODE_HEAT; switch (status_heater->heating_mode) { case HeatingMode::HEATING_MODE_ECO: - this->preset = climate::CLIMATE_PRESET_ECO; + this->fan_mode = climate::CLIMATE_FAN_LOW; break; case HeatingMode::HEATING_MODE_HIGH: - this->preset = climate::CLIMATE_PRESET_COMFORT; + this->fan_mode = climate::CLIMATE_FAN_MEDIUM; break; case HeatingMode::HEATING_MODE_BOOST: - this->preset = climate::CLIMATE_PRESET_BOOST; + this->fan_mode = climate::CLIMATE_FAN_HIGH; break; default: - this->preset = climate::CLIMATE_PRESET_NONE; + this->fan_mode = climate::CLIMATE_FAN_OFF; break; } + + // switch (status_heater->heating_mode) { + // case HeatingMode::HEATING_MODE_ECO: + // this->preset = climate::CLIMATE_PRESET_ECO; + // break; + // case HeatingMode::HEATING_MODE_HIGH: + // this->preset = climate::CLIMATE_PRESET_COMFORT; + // break; + // case HeatingMode::HEATING_MODE_BOOST: + // this->preset = climate::CLIMATE_PRESET_BOOST; + // break; + // default: + // this->preset = climate::CLIMATE_PRESET_NONE; + // break; + // } this->publish_state(); }); } @@ -35,7 +48,7 @@ void TrumaRoomClimate::setup() { void TrumaRoomClimate::dump_config() { LOG_CLIMATE(TAG, "Truma Room Climate", this); } void TrumaRoomClimate::control(const climate::ClimateCall &call) { - if (call.get_target_temperature().has_value()) { + if (call.get_target_temperature().has_value() && !call.get_fan_mode().has_value()) { float temp = *call.get_target_temperature(); this->parent_->get_heater()->action_heater_room(static_cast(temp)); } @@ -56,28 +69,62 @@ void TrumaRoomClimate::control(const climate::ClimateCall &call) { } } - if (call.get_preset().has_value()) { - climate::ClimatePreset pres = *call.get_preset(); + if (call.get_fan_mode().has_value()) { + auto fan_mode = *call.get_fan_mode(); auto status_heater = this->parent_->get_heater()->get_status(); - auto current_target_temp = temp_code_to_decimal(status_heater->target_temp_room); + float temp = temp_code_to_decimal(status_heater->target_temp_room, 0); if (call.get_target_temperature().has_value()) { - current_target_temp = *call.get_target_temperature(); + temp = *call.get_target_temperature(); } - switch (pres) { - case climate::CLIMATE_PRESET_ECO: - this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_ECO); + switch (fan_mode) { + case climate::CLIMATE_FAN_LOW: + case climate::CLIMATE_FAN_MEDIUM: + case climate::CLIMATE_FAN_HIGH: + if (temp < 5) { + temp = 5; + } break; - case climate::CLIMATE_PRESET_COMFORT: - this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_HIGH); + default: break; - case climate::CLIMATE_PRESET_BOOST: - this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_BOOST); + } + switch (fan_mode) { + case climate::CLIMATE_FAN_LOW: + this->parent_->get_heater()->action_heater_room(static_cast(temp), HeatingMode::HEATING_MODE_ECO); + break; + case climate::CLIMATE_FAN_MEDIUM: + this->parent_->get_heater()->action_heater_room(static_cast(temp), HeatingMode::HEATING_MODE_HIGH); + break; + case climate::CLIMATE_FAN_HIGH: + this->parent_->get_heater()->action_heater_room(static_cast(temp), HeatingMode::HEATING_MODE_BOOST); break; default: this->parent_->get_heater()->action_heater_room(0); break; } } + + // if (call.get_preset().has_value()) { + // climate::ClimatePreset pres = *call.get_preset(); + // auto status_heater = this->parent_->get_heater()->get_status(); + // auto current_target_temp = temp_code_to_decimal(status_heater->target_temp_room); + // if (call.get_target_temperature().has_value()) { + // current_target_temp = *call.get_target_temperature(); + // } + // switch (pres) { + // case climate::CLIMATE_PRESET_ECO: + // this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_ECO); + // break; + // case climate::CLIMATE_PRESET_COMFORT: + // this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_HIGH); + // break; + // case climate::CLIMATE_PRESET_BOOST: + // this->parent_->get_heater()->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_BOOST); + // break; + // default: + // this->parent_->get_heater()->action_heater_room(0); + // break; + // } + // } } climate::ClimateTraits TrumaRoomClimate::traits() { @@ -85,17 +132,18 @@ climate::ClimateTraits TrumaRoomClimate::traits() { auto traits = climate::ClimateTraits(); traits.set_supports_current_temperature(true); traits.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_HEAT}); - // traits.set_supported_fan_modes({{ - // climate::CLIMATE_FAN_LOW, - // climate::CLIMATE_FAN_MEDIUM, - // climate::CLIMATE_FAN_HIGH, - // }}); - traits.set_supported_presets({{ - climate::CLIMATE_PRESET_NONE, - climate::CLIMATE_PRESET_ECO, - climate::CLIMATE_PRESET_COMFORT, - climate::CLIMATE_PRESET_BOOST, + traits.set_supported_fan_modes({{ + climate::CLIMATE_FAN_OFF, + climate::CLIMATE_FAN_LOW, + climate::CLIMATE_FAN_MEDIUM, + climate::CLIMATE_FAN_HIGH, }}); + // traits.set_supported_presets({{ + // climate::CLIMATE_PRESET_NONE, + // climate::CLIMATE_PRESET_ECO, + // climate::CLIMATE_PRESET_COMFORT, + // climate::CLIMATE_PRESET_BOOST, + // }}); traits.set_visual_min_temperature(5); traits.set_visual_max_temperature(30); traits.set_visual_temperature_step(1); diff --git a/components/truma_inetbox/helpers.cpp b/components/truma_inetbox/helpers.cpp index db82b66..f693271 100644 --- a/components/truma_inetbox/helpers.cpp +++ b/components/truma_inetbox/helpers.cpp @@ -37,7 +37,7 @@ TargetTemp decimal_to_room_temp(u_int8_t val) { if (val == 0) { return TargetTemp::TARGET_TEMP_OFF; } - if (val <= 5) { + if (val < 5) { return TargetTemp::TARGET_TEMP_OFF; } if (val >= 30) { @@ -47,10 +47,10 @@ TargetTemp decimal_to_room_temp(u_int8_t val) { } TargetTemp decimal_to_room_temp(float val) { - if (val == NAN) { + if (std::isnan(val)) { return TargetTemp::TARGET_TEMP_OFF; } - if (val <= 5) { + if (val < 5) { return TargetTemp::TARGET_TEMP_OFF; } if (val >= 30) { @@ -63,7 +63,7 @@ TargetTemp decimal_to_aircon_temp(u_int8_t val) { if (val == 0) { return TargetTemp::TARGET_TEMP_OFF; } - if (val <= 16) { + if (val < 16) { return TargetTemp::TARGET_TEMP_OFF; } if (val >= 31) { @@ -73,10 +73,10 @@ TargetTemp decimal_to_aircon_temp(u_int8_t val) { } TargetTemp decimal_to_aircon_temp(float val) { - if (val == NAN) { + if (std::isnan(val)) { return TargetTemp::TARGET_TEMP_OFF; } - if (val <= 16) { + if (val < 16) { return TargetTemp::TARGET_TEMP_OFF; } if (val >= 31) { @@ -97,6 +97,18 @@ TargetTemp decimal_to_water_temp(u_int8_t val) { } } +TargetTemp decimal_to_water_temp(float val) { + if (std::isnan(val) || val < 40) { + return TargetTemp::TARGET_TEMP_OFF; + } else if (val >= 40 && val < 60) { + return TargetTemp::TARGET_TEMP_WATER_ECO; + } else if (val >= 60 && val < 80) { + return TargetTemp::TARGET_TEMP_WATER_HIGH; + } else { + return TargetTemp::TARGET_TEMP_WATER_BOOST; + } +} + const std::string operating_status_to_str(OperatingStatus val) { if (val == OperatingStatus::OPERATING_STATUS_OFF) { return "OFF"; diff --git a/components/truma_inetbox/helpers.h b/components/truma_inetbox/helpers.h index e5bd704..ff95a70 100644 --- a/components/truma_inetbox/helpers.h +++ b/components/truma_inetbox/helpers.h @@ -20,6 +20,7 @@ TargetTemp decimal_to_room_temp(float val); TargetTemp decimal_to_aircon_temp(u_int8_t val); TargetTemp decimal_to_aircon_temp(float val); TargetTemp decimal_to_water_temp(u_int8_t val); +TargetTemp decimal_to_water_temp(float val); const std::string operating_status_to_str(OperatingStatus val); ElectricPowerLevel decimal_to_el_power_level(u_int16_t val); diff --git a/examples/Readme.md b/examples/Readme.md new file mode 100644 index 0000000..6998a90 --- /dev/null +++ b/examples/Readme.md @@ -0,0 +1,5 @@ +# Example configuration + +[Combi 4 / 4D / 6 / 6D](combi.yaml) + +[Combi 4E / 4DE / 6E / 6DE](combi_E.yaml) diff --git a/examples/combi.yaml b/examples/combi.yaml new file mode 100644 index 0000000..92b96cd --- /dev/null +++ b/examples/combi.yaml @@ -0,0 +1,59 @@ +esphome: + name: "Truma Combi" + +external_components: + - source: github://Fabian-Schmidt/esphome-truma_inetbox + +esp32: + board: esp32dev + +# Enable logging +logger: + +# Enable Home Assistant API +api: + encryption: + key: "" + +ota: + password: "" + +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_password + +uart: + - id: lin_uart_bus + tx_pin: 17 + rx_pin: 16 + baud_rate: 9600 + data_bits: 8 + parity: NONE + stop_bits: 2 + +truma_inetbox: + uart_id: lin_uart_bus + +climate: + - platform: truma_inetbox + name: "Room" + type: ROOM + - platform: truma_inetbox + name: "Water" + type: WATER + +binary_sensor: + - platform: truma_inetbox + name: "CP Plus alive" + type: CP_PLUS_CONNECTED + - platform: truma_inetbox + name: "Heater has error" + type: HEATER_HAS_ERROR + +sensor: + - platform: truma_inetbox + name: "Current Room Temperature" + type: CURRENT_ROOM_TEMPERATURE + - platform: truma_inetbox + name: "Current Water Temperature" + type: CURRENT_WATER_TEMPERATURE \ No newline at end of file diff --git a/examples/combi_E.yaml b/examples/combi_E.yaml new file mode 100644 index 0000000..19d1ebf --- /dev/null +++ b/examples/combi_E.yaml @@ -0,0 +1,64 @@ +esphome: + name: "Truma Combi E" + +external_components: + - source: github://Fabian-Schmidt/esphome-truma_inetbox + +esp32: + board: esp32dev + +# Enable logging +logger: + +# Enable Home Assistant API +api: + encryption: + key: "" + +ota: + password: "" + +wifi: + ssid: !secret wifi_ssid + password: !secret wifi_password + +uart: + - id: lin_uart_bus + tx_pin: 17 + rx_pin: 16 + baud_rate: 9600 + data_bits: 8 + parity: NONE + stop_bits: 2 + +truma_inetbox: + uart_id: lin_uart_bus + +climate: + - platform: truma_inetbox + name: "Room" + type: ROOM + - platform: truma_inetbox + name: "Water" + type: WATER + +binary_sensor: + - platform: truma_inetbox + name: "CP Plus alive" + type: CP_PLUS_CONNECTED + - platform: truma_inetbox + name: "Heater has error" + type: HEATER_HAS_ERROR + +sensor: + - platform: truma_inetbox + name: "Current Room Temperature" + type: CURRENT_ROOM_TEMPERATURE + - platform: truma_inetbox + name: "Current Water Temperature" + type: CURRENT_WATER_TEMPERATURE + +number: + - platform: truma_inetbox + name: "electric power level" + type: ELECTRIC_POWER_LEVEL \ No newline at end of file