diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index a1a39b6a7..771c876e6 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -701,6 +701,7 @@ void AnalogSensor::publish_values(const bool force) { } config["uniq_id"] = uniq_s; + config["obj_id"] = uniq_s; char name[50]; snprintf(name, sizeof(name), "%s", sensor.name().c_str()); @@ -773,7 +774,7 @@ void AnalogSensor::publish_values(const bool force) { // add default_entity_id std::string topic_str(topic); - doc["default_entity_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s; + doc["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s; Mqtt::add_ha_dev_section(config.as(), "Analog Sensors", nullptr, nullptr, nullptr, false); Mqtt::add_ha_avail_section(config.as(), stat_t, !is_ha_device_created, val_cond); diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 880d51f78..8e5c40032 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -528,15 +528,16 @@ void Mqtt::ha_status() { strcpy(uniq, "system_status"); } - doc["uniq_id"] = uniq; - doc["default_entity_id"] = (std::string) "binary_sensor." + uniq; - doc["stat_t"] = Mqtt::base() + "/status"; - doc["name"] = "System status"; - doc["pl_on"] = "online"; - doc["pl_off"] = "offline"; - doc["stat_cla"] = "measurement"; - doc["dev_cla"] = "connectivity"; - doc["ent_cat"] = "diagnostic"; + doc["uniq_id"] = uniq; + doc["onj_id"] = uniq; + doc["def_ent_id"] = (std::string) "binary_sensor." + uniq; + doc["stat_t"] = Mqtt::base() + "/status"; + doc["name"] = "System status"; + doc["pl_on"] = "online"; + doc["pl_off"] = "offline"; + doc["stat_cla"] = "measurement"; + doc["dev_cla"] = "connectivity"; + doc["ent_cat"] = "diagnostic"; // doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes // doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes @@ -980,11 +981,12 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev // build the full payload JsonDocument doc; doc["uniq_id"] = uniq_id; + doc["onj_id"] = uniq_id; // set the entity_id. This is breaking change in HA 2025.10.0 - see https://github.com/home-assistant/core/pull/151775 // extract the string from topic up to the / using std::string std::string topic_str(topic); - doc["default_entity_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_id; + doc["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_id; char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet @@ -1316,15 +1318,16 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp, JsonDocument doc; - doc["~"] = Mqtt::base(); - doc["uniq_id"] = uniq_id_s; - doc["default_entity_id"] = (std::string) "climate." + uniq_id_s; - doc["name"] = name_s; - doc["mode_stat_t"] = topic_t; - doc["mode_stat_tpl"] = mode_str_tpl; - doc["temp_cmd_t"] = temp_cmd_s; - doc["temp_stat_t"] = topic_t; - doc["temp_stat_tpl"] = (std::string) "{{" + seltemp_s + " if " + seltemp_cond + " else 0}}"; + doc["~"] = Mqtt::base(); + doc["uniq_id"] = uniq_id_s; + doc["obj_id"] = uniq_id_s; + doc["def_ent_id"] = (std::string) "climate." + uniq_id_s; + doc["name"] = name_s; + doc["mode_stat_t"] = topic_t; + doc["mode_stat_tpl"] = mode_str_tpl; + doc["temp_cmd_t"] = temp_cmd_s; + doc["temp_stat_t"] = topic_t; + doc["temp_stat_tpl"] = (std::string) "{{" + seltemp_s + " if " + seltemp_cond + " else 0}}"; if (has_roomtemp) { doc["curr_temp_t"] = topic_t; @@ -1337,8 +1340,8 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp, doc["mode_cmd_t"] = mode_cmd_s; // add hvac_action - https://github.com/emsesp/EMS-ESP32/discussions/2562 - doc["action_topic"] = "~/boiler_data"; - doc["action_template"] = "{% if value_json.hpactivity=='cooling'%}cooling{%elif value_json.heatingactive=='on'%}heating{%else%}idle{%endif%}"; + doc["act_t"] = "~/boiler_data"; + doc["act_tpl"] = "{% if value_json.hpactivity=='cooling'%}cooling{%elif value_json.heatingactive=='on'%}heating{%else%}idle{%endif%}"; // the HA climate component only responds to auto, heat and off JsonArray modes = doc["modes"].to(); diff --git a/src/core/shower.cpp b/src/core/shower.cpp index 3946171f3..fa3f5d673 100644 --- a/src/core/shower.cpp +++ b/src/core/shower.cpp @@ -205,8 +205,9 @@ void Shower::create_ha_discovery() { } else { snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible } - doc["uniq_id"] = str; - doc["default_entity_id"] = (std::string) "binary_sensor." + str; + doc["uniq_id"] = str; + doc["obj_id"] = str; + doc["def_ent_id"] = (std::string) "binary_sensor." + str; snprintf(stat_t, sizeof(stat_t), "%s/shower_active", Mqtt::base().c_str()); doc["stat_t"] = stat_t; @@ -223,8 +224,9 @@ void Shower::create_ha_discovery() { snprintf(str, sizeof(str), "%s_shower_duration", Mqtt::basename().c_str()); - doc["uniq_id"] = str; - doc["default_entity_id"] = (std::string) "sensor." + str; + doc["uniq_id"] = str; + doc["obj_id"] = str; + doc["def_ent_id"] = (std::string) "sensor." + str; snprintf(stat_t, sizeof(stat_t), "%s/shower_data", Mqtt::base().c_str()); doc["stat_t"] = stat_t; diff --git a/src/core/temperaturesensor.cpp b/src/core/temperaturesensor.cpp index 8e17ef4f4..039cda598 100644 --- a/src/core/temperaturesensor.cpp +++ b/src/core/temperaturesensor.cpp @@ -531,8 +531,9 @@ void TemperatureSensor::publish_values(const bool force) { snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(temperaturesensor), sensor.id().c_str()); } - config["uniq_id"] = uniq_s; - config["default_entity_id"] = (std::string) "sensor." + uniq_s; + config["uniq_id"] = uniq_s; + config["obj_id"] = uniq_s; + config["def_ent_id"] = (std::string) "sensor." + uniq_s; char name[50]; snprintf(name, sizeof(name), "%s", sensor.name().c_str()); diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index 8311ce2c5..61c8e8c77 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -430,6 +430,7 @@ void WebCustomEntityService::publish(const bool force) { snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(custom), entityItem.name.c_str()); config["uniq_id"] = uniq_s; + config["obj_id"] = uniq_s; config["name"] = entityItem.name.c_str(); char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; @@ -462,7 +463,7 @@ void WebCustomEntityService::publish(const bool force) { // add default_entity_id std::string topic_str(topic); - config["default_entity_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s; + config["def_ent_id"] = topic_str.substr(0, topic_str.find("/")) + "." + uniq_s; Mqtt::add_ha_classes(config.as(), EMSdevice::DeviceType::SYSTEM, entityItem.value_type, entityItem.uom); Mqtt::add_ha_dev_section(config.as(), "Custom Entities", nullptr, nullptr, nullptr, false); diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 73813042e..e78aac6c6 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -282,9 +282,10 @@ void WebSchedulerService::publish(const bool force) { char uniq_s[70]; snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(scheduler), scheduleItem.name.c_str()); - config["uniq_id"] = uniq_s; - config["name"] = scheduleItem.name.c_str(); - config["default_entity_id"] = (std::string) "switch." + uniq_s; + config["uniq_id"] = uniq_s; + config["obj_id"] = uniq_s; + config["name"] = scheduleItem.name.c_str(); + config["def_ent_id"] = (std::string) "switch." + uniq_s; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];