From 908b81be0f863b4cb42108717adeb627c752de1b Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 19 Oct 2024 23:32:38 +0200 Subject: [PATCH] feat(homeassistant discovery): Add button for flow start --- code/components/jomjol_mqtt/server_mqtt.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index 33c823f66..28e41b882 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -85,9 +85,12 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, * This means a maintopic "home/test/watermeter" is transformed to the discovery topic "homeassistant/sensor/watermeter/..." */ std::string node_id = createNodeId(maintopic); - if (field == "problem") { // Special binary sensor which is based on error topic + if (field == "problem") { // Special case: Binary sensor which is based on error topic topicFull = "homeassistant/binary_sensor/" + node_id + "/" + configTopic + "/config"; } + else if (field == "flowstart") { // Special case: Button + topicFull = "homeassistant/button/" + node_id + "/" + configTopic + "/config"; + } else { topicFull = "homeassistant/sensor/" + node_id + "/" + configTopic + "/config"; } @@ -101,7 +104,7 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, "\"icon\": \"mdi:" + icon + "\","; if (group != "") { - if (field == "problem") { // Special binary sensor which is based on error topic + if (field == "problem") { // Special case: Binary sensor which is based on error topic payload += "\"state_topic\": \"~/" + group + "/error\","; payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\","; } @@ -110,10 +113,14 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, } } else { - if (field == "problem") { // Special binary sensor which is based on error topic + if (field == "problem") { // Special case: Binary sensor which is based on error topic payload += "\"state_topic\": \"~/error\","; payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\","; } + else if (field == "flowstart") { // Special case: Button + payload += "\"cmd_t\":\"~" + "/ctrl/flow_start" + "\","; // Add command topic + payload += "\"pl_prs\":\"1\","; + } else { payload += "\"state_topic\": \"~/" + field + "\","; } @@ -176,6 +183,7 @@ bool MQTThomeassistantDiscovery(int qos) { allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "interval", "Interval", "clock-time-eight-outline", "min", "" , "measurement", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "IP", "IP", "network-outline", "", "", "", "diagnostic", qos); allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "status", "Status", "list-status", "", "", "", "diagnostic", qos); + allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "flowstart", "Manual Flow Start", "timer-play-outline", "", "update", "", "config", qos); for (int i = 0; i < (*NUMBERS).size(); ++i) {