From b9f57edb92392507f40df661e6ccbefb7fd6dd61 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Fri, 28 Oct 2022 22:53:23 +0200 Subject: [PATCH] added separate binary sensor "problem" indicating an error state --- .../jomjol_flowcontroll/ClassFlowMQTT.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 69f2d149..241d773d 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -65,10 +65,16 @@ void sendHomeAssistantDiscoveryTopic(std::string maintopic, std::string group, s "\"icon\": \"mdi:" + icon + "\"," + nl; if (group != "") { - payload += "\"state_topic\": \"~/" + group + "/" + field + "\"," + nl; + if (field == "problem") { // Special binary sensor which is based on error topic + payload += "\"state_topic\": \"~/" + group + "/error\"," + nl; + payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\"," + nl; + } + else { + payload += "\"state_topic\": \"~/" + group + "/" + field + "\"," + nl; + } } else { - payload += "\"state_topic\": \"~/" + field + "\"," + nl; + payload += "\"state_topic\": \"~/" + field + "\"," + nl; } if (unit != "") { @@ -77,9 +83,9 @@ void sendHomeAssistantDiscoveryTopic(std::string maintopic, std::string group, s if (deviceClass != "") { payload += "\"device_class\": \"" + deviceClass + "\"," + nl; - if (deviceClass == "problem") { + /* if (deviceClass == "problem") { payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\"," + nl; - } + }*/ } if (stateClass != "") { @@ -119,12 +125,14 @@ void MQTThomeassistantDiscovery(std::string maintopic) { for (int i = 0; i < (*NUMBERS).size(); ++i) { // maintopic group field User Friendly Name icon unit Device Class State Class sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "value", "Value", "gauge", "", "", "total_increasing"); - sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "error", "Error", "alert-circle-outline", "", "problem", ""); + sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "error", "Error", "alert-circle-outline", "", "", ""); sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "rate", "Rate", "swap-vertical", "", "", ""); sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "changeabsolut", "Absolute Change", "arrow-expand-vertical", "", "", "measurement"); sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "raw", "Raw Value", "raw", "", "", "total_increasing"); sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "timestamp", "Timestamp", "clock-time-eight-outline", "", "timestamp", ""); sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "json", "JSON", "code-json", "", "", ""); + + sendHomeAssistantDiscoveryTopic(maintopic, (*NUMBERS)[i]->name, "problem", "Problem", "code-json", "", "", ""); // Special binary sensor which is based on error topic } }