diff --git a/Network.cpp b/Network.cpp index 69bc1e5f..c3ca3b6d 100644 --- a/Network.cpp +++ b/Network.cpp @@ -382,6 +382,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n _device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true); + // Battery critical configJSON = "{\"dev\":{\"ids\":[\"nuki_"; configJSON.concat(uidString); configJSON.concat("\"],\"mf\":\"Nuki\",\"mdl\":\""); @@ -405,9 +406,72 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n path.concat("/battery_low/config"); _device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true); + + // Battery voltage + configJSON = "{\"dev\":{\"ids\":[\"nuki_"; + configJSON.concat(uidString); + configJSON.concat("\"],\"mf\":\"Nuki\",\"mdl\":\""); + configJSON.concat(deviceType); + configJSON.concat("\",\"name\":\""); + configJSON.concat(name); + configJSON.concat("\"},\"~\":\""); + configJSON.concat(baseTopic); + configJSON.concat("\",\"name\":\""); + configJSON.concat(name); + configJSON.concat(" battery voltage\",\"unique_id\":\""); + configJSON.concat(uidString); + configJSON.concat( + "_battery_voltage\",\"dev_cla\":\"voltage\",\"ent_cat\":\"diagnostic\",\"stat_t\":\"~"); + configJSON.concat(mqtt_topic_battery_voltage); + configJSON.concat("\",\"state_cla\":\"measurement\",\"unit_of_meas\":\"V\""); + configJSON.concat("}"); + + path = discoveryTopic; + path.concat("/sensor/"); + path.concat(uidString); + path.concat("/battery_voltage/config"); + + _device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true); + } +} + +void Network::publishHASSConfigBatLevel(char *deviceType, const char *baseTopic, char *name, char *uidString, + char *lockAction, char *unlockAction, char *openAction, char *lockedState, + char *unlockedState) +{ + String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery); + + if (discoveryTopic != "") + { + // Battery level + String configJSON = "{\"dev\":{\"ids\":[\"nuki_"; + configJSON.concat(uidString); + configJSON.concat("\"],\"mf\":\"Nuki\",\"mdl\":\""); + configJSON.concat(deviceType); + configJSON.concat("\",\"name\":\""); + configJSON.concat(name); + configJSON.concat("\"},\"~\":\""); + configJSON.concat(baseTopic); + configJSON.concat("\",\"name\":\""); + configJSON.concat(name); + configJSON.concat(" battery level\",\"unique_id\":\""); + configJSON.concat(uidString); + configJSON.concat( + "_battery_level\",\"dev_cla\":\"battery\",\"ent_cat\":\"diagnostic\",\"stat_t\":\"~"); + configJSON.concat(mqtt_topic_battery_level); + configJSON.concat("\",\"state_cla\":\"measurement\",\"unit_of_meas\":\"%\""); + configJSON.concat("}"); + + String path = discoveryTopic; + path.concat("/sensor/"); + path.concat(uidString); + path.concat("/battery_level/config"); + + _device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true); } } + void Network::removeHASSConfig(char* uidString) { String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery); diff --git a/Network.h b/Network.h index 7d7eca01..cb7a064b 100644 --- a/Network.h +++ b/Network.h @@ -34,6 +34,7 @@ class Network bool publishString(const char* prefix, const char* topic, const char* value); void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState); + void publishHASSConfigBatLevel(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState); void removeHASSConfig(char* uidString); void publishPresenceDetection(char* csv); diff --git a/NetworkLock.cpp b/NetworkLock.cpp index d4904656..24acd4af 100644 --- a/NetworkLock.cpp +++ b/NetworkLock.cpp @@ -260,6 +260,7 @@ NetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, char *na char *unlockAction, char *openAction, char *lockedState, char *unlockedState) { _network->publishHASSConfig(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState); + _network->publishHASSConfigBatLevel(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState); } void NetworkLock::removeHASSConfig(char *uidString) diff --git a/Version.h b/Version.h index 345ba740..90f87887 100644 --- a/Version.h +++ b/Version.h @@ -1,3 +1,3 @@ #pragma once -#define nuki_hub_version "5.6" \ No newline at end of file +#define nuki_hub_version "5.7" \ No newline at end of file diff --git a/webflash/nuki_hub.bin b/webflash/nuki_hub.bin index 9119dd61..138ceb0b 100644 Binary files a/webflash/nuki_hub.bin and b/webflash/nuki_hub.bin differ