add back obj_id for HA test

This commit is contained in:
MichaelDvP
2025-10-14 08:30:52 +02:00
parent 12b06aa657
commit 9d04058984
6 changed files with 41 additions and 32 deletions

View File

@@ -701,6 +701,7 @@ void AnalogSensor::publish_values(const bool force) {
} }
config["uniq_id"] = uniq_s; config["uniq_id"] = uniq_s;
config["obj_id"] = uniq_s;
char name[50]; char name[50];
snprintf(name, sizeof(name), "%s", sensor.name().c_str()); snprintf(name, sizeof(name), "%s", sensor.name().c_str());
@@ -773,7 +774,7 @@ void AnalogSensor::publish_values(const bool force) {
// add default_entity_id // add default_entity_id
std::string topic_str(topic); 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<JsonObject>(), "Analog Sensors", nullptr, nullptr, nullptr, false); Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Analog Sensors", nullptr, nullptr, nullptr, false);
Mqtt::add_ha_avail_section(config.as<JsonObject>(), stat_t, !is_ha_device_created, val_cond); Mqtt::add_ha_avail_section(config.as<JsonObject>(), stat_t, !is_ha_device_created, val_cond);

View File

@@ -528,15 +528,16 @@ void Mqtt::ha_status() {
strcpy(uniq, "system_status"); strcpy(uniq, "system_status");
} }
doc["uniq_id"] = uniq; doc["uniq_id"] = uniq;
doc["default_entity_id"] = (std::string) "binary_sensor." + uniq; doc["onj_id"] = uniq;
doc["stat_t"] = Mqtt::base() + "/status"; doc["def_ent_id"] = (std::string) "binary_sensor." + uniq;
doc["name"] = "System status"; doc["stat_t"] = Mqtt::base() + "/status";
doc["pl_on"] = "online"; doc["name"] = "System status";
doc["pl_off"] = "offline"; doc["pl_on"] = "online";
doc["stat_cla"] = "measurement"; doc["pl_off"] = "offline";
doc["dev_cla"] = "connectivity"; doc["stat_cla"] = "measurement";
doc["ent_cat"] = "diagnostic"; doc["dev_cla"] = "connectivity";
doc["ent_cat"] = "diagnostic";
// doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes // doc["avty_t"] = "~/status"; // commented out, as it causes errors in HA sometimes
// doc["json_attr_t"] = "~/heartbeat"; // store also as HA attributes // 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 // build the full payload
JsonDocument doc; JsonDocument doc;
doc["uniq_id"] = uniq_id; 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 // 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 // extract the string from topic up to the / using std::string
std::string topic_str(topic); 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 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; JsonDocument doc;
doc["~"] = Mqtt::base(); doc["~"] = Mqtt::base();
doc["uniq_id"] = uniq_id_s; doc["uniq_id"] = uniq_id_s;
doc["default_entity_id"] = (std::string) "climate." + uniq_id_s; doc["obj_id"] = uniq_id_s;
doc["name"] = name_s; doc["def_ent_id"] = (std::string) "climate." + uniq_id_s;
doc["mode_stat_t"] = topic_t; doc["name"] = name_s;
doc["mode_stat_tpl"] = mode_str_tpl; doc["mode_stat_t"] = topic_t;
doc["temp_cmd_t"] = temp_cmd_s; doc["mode_stat_tpl"] = mode_str_tpl;
doc["temp_stat_t"] = topic_t; doc["temp_cmd_t"] = temp_cmd_s;
doc["temp_stat_tpl"] = (std::string) "{{" + seltemp_s + " if " + seltemp_cond + " else 0}}"; doc["temp_stat_t"] = topic_t;
doc["temp_stat_tpl"] = (std::string) "{{" + seltemp_s + " if " + seltemp_cond + " else 0}}";
if (has_roomtemp) { if (has_roomtemp) {
doc["curr_temp_t"] = topic_t; 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; doc["mode_cmd_t"] = mode_cmd_s;
// add hvac_action - https://github.com/emsesp/EMS-ESP32/discussions/2562 // add hvac_action - https://github.com/emsesp/EMS-ESP32/discussions/2562
doc["action_topic"] = "~/boiler_data"; doc["act_t"] = "~/boiler_data";
doc["action_template"] = "{% if value_json.hpactivity=='cooling'%}cooling{%elif value_json.heatingactive=='on'%}heating{%else%}idle{%endif%}"; 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 // the HA climate component only responds to auto, heat and off
JsonArray modes = doc["modes"].to<JsonArray>(); JsonArray modes = doc["modes"].to<JsonArray>();

View File

@@ -205,8 +205,9 @@ void Shower::create_ha_discovery() {
} else { } else {
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
} }
doc["uniq_id"] = str; doc["uniq_id"] = str;
doc["default_entity_id"] = (std::string) "binary_sensor." + 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()); snprintf(stat_t, sizeof(stat_t), "%s/shower_active", Mqtt::base().c_str());
doc["stat_t"] = stat_t; 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()); snprintf(str, sizeof(str), "%s_shower_duration", Mqtt::basename().c_str());
doc["uniq_id"] = str; doc["uniq_id"] = str;
doc["default_entity_id"] = (std::string) "sensor." + 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()); snprintf(stat_t, sizeof(stat_t), "%s/shower_data", Mqtt::base().c_str());
doc["stat_t"] = stat_t; doc["stat_t"] = stat_t;

View File

@@ -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()); snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(temperaturesensor), sensor.id().c_str());
} }
config["uniq_id"] = uniq_s; config["uniq_id"] = uniq_s;
config["default_entity_id"] = (std::string) "sensor." + uniq_s; config["obj_id"] = uniq_s;
config["def_ent_id"] = (std::string) "sensor." + uniq_s;
char name[50]; char name[50];
snprintf(name, sizeof(name), "%s", sensor.name().c_str()); snprintf(name, sizeof(name), "%s", sensor.name().c_str());

View File

@@ -430,6 +430,7 @@ void WebCustomEntityService::publish(const bool force) {
snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(custom), entityItem.name.c_str()); snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(custom), entityItem.name.c_str());
config["uniq_id"] = uniq_s; config["uniq_id"] = uniq_s;
config["obj_id"] = uniq_s;
config["name"] = entityItem.name.c_str(); config["name"] = entityItem.name.c_str();
char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
@@ -462,7 +463,7 @@ void WebCustomEntityService::publish(const bool force) {
// add default_entity_id // add default_entity_id
std::string topic_str(topic); 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<JsonObject>(), EMSdevice::DeviceType::SYSTEM, entityItem.value_type, entityItem.uom); Mqtt::add_ha_classes(config.as<JsonObject>(), EMSdevice::DeviceType::SYSTEM, entityItem.value_type, entityItem.uom);
Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Custom Entities", nullptr, nullptr, nullptr, false); Mqtt::add_ha_dev_section(config.as<JsonObject>(), "Custom Entities", nullptr, nullptr, nullptr, false);

View File

@@ -282,9 +282,10 @@ void WebSchedulerService::publish(const bool force) {
char uniq_s[70]; char uniq_s[70];
snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(scheduler), scheduleItem.name.c_str()); snprintf(uniq_s, sizeof(uniq_s), "%s_%s", F_(scheduler), scheduleItem.name.c_str());
config["uniq_id"] = uniq_s; config["uniq_id"] = uniq_s;
config["name"] = scheduleItem.name.c_str(); config["obj_id"] = uniq_s;
config["default_entity_id"] = (std::string) "switch." + 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 topic[Mqtt::MQTT_TOPIC_MAX_SIZE];
char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; char command_topic[Mqtt::MQTT_TOPIC_MAX_SIZE];