diff --git a/MqttTopics.h b/MqttTopics.h index b5ae1ffd..650a0545 100644 --- a/MqttTopics.h +++ b/MqttTopics.h @@ -41,6 +41,7 @@ #define mqtt_topic_info_hardware_version "/info/hardwareVersion" #define mqtt_topic_info_firmware_version "/info/firmwareVersion" #define mqtt_topic_info_nuki_hub_version "/info/nukiHubVersion" +#define mqtt_topic_info_nuki_hub_ip "/info/nukiHubIp" #define mqtt_topic_keypad "/keypad" #define mqtt_topic_keypad_command_action "/keypad/command/action" diff --git a/Network.cpp b/Network.cpp index e9515749..c643a0bd 100644 --- a/Network.cpp +++ b/Network.cpp @@ -491,6 +491,7 @@ bool Network::reconnect() } publishString(_maintenancePathPrefix, mqtt_topic_mqtt_connection_state, "online"); + publishString(_maintenancePathPrefix, mqtt_topic_info_nuki_hub_ip, _device->localIP().c_str()); _mqttConnectionState = 2; for(const auto& callback : _reconnectedCallbacks) @@ -719,6 +720,18 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n json["dev"]["mf"] = "Nuki"; json["dev"]["mdl"] = deviceType; json["dev"]["name"] = name; + + String cuUrl = _preferences->getString(preference_mqtt_hass_cu_url); + + if (cuUrl != "") + { + json["dev"]["cu"] = cuUrl; + } + else + { + json["dev"]["cu"] = "http://" + _device->localIP(); + } + json["~"] = baseTopic; json["name"] = nullptr; json["unique_id"] = String(uidString) + "_lock"; @@ -890,7 +903,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n publishHassTopic("sensor", "nuki_hub_version", uidString, - "_nuki_hub__version", + "_nuki_hub_version", "NUKI Hub version", name, baseTopic, @@ -903,6 +916,23 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n { { "enabled_by_default", "true" }, {"ic", "mdi:counter"}}); + // NUKI Hub IP Address + publishHassTopic("sensor", + "nuki_hub_ip", + uidString, + "_nuki_hub_ip", + "NUKI Hub IP", + name, + baseTopic, + _lockPath + mqtt_topic_info_nuki_hub_ip, + deviceType, + "", + "", + "diagnostic", + "", + { { "enabled_by_default", "true" }, + {"ic", "mdi:ip"}}); + // LED enabled publishHassTopic("switch", "led_enabled", @@ -1379,6 +1409,12 @@ void Network::removeHASSConfig(char* uidString) path.concat(uidString); path.concat("/sound_level/config"); _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); + + path = discoveryTopic; + path.concat("/sensor/"); + path.concat(uidString); + path.concat("/nuki_hub_ip/config"); + _device->mqttPublish(path.c_str(), MQTT_QOS_LEVEL, true, ""); path = discoveryTopic; path.concat("/number/"); diff --git a/PreferencesKeys.h b/PreferencesKeys.h index b6587722..13757d53 100644 --- a/PreferencesKeys.h +++ b/PreferencesKeys.h @@ -20,6 +20,7 @@ #define preference_mqtt_crt "mqttcrt" #define preference_mqtt_key "mqttkey" #define preference_mqtt_hass_discovery "hassdiscovery" +#define preference_mqtt_hass_cu_url "hassConfigUrl" #define preference_ip_dhcp_enabled "dhcpena" #define preference_ip_address "ipaddr" #define preference_ip_subnet "ipsub" @@ -64,7 +65,7 @@ class DebugPreferences preference_mqtt_user, preference_mqtt_password, preference_mqtt_log_enabled, preference_lock_enabled, preference_mqtt_lock_path, preference_opener_enabled, preference_mqtt_opener_path, preference_lock_max_keypad_code_count, preference_opener_max_keypad_code_count, preference_mqtt_ca, - preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery, + preference_mqtt_crt, preference_mqtt_key, preference_mqtt_hass_discovery, preference_mqtt_hass_cu_url, preference_ip_dhcp_enabled, preference_ip_address, preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server, preference_network_hardware, preference_network_wifi_fallback_disabled, preference_rssi_publish_interval, preference_hostname, preference_network_timeout, preference_restart_on_disconnect, diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 07f1446d..d6a13729 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -352,6 +352,11 @@ bool WebCfgServer::processArgs(String& message) configChanged = true; } } + else if(key == "HASSCUURL") + { + _preferences->putString(preference_mqtt_hass_cu_url, value); + configChanged = true; + } else if(key == "HOSTNAME") { _preferences->putString(preference_hostname, value); @@ -764,6 +769,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response) response.concat("