mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-14 19:59:53 +03:00
send HA modes based on actual thermostat modes
This commit is contained in:
@@ -2050,14 +2050,14 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
// create climate when we reach the haclimate entity
|
||||
if (!strcmp(dv.short_name, FL_(haclimate)[0]) && !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE) && dv.has_state(DeviceValueState::DV_ACTIVE)) {
|
||||
if (*(int8_t *)(dv.value_p) == 1 && (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) || dv.has_state(DeviceValueState::DV_HA_CLIMATE_NO_RT))) {
|
||||
if (Mqtt::publish_ha_climate_config(dv.tag, true, false, dv.min, dv.max)) { // roomTemp
|
||||
if (Mqtt::publish_ha_climate_config(dv, true, false)) { // roomTemp
|
||||
dv.remove_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
count++;
|
||||
}
|
||||
} 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))) {
|
||||
if (Mqtt::publish_ha_climate_config(dv.tag, false, false, dv.min, dv.max)) { // no roomTemp
|
||||
if (Mqtt::publish_ha_climate_config(dv, false, false)) { // no roomTemp
|
||||
dv.add_state(DeviceValueState::DV_HA_CLIMATE_NO_RT);
|
||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||
count++;
|
||||
@@ -2075,7 +2075,7 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
}
|
||||
// SRC thermostats mapped to connect/src1/...
|
||||
if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(selRoomTemp)[0])) {
|
||||
Mqtt::publish_ha_climate_config(dv.tag, true, false, dv.min, dv.max);
|
||||
Mqtt::publish_ha_climate_config(dv, true, false);
|
||||
}
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
|
||||
@@ -1236,7 +1236,10 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8
|
||||
}
|
||||
}
|
||||
|
||||
bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp, const bool remove, const int16_t min, const uint32_t max) {
|
||||
bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_roomtemp, const bool remove) {
|
||||
int8_t tag = dv.tag;
|
||||
int16_t min = dv.min;
|
||||
uint32_t max = dv.max;
|
||||
uint8_t hc_num = tag < DeviceValueTAG::TAG_SRC1 ? tag : tag - DeviceValueTAG::TAG_SRC1 + 1;
|
||||
const char * tagname = tag < DeviceValueTAG::TAG_SRC1 ? "hc" : "src";
|
||||
const uint8_t device_type = tag < DeviceValueTAG::TAG_SRC1 ? EMSdevice::DeviceType::THERMOSTAT : EMSdevice::DeviceType::CONNECT;
|
||||
@@ -1356,9 +1359,33 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp,
|
||||
// the HA climate component only responds to auto, heat and off
|
||||
JsonArray modes = doc["modes"].to<JsonArray>();
|
||||
|
||||
modes.add("auto");
|
||||
modes.add("heat");
|
||||
modes.add("off");
|
||||
// go through dv.options and map to HA climate modes
|
||||
// https://www.home-assistant.io/integrations/climate.mqtt/
|
||||
// HA supports: ["auto", "off", "cool", "heat", "dry", "fan_only"]
|
||||
if (dv.options != nullptr) {
|
||||
bool found_auto = false;
|
||||
bool found_heat = false;
|
||||
bool found_off = false;
|
||||
for (uint8_t i = 0; i < dv.options_size; i++) {
|
||||
const char * option = dv.options[i][0];
|
||||
if (strcmp(option, "auto") == 0) {
|
||||
found_auto = true;
|
||||
} else if (strcmp(option, "heat") == 0) {
|
||||
found_heat = true;
|
||||
} else if (strcmp(option, "off") == 0) {
|
||||
found_off = true;
|
||||
}
|
||||
}
|
||||
if (found_auto) {
|
||||
modes.add("auto");
|
||||
}
|
||||
if (found_heat) {
|
||||
modes.add("heat");
|
||||
}
|
||||
if (found_off) {
|
||||
modes.add("off");
|
||||
}
|
||||
}
|
||||
|
||||
add_ha_dev_section(doc.as<JsonObject>(), devicename, nullptr, nullptr, nullptr, false); // add dev section
|
||||
add_ha_avty_section(doc.as<JsonObject>(), topic_t, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); // add availability section
|
||||
|
||||
@@ -113,7 +113,7 @@ class Mqtt {
|
||||
const bool create_device_config = false);
|
||||
|
||||
static bool publish_system_ha_sensor_config(uint8_t type, const char * name, const char * entity, const uint8_t uom);
|
||||
static bool publish_ha_climate_config(const int8_t tag, const bool has_roomtemp, const bool remove = false, const int16_t min = 5, const uint32_t max = 30);
|
||||
static bool publish_ha_climate_config(const DeviceValue & dv, const bool has_roomtemp, const bool remove = false);
|
||||
|
||||
static void show_topic_handlers(uuid::console::Shell & shell, const uint8_t device_type);
|
||||
static void show_mqtt(uuid::console::Shell & shell);
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.7.3-dev.35"
|
||||
#define EMSESP_APP_VERSION "3.7.3-dev.36"
|
||||
|
||||
Reference in New Issue
Block a user