This commit is contained in:
MichaelDvP
2022-12-17 11:14:53 +01:00
20 changed files with 92 additions and 76 deletions

View File

@@ -451,14 +451,15 @@ void AnalogSensor::publish_values(const bool force) {
}
config["val_tpl"] = str;
char uniq_s[70];
if (Mqtt::multiple_instances()) {
snprintf(str, sizeof(str), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
snprintf(uniq_s, sizeof(uniq_s), "%s_analogsensor_%d", Mqtt::basename().c_str(), sensor.gpio());
} else {
snprintf(str, sizeof(str), "analogsensor_%d", sensor.gpio());
snprintf(uniq_s, sizeof(uniq_s), "analogsensor_%d", sensor.gpio());
}
config["object_id"] = str;
config["uniq_id"] = str; // same as object_id
config["object_id"] = uniq_s;
config["uniq_id"] = uniq_s; // same as object_id
snprintf(str, sizeof(str), "%s", sensor.name().c_str());
config["name"] = str;

View File

@@ -518,14 +518,15 @@ void DallasSensor::publish_values(const bool force) {
}
config["val_tpl"] = str;
char uniq_s[70];
if (Mqtt::multiple_instances()) {
snprintf(str, sizeof(str), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
snprintf(uniq_s, sizeof(uniq_s), "%s_dallassensor_%s", Mqtt::basename().c_str(), sensor.id().c_str());
} else {
snprintf(str, sizeof(str), "dallassensor_%s", sensor.id().c_str());
snprintf(uniq_s, sizeof(uniq_s), "dallassensor_%s", sensor.id().c_str());
}
config["object_id"] = str;
config["uniq_id"] = str; // same as object_id
config["object_id"] = uniq_s;
config["uniq_id"] = uniq_s; // same as object_id
snprintf(str, sizeof(str), "%s", sensor.name().c_str());
config["name"] = str;

View File

@@ -678,6 +678,10 @@ std::string Helpers::toUpper(std::string const & s) {
// replace char in char string
void Helpers::replace_char(char * str, char find, char replace) {
if (str == nullptr) {
return;
}
int i = 0;
while (str[i] != '\0') {

View File

@@ -225,7 +225,7 @@ MAKE_PSTR(tag_boiler_data_ww_mqtt, "ww")
MAKE_PSTR(tag_device_data_ww_mqtt, "")
// Home Assistant - this is special and has no translations
MAKE_PSTR_LIST(climate, "HA climate config creation")
MAKE_PSTR_LIST(climate, "")
// syslog
MAKE_PSTR_LIST(list_syslog_level, "off", "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace", "all")

View File

@@ -974,7 +974,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
const int16_t dv_set_max,
const JsonObject & dev_json) {
// ignore if name (fullname) is empty
if (!fullname) {
if (!fullname || !en_name) {
return;
}
@@ -989,14 +989,22 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
snprintf(entity_with_tag, sizeof(entity_with_tag), "%s", entity);
}
// build unique identifier which will be used in the topic, also used as object_id
// build unique identifier also used as object_id and becomes the Entity ID in HA
char uniq_id[70];
if (Mqtt::multiple_instances()) {
// prefix base name to each uniq_id and use the shortname
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
} else {
// old v3.4 style
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, en_name);
// take en_name and replace all spaces and lowercase it
char uniq_s[40];
strlcpy(uniq_s, en_name, sizeof(uniq_s));
Helpers::replace_char(uniq_s, ' ', '_');
if (EMSdevice::tag_to_string(tag).empty()) {
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, Helpers::toLower(uniq_s).c_str());
} else {
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", device_name, EMSdevice::tag_to_string(tag).c_str(), Helpers::toLower(uniq_s).c_str());
}
}
// build a config topic that will be prefix onto a HA type (e.g. number, switch)

View File

@@ -155,7 +155,11 @@ void Shower::set_shower_state(bool state, bool force) {
doc["name"] = "Shower Active";
char str[70];
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
if (Mqtt::multiple_instances()) {
snprintf(str, sizeof(str), "%s_shower_active", Mqtt::basename().c_str());
} else {
snprintf(str, sizeof(str), "shower_active"); // v3.4 compatible
}
doc["uniq_id"] = str;
doc["object_id"] = str;

View File

@@ -1059,11 +1059,11 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp
JsonObject node;
// System
node = output.createNestedObject("System Info");
node["version"] = EMSESP_APP_VERSION;
node["platform"] = EMSESP_PLATFORM;
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
// node["uptime (seconds)"] = uuid::get_uptime_sec();
node = output.createNestedObject("System Info");
node["version"] = EMSESP_APP_VERSION;
node["platform"] = EMSESP_PLATFORM;
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
node["uptime (seconds)"] = uuid::get_uptime_sec();
#ifndef EMSESP_STANDALONE
node["free mem"] = ESP.getFreeHeap() / 1024; // kilobytes
node["max alloc"] = ESP.getMaxAllocHeap() / 1024; // kilobytes

View File

@@ -30,12 +30,12 @@ namespace emsesp {
// #define EMSESP_DEBUG_DEFAULT "solar"
// #define EMSESP_DEBUG_DEFAULT "mixer"
// #define EMSESP_DEBUG_DEFAULT "web"
#define EMSESP_DEBUG_DEFAULT "mqtt"
// #define EMSESP_DEBUG_DEFAULT "mqtt"
// #define EMSESP_DEBUG_DEFAULT "general"
// #define EMSESP_DEBUG_DEFAULT "boiler"
// #define EMSESP_DEBUG_DEFAULT "mqtt2"
// #define EMSESP_DEBUG_DEFAULT "mqtt_nested"
// #define EMSESP_DEBUG_DEFAULT "ha"
#define EMSESP_DEBUG_DEFAULT "ha"
// #define EMSESP_DEBUG_DEFAULT "masked"
// #define EMSESP_DEBUG_DEFAULT "board_profile"
// #define EMSESP_DEBUG_DEFAULT "shower_alert"