mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-06 11:36:51 +03:00
Extend Homeassistant discovery with button for flow start (#3415)
* feat(homeassistant discovery): Add button for flow start * Update * Update * Allow Flow Start MQTT topic to have a zero-length payload * remove unused payload --------- Co-authored-by: Slider0007 <jobbelle@gmx.net>
This commit is contained in:
@@ -389,13 +389,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);
|
ESP_LOGD(TAG, "Handler called: topic %s, data %.*s", _topic.c_str(), _data_len, _data);
|
||||||
|
|
||||||
if (_data_len > 0) {
|
|
||||||
MQTTCtrlFlowStart(_topic);
|
MQTTCtrlFlowStart(_topic);
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "handler_flow_start: handler called, but no data");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,9 +86,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/..."
|
* This means a maintopic "home/test/watermeter" is transformed to the discovery topic "homeassistant/sensor/watermeter/..."
|
||||||
*/
|
*/
|
||||||
std::string node_id = createNodeId(maintopic);
|
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";
|
topicFull = "homeassistant/binary_sensor/" + node_id + "/" + configTopic + "/config";
|
||||||
}
|
}
|
||||||
|
else if (field == "flowstart") { // Special case: Button
|
||||||
|
topicFull = "homeassistant/button/" + node_id + "/" + configTopic + "/config";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
topicFull = "homeassistant/sensor/" + node_id + "/" + configTopic + "/config";
|
topicFull = "homeassistant/sensor/" + node_id + "/" + configTopic + "/config";
|
||||||
}
|
}
|
||||||
@@ -102,7 +105,7 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field,
|
|||||||
"\"icon\": \"mdi:" + icon + "\",";
|
"\"icon\": \"mdi:" + icon + "\",";
|
||||||
|
|
||||||
if (group != "") {
|
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 += "\"state_topic\": \"~/" + group + "/error\",";
|
||||||
payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\",";
|
payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\",";
|
||||||
}
|
}
|
||||||
@@ -111,10 +114,13 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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 += "\"state_topic\": \"~/error\",";
|
||||||
payload += "\"value_template\": \"{{ 'OFF' if 'no error' in value else 'ON'}}\",";
|
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
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
payload += "\"state_topic\": \"~/" + field + "\",";
|
payload += "\"state_topic\": \"~/" + field + "\",";
|
||||||
}
|
}
|
||||||
@@ -177,6 +183,7 @@ bool MQTThomeassistantDiscovery(int qos) {
|
|||||||
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "interval", "Interval", "clock-time-eight-outline", "min", "" , "measurement", "diagnostic", qos);
|
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "interval", "Interval", "clock-time-eight-outline", "min", "" , "measurement", "diagnostic", qos);
|
||||||
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "IP", "IP", "network-outline", "", "", "", "diagnostic", qos);
|
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "IP", "IP", "network-outline", "", "", "", "diagnostic", qos);
|
||||||
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "status", "Status", "list-status", "", "", "", "diagnostic", qos);
|
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "status", "Status", "list-status", "", "", "", "diagnostic", qos);
|
||||||
|
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic("", "flowstart", "Manual Flow Start", "timer-play-outline", "", "", "", "", qos);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < (*NUMBERS).size(); ++i) {
|
for (int i = 0; i < (*NUMBERS).size(); ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user