Skip to content

Commit

Permalink
Adjust climates to handle multi zone configs
Browse files Browse the repository at this point in the history
  • Loading branch information
gekkekoe committed Dec 2, 2024
1 parent 95c3d4c commit 9c57780
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
16 changes: 12 additions & 4 deletions components/ecodan/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ namespace ecodan
case ecodan::Status::HpMode::HEAT_FLOW_TEMP:
case ecodan::Status::HpMode::HEAT_COMPENSATION_CURVE:
if (this->mode != climate::ClimateMode::CLIMATE_MODE_HEAT && allow_refresh) {
this->mode = climate::ClimateMode::CLIMATE_MODE_HEAT;
should_publish = true;
if (this->climate_zone_identifier == ClimateZoneIdentifier::SINGLE_ZONE
|| static_cast<uint8_t>(ClimateZoneIdentifier::MULTI_ZONE_BOTH) == status.MultiZoneStatus
|| static_cast<uint8_t>(this->climate_zone_identifier) == status.MultiZoneStatus) {
this->mode = climate::ClimateMode::CLIMATE_MODE_HEAT;
should_publish = true;
}
}
break;
case ecodan::Status::HpMode::COOL_ROOM_TEMP:
case ecodan::Status::HpMode::COOL_FLOW_TEMP:
if (this->mode != climate::ClimateMode::CLIMATE_MODE_COOL && allow_refresh) {
this->mode = climate::ClimateMode::CLIMATE_MODE_COOL;
should_publish = true;
if (this->climate_zone_identifier == ClimateZoneIdentifier::SINGLE_ZONE
|| static_cast<uint8_t>(ClimateZoneIdentifier::MULTI_ZONE_BOTH) == status.MultiZoneStatus
|| static_cast<uint8_t>(this->climate_zone_identifier) == status.MultiZoneStatus) {
this->mode = climate::ClimateMode::CLIMATE_MODE_COOL;
should_publish = true;
}
}
break;
case ecodan::Status::HpMode::OFF:
Expand Down
11 changes: 9 additions & 2 deletions components/ecodan/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
cv.Required("target_temp_func"): cv.string,
cv.Required("get_target_temp_func"): cv.string,
cv.Optional("current_temp_func"): cv.string,
cv.Optional("zone_identifier"): cv.uint8_t,
}).extend(cv.polling_component_schema('100ms')),
cv.Optional("heatpump_climate_room_z1"): climate.CLIMATE_SCHEMA.extend(
{
Expand All @@ -27,6 +28,7 @@
cv.Required("target_temp_func"): cv.string,
cv.Required("get_target_temp_func"): cv.string,
cv.Optional("current_temp_func"): cv.string,
cv.Optional("zone_identifier"): cv.uint8_t,
cv.Optional("thermostat_climate_mode"): cv.boolean,
}).extend(cv.polling_component_schema('100ms')),
cv.Optional("heatpump_climate_z2"): climate.CLIMATE_SCHEMA.extend(
Expand All @@ -36,6 +38,7 @@
cv.Required("target_temp_func"): cv.string,
cv.Required("get_target_temp_func"): cv.string,
cv.Optional("current_temp_func"): cv.string,
cv.Optional("zone_identifier"): cv.uint8_t,
}).extend(cv.polling_component_schema('100ms')),
cv.Optional("heatpump_climate_room_z2"): climate.CLIMATE_SCHEMA.extend(
{
Expand All @@ -44,6 +47,7 @@
cv.Required("target_temp_func"): cv.string,
cv.Required("get_target_temp_func"): cv.string,
cv.Optional("current_temp_func"): cv.string,
cv.Optional("zone_identifier"): cv.uint8_t,
cv.Optional("thermostat_climate_mode"): cv.boolean,
}).extend(cv.polling_component_schema('100ms')),
cv.Optional("heatpump_climate_dhw"): climate.CLIMATE_SCHEMA.extend(
Expand All @@ -70,12 +74,15 @@ async def to_code(config):
cg.add(inst.set_status(cg.RawExpression(f'[=](void) -> const ecodan::Status& {{ {conf["get_status_func"]} }}')))
cg.add(inst.set_target_temp_func(cg.RawExpression(f'[=](float x){{ {conf["target_temp_func"]} }}')))
cg.add(inst.set_get_target_temp_func(cg.RawExpression(f'[=](void) -> float {{ {conf["get_target_temp_func"]} }}')))

if "current_temp_func" in conf:
cg.add(inst.set_get_current_temp_func(cg.RawExpression(f'[=](void) -> float {{ {conf["current_temp_func"]} }}')))
if "dhw_climate_mode" in conf:
cg.add(inst.set_dhw_climate_mode(True))
if "thermostat_climate_mode" in conf:
cg.add(inst.set_thermostat_climate_mode(True))
cg.add(inst.set_thermostat_climate_mode(True))
if "zone_identifier" in conf:
cg.add(inst.set_zone_identifier(conf["zone_identifier"]))

await cg.register_component(inst, conf)
await climate.register_climate(inst, conf)
2 changes: 2 additions & 0 deletions components/ecodan/ecodan.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ namespace ecodan
void set_status(std::function<const ecodan::Status& (void)> get_status_func) { get_status = get_status_func; };
void set_dhw_climate_mode(bool mode) { this->dhw_climate_mode = mode; }
void set_thermostat_climate_mode(bool mode) { this->thermostat_climate_mode = mode; }
void set_zone_identifier(uint8_t zone_identifier) { this->climate_zone_identifier = static_cast<ClimateZoneIdentifier>(zone_identifier); }
private:
std::function<void(float)> set_target_temp = nullptr;
std::function<float(void)> get_current_temp = nullptr;
std::function<float(void)> get_target_temp = nullptr;
std::function<const ecodan::Status& (void)> get_status = nullptr;
bool dhw_climate_mode = false;
bool thermostat_climate_mode = false;
ClimateZoneIdentifier climate_zone_identifier = ClimateZoneIdentifier::SINGLE_ZONE;

void refresh();
void validate_target_temperature();
Expand Down
8 changes: 8 additions & 0 deletions components/ecodan/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
namespace esphome {
namespace ecodan
{
enum class ClimateZoneIdentifier
{
SINGLE_ZONE = 0,
MULTI_ZONE_BOTH = 1,
MULTI_ZONE_1 = 2,
MULTI_ZONE_2 = 3
};

// https://github.com/m000c400/Mitsubishi-CN105-Protocol-Decode
enum class MsgType : uint8_t
{
Expand Down
5 changes: 5 additions & 0 deletions confs/zone1.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
substitutions:
zone_identifier_z1: "0"

binary_sensor:
- platform: ecodan
status_prohibit_heating_z1:
Expand All @@ -15,6 +18,7 @@ climate:
heatpump_climate_z1:
name: ${heatpump_climate_z1}
id: heatpump_climate_z1
zone_identifier: ${zone_identifier_z1}
get_status_func: |-
return id(ecodan_instance).get_status();
get_target_temp_func: |-
Expand Down Expand Up @@ -68,6 +72,7 @@ climate:
name: ${heatpump_climate_room_z1}
id: heatpump_climate_room_z1
thermostat_climate_mode: true
zone_identifier: ${zone_identifier_z1}
get_status_func: |-
return id(ecodan_instance).get_status();
get_target_temp_func: |-
Expand Down
5 changes: 5 additions & 0 deletions confs/zone2.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
substitutions:
zone_identifier_z1: "2"

binary_sensor:
- platform: ecodan
status_prohibit_heating_z2:
Expand All @@ -18,6 +21,7 @@ climate:
heatpump_climate_z2:
name: ${heatpump_climate_z2}
id: heatpump_climate_z2
zone_identifier: 3
get_status_func: |-
return id(ecodan_instance).get_status();
get_target_temp_func: |-
Expand Down Expand Up @@ -71,6 +75,7 @@ climate:
name: ${heatpump_climate_room_z2}
id: heatpump_climate_room_z2
thermostat_climate_mode: true
zone_identifier: 3
get_status_func: |-
return id(ecodan_instance).get_status();
get_target_temp_func: |-
Expand Down

0 comments on commit 9c57780

Please sign in to comment.