Skip to content

Commit

Permalink
feat(homeassistant discovery): Add button for flow start
Browse files Browse the repository at this point in the history
  • Loading branch information
Slider0007 committed Oct 19, 2024
1 parent bfde831 commit 908b81b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions code/components/jomjol_mqtt/server_mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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'}}\",";
}
Expand All @@ -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 + "\",";
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 908b81b

Please sign in to comment.