Add input form for HASS discovery topic
This commit is contained in:
111
Network.cpp
111
Network.cpp
@@ -345,64 +345,71 @@ void Network::publishPresenceDetection(char *csv)
|
|||||||
|
|
||||||
void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState)
|
void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction, char* lockedState, char* unlockedState)
|
||||||
{
|
{
|
||||||
String configJSON = "{\"dev\":{\"ids\":[\"nuki_";
|
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||||
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("\",\"unique_id\":\"");
|
|
||||||
configJSON.concat(uidString);
|
|
||||||
configJSON.concat("_lock\",\"cmd_t\":\"~");
|
|
||||||
configJSON.concat(mqtt_topic_lock_action);
|
|
||||||
configJSON.concat("\",\"pl_lock\":\"");
|
|
||||||
configJSON.concat(lockAction);
|
|
||||||
configJSON.concat("\",\"pl_unlk\":\"");
|
|
||||||
configJSON.concat(unlockAction);
|
|
||||||
configJSON.concat("\",\"pl_open\":\"");
|
|
||||||
configJSON.concat(openAction);
|
|
||||||
configJSON.concat("\",\"stat_t\":\"~");
|
|
||||||
configJSON.concat(mqtt_topic_lock_state);
|
|
||||||
configJSON.concat("\",\"stat_locked\":\"");
|
|
||||||
configJSON.concat(lockedState);
|
|
||||||
configJSON.concat("\",\"stat_unlocked\":\"");
|
|
||||||
configJSON.concat(unlockedState);
|
|
||||||
configJSON.concat("\",\"opt\":\"false\"}");
|
|
||||||
|
|
||||||
String path = "homeassistant/lock/";
|
if(discoveryTopic != "")
|
||||||
path.concat(uidString);
|
{
|
||||||
path.concat("/smartlock/config");
|
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("\",\"unique_id\":\"");
|
||||||
|
configJSON.concat(uidString);
|
||||||
|
configJSON.concat("_lock\",\"cmd_t\":\"~");
|
||||||
|
configJSON.concat(mqtt_topic_lock_action);
|
||||||
|
configJSON.concat("\",\"pl_lock\":\"");
|
||||||
|
configJSON.concat(lockAction);
|
||||||
|
configJSON.concat("\",\"pl_unlk\":\"");
|
||||||
|
configJSON.concat(unlockAction);
|
||||||
|
configJSON.concat("\",\"pl_open\":\"");
|
||||||
|
configJSON.concat(openAction);
|
||||||
|
configJSON.concat("\",\"stat_t\":\"~");
|
||||||
|
configJSON.concat(mqtt_topic_lock_state);
|
||||||
|
configJSON.concat("\",\"stat_locked\":\"");
|
||||||
|
configJSON.concat(lockedState);
|
||||||
|
configJSON.concat("\",\"stat_unlocked\":\"");
|
||||||
|
configJSON.concat(unlockedState);
|
||||||
|
configJSON.concat("\",\"opt\":\"false\"}");
|
||||||
|
|
||||||
Serial.println("HASS Config:");
|
String path = discoveryTopic;
|
||||||
Serial.println(configJSON);
|
path.concat("/lock/");
|
||||||
|
path.concat(uidString);
|
||||||
|
path.concat("/smartlock/config");
|
||||||
|
|
||||||
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
Serial.println("HASS Config:");
|
||||||
|
Serial.println(configJSON);
|
||||||
|
|
||||||
configJSON = "{\"dev\":{\"ids\":[\"nuki_";
|
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
||||||
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 low\",\"unique_id\":\"");
|
|
||||||
configJSON.concat(uidString);
|
|
||||||
configJSON.concat("_battery_low\",\"dev_cla\":\"battery\",\"ent_cat\":\"diagnostic\",\"pl_off\":\"0\",\"pl_on\":\"1\",\"stat_t\":\"~");
|
|
||||||
configJSON.concat(mqtt_topic_battery_critical);
|
|
||||||
configJSON.concat("\"}");
|
|
||||||
|
|
||||||
path = "homeassistant/binary_sensor/";
|
configJSON = "{\"dev\":{\"ids\":[\"nuki_";
|
||||||
path.concat(uidString);
|
configJSON.concat(uidString);
|
||||||
path.concat("/battery_low/config");
|
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 low\",\"unique_id\":\"");
|
||||||
|
configJSON.concat(uidString);
|
||||||
|
configJSON.concat("_battery_low\",\"dev_cla\":\"battery\",\"ent_cat\":\"diagnostic\",\"pl_off\":\"0\",\"pl_on\":\"1\",\"stat_t\":\"~");
|
||||||
|
configJSON.concat(mqtt_topic_battery_critical);
|
||||||
|
configJSON.concat("\"}");
|
||||||
|
|
||||||
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
path = discoveryTopic;
|
||||||
|
path.concat("/binary_sensor/");
|
||||||
|
path.concat(uidString);
|
||||||
|
path.concat("/battery_low/config");
|
||||||
|
|
||||||
|
_device->mqttClient()->publish(path.c_str(), configJSON.c_str(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
|
void Network::setLockActionReceivedCallback(bool (*lockActionReceivedCallback)(const char *))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#define preference_mqtt_ca "mqttca"
|
#define preference_mqtt_ca "mqttca"
|
||||||
#define preference_mqtt_crt "mqttcrt"
|
#define preference_mqtt_crt "mqttcrt"
|
||||||
#define preference_mqtt_key "mqttkey"
|
#define preference_mqtt_key "mqttkey"
|
||||||
|
#define preference_mqtt_hass_discovery "hassdiscovery"
|
||||||
#define preference_hostname "hostname"
|
#define preference_hostname "hostname"
|
||||||
#define preference_network_timeout "nettmout"
|
#define preference_network_timeout "nettmout"
|
||||||
#define preference_query_interval_lockstate "lockStInterval"
|
#define preference_query_interval_lockstate "lockStInterval"
|
||||||
|
|||||||
@@ -225,6 +225,11 @@ bool WebCfgServer::processArgs(String& message)
|
|||||||
_preferences->putString(preference_mqtt_key, value);
|
_preferences->putString(preference_mqtt_key, value);
|
||||||
configChanged = true;
|
configChanged = true;
|
||||||
}
|
}
|
||||||
|
else if(key == "HASSDISCOVERY")
|
||||||
|
{
|
||||||
|
_preferences->putString(preference_mqtt_hass_discovery, value);
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
else if(key == "HOSTNAME")
|
else if(key == "HOSTNAME")
|
||||||
{
|
{
|
||||||
_preferences->putString(preference_hostname, value);
|
_preferences->putString(preference_hostname, value);
|
||||||
@@ -493,6 +498,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
|
|||||||
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)", _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);
|
||||||
response.concat("</table>");
|
response.concat("</table>");
|
||||||
response.concat("* If no encryption is configured for the MQTT broker, leave empty.<br>");
|
response.concat("* If no encryption is configured for the MQTT broker, leave empty.<br>");
|
||||||
|
|||||||
Reference in New Issue
Block a user