From b3ee5f4d9a7e4112af31520f108639d13ae5d954 Mon Sep 17 00:00:00 2001 From: pswid <78219494+pswid@users.noreply.github.com> Date: Mon, 30 Jan 2023 12:05:16 +0100 Subject: [PATCH 1/4] added link to the EMS-ESP web interface in HA (IPv4 only) --- src/mqtt.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 7f000fe58..f955b5af2 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -610,8 +610,8 @@ void Mqtt::ha_status() { strcpy(uniq, "system_status"); } - doc["uniq_id"] = uniq; - doc["obj_id"] = uniq; + doc["uniq_id"] = uniq; + doc["obj_id"] = uniq; doc["stat_t"] = mqtt_base_ + "/status"; doc["name"] = "EMS-ESP status"; @@ -628,7 +628,11 @@ void Mqtt::ha_status() { dev["sw"] = "v" + std::string(EMSESP_APP_VERSION); dev["mf"] = "proddy"; dev["mdl"] = "EMS-ESP"; - JsonArray ids = dev.createNestedArray("ids"); + if (EMSESP::system_.ethernet_connected()) + dev["cu"] = ETH.localIP().toString(); + else + dev["cu"] = WiFi.localIP().toString(); + JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp"); char topic[MQTT_TOPIC_MAX_SIZE]; @@ -1066,7 +1070,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev doc["obj_id"] = uniq_id; // same as unique_id const char * ic_ha = "ic"; // icon - only set this if there is no device class - const char * sc_ha = "state_class"; // state class + const char * sc_ha = "stat_cla"; // state class const char * uom_ha = "unit_of_meas"; // unit of measure // handle commands, which are device entities that are writable @@ -1084,7 +1088,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev // for enums, add options if (type == DeviceValueType::ENUM) { - JsonArray option_list = doc.createNestedArray("options"); + JsonArray option_list = doc.createNestedArray("ops"); //options for (uint8_t i = 0; i < options_size; i++) { option_list.add(Helpers::translated_word(options[i])); } @@ -1187,7 +1191,7 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev // this next section is adding the state class, device class and sometimes the icon // used for Sensor and Binary Sensor Entities in HA if (set_ha_classes) { - const char * dc_ha = "device_class"; // device class + const char * dc_ha = "dev_cla"; // device class switch (uom) { case DeviceValueUOM::DEGREES: From b18da9064bdee6d5887d98825e62793efd2dfdb1 Mon Sep 17 00:00:00 2001 From: pswid <78219494+pswid@users.noreply.github.com> Date: Mon, 30 Jan 2023 18:31:57 +0100 Subject: [PATCH 2/4] fixed link to the EMS-ESP in HA prefix "http:// " is needed though --- src/mqtt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index f955b5af2..f56a1f785 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -629,9 +629,9 @@ void Mqtt::ha_status() { dev["mf"] = "proddy"; dev["mdl"] = "EMS-ESP"; if (EMSESP::system_.ethernet_connected()) - dev["cu"] = ETH.localIP().toString(); + dev["cu"] = "http://" + ETH.localIP().toString(); else - dev["cu"] = WiFi.localIP().toString(); + dev["cu"] = "http://" + WiFi.localIP().toString(); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp"); From 997ced393873070ce4f5ea92421e16a10f23a40d Mon Sep 17 00:00:00 2001 From: pswid <78219494+pswid@users.noreply.github.com> Date: Mon, 30 Jan 2023 19:37:50 +0100 Subject: [PATCH 3/4] system entities moved to "diagnostic" category in HA --- src/mqtt.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index f56a1f785..2034bd354 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -619,6 +619,7 @@ void Mqtt::ha_status() { 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 @@ -1275,6 +1276,11 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } } + // add category "diagnostic" for system entities + if (device_type == EMSdevice::DeviceType::SYSTEM) { + doc["ent_cat"] = "diagnostic"; + } + // add the dev json object to the end doc["dev"] = dev_json; From e3e14e7a665c665dfb268abda7374b8c857aff1b Mon Sep 17 00:00:00 2001 From: pswid <78219494+pswid@users.noreply.github.com> Date: Mon, 30 Jan 2023 19:50:36 +0100 Subject: [PATCH 4/4] fixed NTP status in HA (see #931) I missed this one --- src/system.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index 21a904d49..36a816126 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -595,10 +595,7 @@ bool System::heartbeat_json(JsonObject & output) { output["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); output["uptime_sec"] = uuid::get_uptime_sec(); bool value_b = ntp_connected(); - if (Mqtt::ha_enabled()) { - char s[12]; - output["ntp_status"] = Helpers::render_boolean(s, value_b); // for HA always render as string - } else if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) { + if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) { output["ntp_status"] = value_b; } else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) { output["ntp_status"] = value_b ? 1 : 0;