mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
add back obj_id for HA test
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -529,7 +529,8 @@ void Mqtt::ha_status() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doc["uniq_id"] = uniq;
|
doc["uniq_id"] = uniq;
|
||||||
doc["default_entity_id"] = (std::string) "binary_sensor." + uniq;
|
doc["onj_id"] = uniq;
|
||||||
|
doc["def_ent_id"] = (std::string) "binary_sensor." + uniq;
|
||||||
doc["stat_t"] = Mqtt::base() + "/status";
|
doc["stat_t"] = Mqtt::base() + "/status";
|
||||||
doc["name"] = "System status";
|
doc["name"] = "System status";
|
||||||
doc["pl_on"] = "online";
|
doc["pl_on"] = "online";
|
||||||
@@ -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
|
||||||
|
|
||||||
@@ -1318,7 +1320,8 @@ bool Mqtt::publish_ha_climate_config(const int8_t tag, const bool has_roomtemp,
|
|||||||
|
|
||||||
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["def_ent_id"] = (std::string) "climate." + uniq_id_s;
|
||||||
doc["name"] = name_s;
|
doc["name"] = name_s;
|
||||||
doc["mode_stat_t"] = topic_t;
|
doc["mode_stat_t"] = topic_t;
|
||||||
doc["mode_stat_tpl"] = mode_str_tpl;
|
doc["mode_stat_tpl"] = mode_str_tpl;
|
||||||
@@ -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>();
|
||||||
|
|||||||
@@ -206,7 +206,8 @@ void Shower::create_ha_discovery() {
|
|||||||
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;
|
||||||
@@ -224,7 +225,8 @@ 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;
|
||||||
|
|||||||
@@ -532,7 +532,8 @@ void TemperatureSensor::publish_values(const bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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());
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -283,8 +283,9 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
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["obj_id"] = uniq_s;
|
||||||
config["name"] = scheduleItem.name.c_str();
|
config["name"] = scheduleItem.name.c_str();
|
||||||
config["default_entity_id"] = (std::string) "switch." + uniq_s;
|
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];
|
||||||
|
|||||||
Reference in New Issue
Block a user