From 908b81be0f863b4cb42108717adeb627c752de1b Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 19 Oct 2024 23:32:38 +0200 Subject: [PATCH 1/5] 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) { From 598feb7a941f3b77241b7b075a8424f5d23d5389 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 19 Oct 2024 23:35:44 +0200 Subject: [PATCH 2/5] Update --- code/components/jomjol_mqtt/server_mqtt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index 28e41b882..5f2e58256 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -118,7 +118,7 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, 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 += "\"cmd_t\":\"~/ctrl/flow_start\","; // Add command topic payload += "\"pl_prs\":\"1\","; } else { From 351b01182906f96963047ed97835d99e778faef0 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Fri, 15 Nov 2024 14:59:57 +0100 Subject: [PATCH 3/5] Update --- code/components/jomjol_mqtt/server_mqtt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index 5f2e58256..ce55cf299 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -183,7 +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); + allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "flowstart", "Manual Flow Start", "timer-play-outline", "", "", "", "", qos); for (int i = 0; i < (*NUMBERS).size(); ++i) { From ba7b4ee1413bc35f14c2ccf6ae0be7dd7aa0b862 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Mon, 2 Dec 2024 20:36:43 +0100 Subject: [PATCH 4/5] Allow Flow Start MQTT topic to have a zero-length payload --- code/components/jomjol_mqtt/interface_mqtt.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index cb7a0ce44..c060de78a 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -388,13 +388,7 @@ bool mqtt_handler_flow_start(std::string _topic, char* _data, int _data_len) { ESP_LOGD(TAG, "Handler called: topic %s, data %.*s", _topic.c_str(), _data_len, _data); - if (_data_len > 0) { - MQTTCtrlFlowStart(_topic); - } - else { - LogFile.WriteToFile(ESP_LOG_WARN, TAG, "handler_flow_start: handler called, but no data"); - } - + MQTTCtrlFlowStart(_topic); return ESP_OK; } From 5e2c9948b273b4fc70dd700e6f1f9e09475c74f1 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Mon, 2 Dec 2024 21:24:33 +0100 Subject: [PATCH 5/5] remove unused payload --- code/components/jomjol_mqtt/server_mqtt.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index ce55cf299..2ec954af4 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -119,7 +119,6 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, } 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 + "\",";