mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
climate min/max values
This commit is contained in:
@@ -165,17 +165,21 @@ const SettingsCustomization: FC = () => {
|
||||
}
|
||||
|
||||
function formatName(de: DeviceEntity) {
|
||||
if (de.n === undefined || de.n === de.id) {
|
||||
return de.id;
|
||||
}
|
||||
|
||||
if (de.n[0] === '!') {
|
||||
return LL.COMMAND() + ': ' + de.n.slice(1);
|
||||
if (de.n === undefined) {
|
||||
return (
|
||||
<>
|
||||
(
|
||||
<Link target="_blank" href={APIURL + devices?.devices[selectedDevice].t + '/' + de.id}>
|
||||
{de.id}
|
||||
</Link>
|
||||
)
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{de.cn !== undefined && de.cn !== '' ? de.cn : de.n}
|
||||
{de.n[0] === '!' ? LL.COMMAND() + ': ' + de.n.slice(1) : de.cn !== undefined && de.cn !== '' ? de.cn : de.n}
|
||||
(
|
||||
<Link target="_blank" href={APIURL + devices?.devices[selectedDevice].t + '/' + de.id}>
|
||||
{de.id}
|
||||
@@ -322,7 +326,7 @@ const SettingsCustomization: FC = () => {
|
||||
};
|
||||
|
||||
const editEntity = (de: DeviceEntity) => {
|
||||
if (de.n && de.n[0] === '!') {
|
||||
if (de.n === undefined || (de.n && de.n[0] === '!')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -3950,7 +3950,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
|
||||
register_device_value(tag, &hc->selTemp, DeviceValueType::SHORT, seltemp_divider, FL_(selRoomTemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_temp), 0, 30);
|
||||
}
|
||||
register_device_value(tag, &hc->roomTemp, DeviceValueType::SHORT, roomtemp_divider, FL_(roomTemp), DeviceValueUOM::DEGREES);
|
||||
register_device_value(tag, &hc->climate, DeviceValueType::ENUM, FL_(enum_climate), FL_(climate), DeviceValueUOM::NONE);
|
||||
register_device_value(tag, &hc->climate, DeviceValueType::ENUM, FL_(enum_climate), FL_(climate), DeviceValueUOM::NONE, nullptr, 5, 30);
|
||||
|
||||
switch (model) {
|
||||
case EMS_DEVICE_FLAG_RC10:
|
||||
@@ -4135,9 +4135,16 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
|
||||
register_device_value(tag, &hc->mode, DeviceValueType::ENUM, FL_(enum_mode3), FL_(mode), DeviceValueUOM::NONE, MAKE_CF_CB(set_mode));
|
||||
register_device_value(tag, &hc->modetype, DeviceValueType::ENUM, FL_(enum_modetype3), FL_(modetype), DeviceValueUOM::NONE);
|
||||
register_device_value(
|
||||
tag, &hc->daytemp, DeviceValueType::UINT, DeviceValueNumOp::DV_NUMOP_DIV2, FL_(daytemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_daytemp));
|
||||
register_device_value(
|
||||
tag, &hc->nighttemp, DeviceValueType::UINT, DeviceValueNumOp::DV_NUMOP_DIV2, FL_(nighttemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_nighttemp));
|
||||
tag, &hc->daytemp, DeviceValueType::UINT, DeviceValueNumOp::DV_NUMOP_DIV2, FL_(daytemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_daytemp), 5, 30);
|
||||
register_device_value(tag,
|
||||
&hc->nighttemp,
|
||||
DeviceValueType::UINT,
|
||||
DeviceValueNumOp::DV_NUMOP_DIV2,
|
||||
FL_(nighttemp),
|
||||
DeviceValueUOM::DEGREES,
|
||||
MAKE_CF_CB(set_nighttemp),
|
||||
5,
|
||||
30);
|
||||
register_device_value(tag, &hc->designtemp, DeviceValueType::UINT, FL_(designtemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_designtemp), 30, 90);
|
||||
register_device_value(tag,
|
||||
&hc->offsettemp,
|
||||
@@ -4154,7 +4161,9 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
|
||||
DeviceValueNumOp::DV_NUMOP_DIV2,
|
||||
FL_(holidaytemp),
|
||||
DeviceValueUOM::DEGREES,
|
||||
MAKE_CF_CB(set_holidaytemp));
|
||||
MAKE_CF_CB(set_holidaytemp),
|
||||
5,
|
||||
30);
|
||||
register_device_value(tag, &hc->targetflowtemp, DeviceValueType::UINT, FL_(targetflowtemp), DeviceValueUOM::DEGREES);
|
||||
register_device_value(tag, &hc->summertemp, DeviceValueType::UINT, FL_(summertemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_summertemp), 9, 25);
|
||||
register_device_value(tag, &hc->summermode, DeviceValueType::ENUM, FL_(enum_summer), FL_(summermode), DeviceValueUOM::NONE);
|
||||
@@ -4183,7 +4192,9 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
|
||||
DeviceValueNumOp::DV_NUMOP_DIV2,
|
||||
FL_(tempautotemp),
|
||||
DeviceValueUOM::DEGREES,
|
||||
MAKE_CF_CB(set_tempautotemp));
|
||||
MAKE_CF_CB(set_tempautotemp),
|
||||
0,
|
||||
30);
|
||||
register_device_value(tag, &hc->noreducetemp, DeviceValueType::INT, FL_(noreducetemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_noreducetemp), -30, 10);
|
||||
register_device_value(tag, &hc->reducetemp, DeviceValueType::INT, FL_(reducetemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_reducetemp), -20, 10);
|
||||
register_device_value(tag, &hc->vacreducetemp, DeviceValueType::INT, FL_(vacreducetemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_vacreducetemp), -20, 10);
|
||||
|
||||
@@ -986,6 +986,20 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
|
||||
}
|
||||
}
|
||||
|
||||
void EMSdevice::set_climate_minmax(uint8_t tag, int16_t min, uint16_t max) {
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.tag == tag && dv.short_name == FL_(climate[0])) {
|
||||
if (dv.min != min || dv.max != max) {
|
||||
dv.min = min;
|
||||
dv.max = max;
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
Mqtt::publish_ha_climate_config(dv.tag, false, true); // delete topic (remove = true)
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set mask per device entity based on the id which is prefixed with the 2 char hex mask value
|
||||
// returns true if the entity has a mask set (not 0 the default)
|
||||
void EMSdevice::setCustomEntity(const std::string & entity_id) {
|
||||
@@ -1009,7 +1023,7 @@ void EMSdevice::setCustomEntity(const std::string & entity_id) {
|
||||
uint8_t new_mask = Helpers::hextoint(entity_id.substr(0, 2).c_str()); // first character contains mask flags
|
||||
|
||||
// if it's a new mask, reconfigure HA
|
||||
if (Mqtt::ha_enabled() && ((current_mask ^ new_mask) & (DeviceValueState::DV_READONLY >> 4))) {
|
||||
if (Mqtt::ha_enabled() && (has_custom_name || ((current_mask ^ new_mask) & (DeviceValueState::DV_READONLY >> 4)))) {
|
||||
// remove ha config on change of dv_readonly flag
|
||||
dv.remove_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
Mqtt::publish_ha_sensor_config(dv, "", "", true); // delete topic (remove = true)
|
||||
@@ -1024,7 +1038,13 @@ void EMSdevice::setCustomEntity(const std::string & entity_id) {
|
||||
} else {
|
||||
dv.custom_fullname = "";
|
||||
}
|
||||
|
||||
auto min = dv.min;
|
||||
auto max = dv.max;
|
||||
dv.set_custom_minmax();
|
||||
if (dv.short_name == FL_(seltemp)[0] && (min != dv.min || max != dv.max)) {
|
||||
set_climate_minmax(dv.tag, dv.min, dv.max);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1192,12 +1212,14 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8
|
||||
break;
|
||||
}
|
||||
|
||||
// set the min and max
|
||||
// set the min and max only for commands
|
||||
if (dv.has_cmd) {
|
||||
int16_t dv_set_min, dv_set_max;
|
||||
if (dv.get_min_max(dv_set_min, dv_set_max)) {
|
||||
json["min"] = dv_set_min;
|
||||
json["max"] = dv_set_max;
|
||||
}
|
||||
}
|
||||
|
||||
// add uom if it's not a " " (single space)
|
||||
if (!uom_to_string(dv.uom).empty() && uom_to_string(dv.uom) != " ") {
|
||||
@@ -1474,12 +1496,12 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
if (*(int8_t *)(dv.value_p) == 1 && (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
|
||||
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
Mqtt::publish_ha_climate_config(dv.tag, true);
|
||||
Mqtt::publish_ha_climate_config(dv.tag, true, false, dv.min, dv.max);
|
||||
} else if (*(int8_t *)(dv.value_p) == 0
|
||||
&& (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || !dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
|
||||
dv.add_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
Mqtt::publish_ha_climate_config(dv.tag, false);
|
||||
Mqtt::publish_ha_climate_config(dv.tag, false, false, dv.min, dv.max);
|
||||
}
|
||||
}
|
||||
if (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) && (dv.type != DeviceValueType::CMD) && dv.has_state(DeviceValueState::DV_ACTIVE)
|
||||
|
||||
@@ -187,6 +187,7 @@ class EMSdevice {
|
||||
void list_device_entries(JsonObject & output) const;
|
||||
void add_handlers_ignored(const uint16_t handler);
|
||||
|
||||
void set_climate_minmax(uint8_t tag, int16_t min, uint16_t max);
|
||||
void setCustomEntity(const std::string & entity_id);
|
||||
void getCustomEntities(std::vector<std::string> & entity_ids);
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ MAKE_PSTR(response, "response")
|
||||
MAKE_PSTR(tag_boiler_data_ww_mqtt, "ww")
|
||||
MAKE_PSTR(tag_device_data_ww_mqtt, "")
|
||||
|
||||
MAKE_PSTR_LIST(climate, F("HA climate config creation"))
|
||||
MAKE_PSTR_LIST(climate, F("HA climate config creation"), F("")) // empty fullname
|
||||
|
||||
// syslog
|
||||
MAKE_PSTR_LIST(list_syslog_level, F("off"), F("emerg"), F("alert"), F("crit"), F("error"), F("warn"), F("notice"), F("info"), F("debug"), F("trace"), F("all"))
|
||||
|
||||
@@ -1248,7 +1248,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type,
|
||||
publish_ha(topic, doc.as<JsonObject>());
|
||||
}
|
||||
|
||||
void Mqtt::publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove) {
|
||||
void Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp, const bool remove, const int16_t min, const uint16_t max) {
|
||||
uint8_t hc_num = tag - DeviceValueTAG::TAG_HC1 + 1;
|
||||
|
||||
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||
@@ -1321,8 +1321,8 @@ void Mqtt::publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove
|
||||
doc["curr_temp_tpl"] = currtemp_s;
|
||||
}
|
||||
|
||||
doc["min_temp"] = Helpers::render_value(min_s, (uint32_t)5, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||
doc["max_temp"] = Helpers::render_value(max_s, (uint32_t)30, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||
doc["min_temp"] = Helpers::render_value(min_s, min, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||
doc["max_temp"] = Helpers::render_value(max_s, max, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||
doc["temp_step"] = "0.5";
|
||||
|
||||
// the HA climate component only responds to auto, heat and off
|
||||
|
||||
@@ -108,7 +108,7 @@ class Mqtt {
|
||||
const JsonObject & dev_json);
|
||||
|
||||
static void publish_system_ha_sensor_config(uint8_t type, const __FlashStringHelper * name, const __FlashStringHelper * entity, const uint8_t uom);
|
||||
static void publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove = false);
|
||||
static void publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp, const bool remove = false, const int16_t min = 5, const uint16_t max = 30);
|
||||
|
||||
static void show_topic_handlers(uuid::console::Shell & shell, const uint8_t device_type);
|
||||
static void show_mqtt(uuid::console::Shell & shell);
|
||||
|
||||
Reference in New Issue
Block a user