From 33931110321f4346f701d55dd62c961053042e7b Mon Sep 17 00:00:00 2001 From: iranl Date: Fri, 2 Feb 2024 22:07:13 +0100 Subject: [PATCH 1/3] Add Home Assistant Auto Discovery buttons --- Network.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Network.cpp b/Network.cpp index 6224498..310f972 100644 --- a/Network.cpp +++ b/Network.cpp @@ -942,6 +942,55 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n { "pl_off", "0" }, { "state_on", "1" }, { "state_off", "0" }}); + + // Lock 'n' Go + publishHassTopic("button", + "lockngo", + uidString, + "_lock_n_go_button", + "Lock 'n' Go", + name, + baseTopic, + mqtt_topic_mqtt_connection_state, + deviceType, + "", + "", + "", + mqtt_topic_lock_action, + { { "pl_prs", "lockNgo" }}); + + // Lock 'n' Go with unlatch + publishHassTopic("button", + "lockngounlatch", + uidString, + "_lock_n_go_unlatch_button", + "Lock 'n' Go with unlatch", + name, + baseTopic, + mqtt_topic_mqtt_connection_state, + deviceType, + "", + "", + "", + mqtt_topic_lock_action, + { { "pl_prs", "lockNgoUnlatch" }}); + + // Unlatch + publishHassTopic("button", + "unlatch", + uidString, + "_unlatch_button", + "Unlatch", + name, + baseTopic, + mqtt_topic_mqtt_connection_state, + deviceType, + "", + "", + "", + mqtt_topic_lock_action, + { { "pl_prs", "unlatch" }}); + } } //json["cmd_t"] = String("~") + String(mqtt_topic_lock_action); @@ -1271,6 +1320,24 @@ void Network::removeHASSConfig(char* uidString) path.concat(uidString); path.concat("/battery_low/config"); _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); + + path = discoveryTopic; + path.concat("/button/"); + path.concat(uidString); + path.concat("/lockngo/config"); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); + + path = discoveryTopic; + path.concat("/button/"); + path.concat(uidString); + path.concat("/lockngounlatch/config"); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); + + path = discoveryTopic; + path.concat("/button/"); + path.concat(uidString); + path.concat("/unlatch/config"); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/sensor/"); From e9aed30a334618dae28f90e0d253d5d152f1c2ea Mon Sep 17 00:00:00 2001 From: iranl Date: Sun, 4 Feb 2024 14:36:30 +0100 Subject: [PATCH 2/3] Add files via upload --- Network.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Network.cpp b/Network.cpp index 310f972..ce3d07c 100644 --- a/Network.cpp +++ b/Network.cpp @@ -957,7 +957,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "pl_prs", "lockNgo" }}); + { { "enabled_by_default", "true" }, + { "pl_prs", "lockNgo" }}); // Lock 'n' Go with unlatch publishHassTopic("button", @@ -973,7 +974,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "pl_prs", "lockNgoUnlatch" }}); + { { "enabled_by_default", "true" }, + { "pl_prs", "lockNgoUnlatch" }}); // Unlatch publishHassTopic("button", @@ -989,7 +991,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "pl_prs", "unlatch" }}); + { { "enabled_by_default", "true" }, + { "pl_prs", "unlatch" }}); } } From 5ade0573f308e1ef31c47c238ed56ab190ca7a01 Mon Sep 17 00:00:00 2001 From: iranl Date: Sun, 4 Feb 2024 14:37:35 +0100 Subject: [PATCH 3/3] Add buttons as disabled by default --- Network.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Network.cpp b/Network.cpp index ce3d07c..912f0ca 100644 --- a/Network.cpp +++ b/Network.cpp @@ -957,7 +957,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "enabled_by_default", "true" }, + { { "enabled_by_default", "false" }, { "pl_prs", "lockNgo" }}); // Lock 'n' Go with unlatch @@ -974,7 +974,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "enabled_by_default", "true" }, + { { "enabled_by_default", "false" }, { "pl_prs", "lockNgoUnlatch" }}); // Unlatch @@ -991,7 +991,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n "", "", mqtt_topic_lock_action, - { { "enabled_by_default", "true" }, + { { "enabled_by_default", "false" }, { "pl_prs", "unlatch" }}); }