mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
HA roomtemp optional - #325
This commit is contained in:
@@ -380,17 +380,25 @@ void Thermostat::publish_ha_config_hc(std::shared_ptr<Thermostat::HeatingCircuit
|
|||||||
char temp_cmd_s[30];
|
char temp_cmd_s[30];
|
||||||
char mode_cmd_s[30];
|
char mode_cmd_s[30];
|
||||||
|
|
||||||
|
// https://github.com/emsesp/EMS-ESP32/issues/325#issuecomment-1022249093
|
||||||
|
// before you had to have a seltemp and roomtemp for the HA to work, now its optional
|
||||||
|
bool have_current_room_temp = Helpers::hasValue(hc->roomTemp);
|
||||||
|
|
||||||
if (Mqtt::nested_format() == 1) {
|
if (Mqtt::nested_format() == 1) {
|
||||||
// nested format
|
// nested format
|
||||||
snprintf(hc_mode_s, sizeof(hc_mode_s), "value_json.hc%d.mode", hc_num);
|
snprintf(hc_mode_s, sizeof(hc_mode_s), "value_json.hc%d.mode", hc_num);
|
||||||
snprintf(seltemp_s, sizeof(seltemp_s), "{{value_json.hc%d.seltemp}}", hc_num);
|
snprintf(seltemp_s, sizeof(seltemp_s), "{{value_json.hc%d.seltemp}}", hc_num);
|
||||||
|
if (have_current_room_temp) {
|
||||||
snprintf(currtemp_s, sizeof(currtemp_s), "{{value_json.hc%d.currtemp}}", hc_num);
|
snprintf(currtemp_s, sizeof(currtemp_s), "{{value_json.hc%d.currtemp}}", hc_num);
|
||||||
|
}
|
||||||
snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
|
snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_NONE).c_str());
|
||||||
} else {
|
} else {
|
||||||
// single format
|
// single format
|
||||||
snprintf(hc_mode_s, sizeof(hc_mode_s), "value_json.mode");
|
snprintf(hc_mode_s, sizeof(hc_mode_s), "value_json.mode");
|
||||||
snprintf(seltemp_s, sizeof(seltemp_s), "{{value_json.seltemp}}");
|
snprintf(seltemp_s, sizeof(seltemp_s), "{{value_json.seltemp}}");
|
||||||
|
if (have_current_room_temp) {
|
||||||
snprintf(currtemp_s, sizeof(currtemp_s), "{{value_json.currtemp}}");
|
snprintf(currtemp_s, sizeof(currtemp_s), "{{value_json.currtemp}}");
|
||||||
|
}
|
||||||
snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_HC1 + hc_num - 1).c_str());
|
snprintf(topic_t, sizeof(topic_t), "~/%s", Mqtt::tag_to_topic(EMSdevice::DeviceType::THERMOSTAT, DeviceValueTAG::TAG_HC1 + hc_num - 1).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,8 +424,12 @@ void Thermostat::publish_ha_config_hc(std::shared_ptr<Thermostat::HeatingCircuit
|
|||||||
doc["temp_stat_t"] = topic_t;
|
doc["temp_stat_t"] = topic_t;
|
||||||
doc["temp_stat_tpl"] = seltemp_s;
|
doc["temp_stat_tpl"] = seltemp_s;
|
||||||
doc["mode_cmd_t"] = mode_cmd_s;
|
doc["mode_cmd_t"] = mode_cmd_s;
|
||||||
|
|
||||||
|
if (have_current_room_temp) {
|
||||||
doc["curr_temp_t"] = topic_t;
|
doc["curr_temp_t"] = topic_t;
|
||||||
doc["curr_temp_tpl"] = currtemp_s;
|
doc["curr_temp_tpl"] = currtemp_s;
|
||||||
|
}
|
||||||
|
|
||||||
doc["min_temp"] = "5";
|
doc["min_temp"] = "5";
|
||||||
doc["max_temp"] = "30";
|
doc["max_temp"] = "30";
|
||||||
doc["temp_step"] = "0.5";
|
doc["temp_step"] = "0.5";
|
||||||
@@ -662,9 +674,8 @@ void Thermostat::add_ha_climate(std::shared_ptr<HeatingCircuit> hc) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only if it has a valid seltemp and currtemp
|
// only if it has a valid seltemp (roomtemp is optional)
|
||||||
// mode always defaults to auto
|
if (Helpers::hasValue(hc->selTemp)) {
|
||||||
if (Helpers::hasValue(hc->roomTemp) && Helpers::hasValue(hc->selTemp)) {
|
|
||||||
publish_ha_config_hc(hc);
|
publish_ha_config_hc(hc);
|
||||||
hc->ha_climate_created(true); // only create it once
|
hc->ha_climate_created(true); // only create it once
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define EMSESP_APP_VERSION "3.4.0b1"
|
#define EMSESP_APP_VERSION "3.4.0b2"
|
||||||
|
|||||||
Reference in New Issue
Block a user