From 5b9aa508c082b00953a7485828f4340b32c184ee Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:24:54 +0200 Subject: [PATCH 1/3] add connection status entity for inverter --- src/MqttHandleHass.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/MqttHandleHass.cpp b/src/MqttHandleHass.cpp index d613355ac..65a6381e6 100644 --- a/src/MqttHandleHass.cpp +++ b/src/MqttHandleHass.cpp @@ -61,6 +61,7 @@ void MqttHandleHassClass::publishConfig() publishInverterNumber(inv, "Limit NonPersistent Absolute", "mdi:speedometer", "config", "cmd/limit_nonpersistent_absolute", "status/limit_absolute", "W", 10, 2250); publishInverterNumber(inv, "Limit Persistent Absolute", "mdi:speedometer", "config", "cmd/limit_persistent_absolute", "status/limit_absolute", "W", 10, 2250); + publishInverterBinarySensor(inv, "Status", "connectivity", "diagnostic", "status/reachable", "1", "0"); publishInverterBinarySensor(inv, "Reachable", "status/reachable", "1", "0"); publishInverterBinarySensor(inv, "Producing", "status/producing", "1", "0"); @@ -225,7 +226,7 @@ void MqttHandleHassClass::publishInverterNumber( publish(configTopic, buffer); } -void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off) +void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr inv, const char* caption, const char* device_class, const char* category, const char* subTopic, const char* payload_on, const char* payload_off) { String serial = inv->serialString(); @@ -242,6 +243,12 @@ void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptrname()) + " " + caption; root["uniq_id"] = serial + "_" + sensorId; + if (strcmp(device_class, "")) { + root["dev_cla"] = device_class; + } + if (strcmp(category, "")) { + root["ent_cat"] = category; + } root["stat_t"] = statTopic; root["pl_on"] = payload_on; root["pl_off"] = payload_off; @@ -269,4 +276,4 @@ void MqttHandleHassClass::publish(const String& subtopic, const String& payload) String topic = Configuration.get().Mqtt_Hass_Topic; topic += subtopic; MqttSettings.publishGeneric(topic.c_str(), payload.c_str(), Configuration.get().Mqtt_Hass_Retain); -} \ No newline at end of file +} From 6a10704f9f17b6da916bf60e68336b39aec5503e Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:41:31 +0200 Subject: [PATCH 2/3] Update MqttHandleHass.cpp --- src/MqttHandleHass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MqttHandleHass.cpp b/src/MqttHandleHass.cpp index 65a6381e6..311bd7078 100644 --- a/src/MqttHandleHass.cpp +++ b/src/MqttHandleHass.cpp @@ -62,8 +62,8 @@ void MqttHandleHassClass::publishConfig() publishInverterNumber(inv, "Limit Persistent Absolute", "mdi:speedometer", "config", "cmd/limit_persistent_absolute", "status/limit_absolute", "W", 10, 2250); publishInverterBinarySensor(inv, "Status", "connectivity", "diagnostic", "status/reachable", "1", "0"); - publishInverterBinarySensor(inv, "Reachable", "status/reachable", "1", "0"); - publishInverterBinarySensor(inv, "Producing", "status/producing", "1", "0"); + publishInverterBinarySensor(inv, "Reachable", "", "", "status/reachable", "1", "0"); + publishInverterBinarySensor(inv, "Producing", "", "", "status/producing", "1", "0"); // Loop all channels for (auto& t : inv->Statistics()->getChannelTypes()) { From 164030113912c7351d898f91e0c99977b3d672cc Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:42:08 +0200 Subject: [PATCH 3/3] Update MqttHandleHass.h --- include/MqttHandleHass.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/MqttHandleHass.h b/include/MqttHandleHass.h index 5bf7e71eb..3b28dab8e 100644 --- a/include/MqttHandleHass.h +++ b/include/MqttHandleHass.h @@ -60,11 +60,11 @@ class MqttHandleHassClass { void publishField(std::shared_ptr inv, ChannelType_t type, ChannelNum_t channel, byteAssign_fieldDeviceClass_t fieldType, bool clear = false); void publishInverterButton(std::shared_ptr inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload); void publishInverterNumber(std::shared_ptr inv, const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, int16_t min = 1, int16_t max = 100); - void publishInverterBinarySensor(std::shared_ptr inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off); + void publishInverterBinarySensor(std::shared_ptr inv, const char* caption, const char* device_class, const char* category, const char* subTopic, const char* payload_on, const char* payload_off); void createDeviceInfo(JsonObject& object, std::shared_ptr inv); bool _wasConnected = false; bool _updateForced = false; }; -extern MqttHandleHassClass MqttHandleHass; \ No newline at end of file +extern MqttHandleHassClass MqttHandleHass;