add home assistant door sensor auto discovery
This commit is contained in:
34
Network.cpp
34
Network.cpp
@@ -471,6 +471,40 @@ void Network::publishHASSConfigBatLevel(char *deviceType, const char *baseTopic,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::publishHASSConfigDoorSensor(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 != "")
|
||||||
|
{
|
||||||
|
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(" door sensor\",\"unique_id\":\"");
|
||||||
|
configJSON.concat(uidString);
|
||||||
|
configJSON.concat(
|
||||||
|
"_door_sensor\",\"dev_cla\":\"door\",\"stat_t\":\"~");
|
||||||
|
configJSON.concat(mqtt_topic_lock_door_sensor_state);
|
||||||
|
configJSON.concat("\",\"pl_off\":\"doorClosed\",\"pl_on\":\"doorOpened\",\"pl_not_avail\":\"unavailable\"");
|
||||||
|
configJSON.concat("}");
|
||||||
|
|
||||||
|
String path = discoveryTopic;
|
||||||
|
path.concat("/binary_sensor/");
|
||||||
|
path.concat(uidString);
|
||||||
|
path.concat("/door_sensor/config");
|
||||||
|
|
||||||
|
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Network::removeHASSConfig(char* uidString)
|
void Network::removeHASSConfig(char* uidString)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
|
|
||||||
void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState);
|
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 publishHASSConfigBatLevel(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState);
|
||||||
|
void publishHASSConfigDoorSensor(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState);
|
||||||
void removeHASSConfig(char* uidString);
|
void removeHASSConfig(char* uidString);
|
||||||
|
|
||||||
void publishPresenceDetection(char* csv);
|
void publishPresenceDetection(char* csv);
|
||||||
|
|||||||
@@ -456,6 +456,7 @@ NetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, char *na
|
|||||||
{
|
{
|
||||||
_network->publishHASSConfig(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
|
_network->publishHASSConfig(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
|
||||||
_network->publishHASSConfigBatLevel(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
|
_network->publishHASSConfigBatLevel(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
|
||||||
|
_network->publishHASSConfigDoorSensor(deviceType, baseTopic, name, uidString, lockAction, unlockAction, openAction, lockedState, unlockedState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkLock::removeHASSConfig(char *uidString)
|
void NetworkLock::removeHASSConfig(char *uidString)
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define nuki_hub_version "5.10"
|
#define nuki_hub_version "5.11"
|
||||||
@@ -568,10 +568,10 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
|||||||
|
|
||||||
response.concat("<h3>Advanced MQTT and Network Configuration</h3>");
|
response.concat("<h3>Advanced MQTT and Network Configuration</h3>");
|
||||||
response.concat("<table>");
|
response.concat("<table>");
|
||||||
|
printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable; usually homeassistant)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30);
|
||||||
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE);
|
printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE);
|
||||||
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
|
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
|
||||||
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
|
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
|
||||||
printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable; usually homeassistant)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30);
|
|
||||||
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
|
||||||
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
|
||||||
printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10);
|
printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user