fix ha autodiscovery topics
This commit is contained in:
2
Config.h
2
Config.h
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NUKI_HUB_VERSION "8.9-json-4"
|
#define NUKI_HUB_VERSION "8.9-json-5"
|
||||||
|
|
||||||
#define MQTT_QOS_LEVEL 1
|
#define MQTT_QOS_LEVEL 1
|
||||||
#define MQTT_CLEAN_SESSIONS false
|
#define MQTT_CLEAN_SESSIONS false
|
||||||
94
Network.cpp
94
Network.cpp
@@ -596,9 +596,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
|||||||
"battery",
|
"battery",
|
||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"",
|
{{"pl_on", "1"},
|
||||||
"1",
|
{"pl_off", "0"}});
|
||||||
"0");
|
|
||||||
|
|
||||||
if(hasKeypad)
|
if(hasKeypad)
|
||||||
{
|
{
|
||||||
@@ -615,9 +614,8 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
|||||||
"battery",
|
"battery",
|
||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"",
|
{{"pl_on", "1"},
|
||||||
"1",
|
{"pl_off", "0"}});
|
||||||
"0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Battery voltage
|
// Battery voltage
|
||||||
@@ -633,7 +631,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
|||||||
"voltage",
|
"voltage",
|
||||||
"measurement",
|
"measurement",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"V");
|
{ {"unit_of_meas", "V"} });
|
||||||
|
|
||||||
// Trigger
|
// Trigger
|
||||||
publishHassTopic("sensor",
|
publishHassTopic("sensor",
|
||||||
@@ -648,11 +646,7 @@ void Network::publishHASSConfig(char* deviceType, const char* baseTopic, char* n
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"",
|
{ { "enabled_by_default", "true" } });
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"true");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +670,7 @@ void Network::publishHASSConfigBatLevel(char *deviceType, const char *baseTopic,
|
|||||||
"battery",
|
"battery",
|
||||||
"measurement",
|
"measurement",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
"%");
|
{ {"unit_of_meas", "%"} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,10 +694,9 @@ void Network::publishHASSConfigDoorSensor(char *deviceType, const char *baseTopi
|
|||||||
"door",
|
"door",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
"",
|
{{"pl_on", "doorOpened"},
|
||||||
"doorOpened",
|
{"pl_off", "doorClosed"},
|
||||||
"doorClosed",
|
{"pl_not_avail", "unavailable"}});
|
||||||
"unavailable");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,16 +708,20 @@ void Network::publishHASSConfigRingDetect(char *deviceType, const char *baseTopi
|
|||||||
|
|
||||||
if (discoveryTopic != "")
|
if (discoveryTopic != "")
|
||||||
{
|
{
|
||||||
publishHassTopic("sensor",
|
publishHassTopic("binary_sensor",
|
||||||
"ring",
|
"ring",
|
||||||
uidString,
|
uidString,
|
||||||
"_ring_detect",
|
"_ring_detect",
|
||||||
"ring detect",
|
"ring detect",
|
||||||
name,
|
name,
|
||||||
baseTopic,
|
baseTopic,
|
||||||
mqtt_topic_lock_door_sensor_state,
|
mqtt_topic_lock_state,
|
||||||
deviceType,
|
deviceType,
|
||||||
"sound");
|
"sound",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
{{"pl_on", "ring"},
|
||||||
|
{"pl_off", "locked"}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,7 +736,19 @@ void Network::publishHASSWifiRssiConfig(char *deviceType, const char *baseTopic,
|
|||||||
|
|
||||||
if (discoveryTopic != "")
|
if (discoveryTopic != "")
|
||||||
{
|
{
|
||||||
publishHassTopic("sensor", "wifi_signal_strength", uidString, "_wifi_signal_strength", "wifi signal strength", name, baseTopic, mqtt_topic_wifi_rssi, deviceType, "signal_strength", "measurement", "diagnostic", "dBm");
|
publishHassTopic("sensor",
|
||||||
|
"wifi_signal_strength",
|
||||||
|
uidString,
|
||||||
|
"_wifi_signal_strength",
|
||||||
|
"wifi signal strength",
|
||||||
|
name,
|
||||||
|
baseTopic,
|
||||||
|
mqtt_topic_wifi_rssi,
|
||||||
|
deviceType,
|
||||||
|
"signal_strength",
|
||||||
|
"measurement",
|
||||||
|
"diagnostic",
|
||||||
|
{ {"unit_of_meas", "dBm"} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +758,19 @@ void Network::publishHASSBleRssiConfig(char *deviceType, const char *baseTopic,
|
|||||||
|
|
||||||
if (discoveryTopic != "")
|
if (discoveryTopic != "")
|
||||||
{
|
{
|
||||||
publishHassTopic("sensor", "bluetooth_signal_strength", uidString, "_bluetooth_signal_strength", "bluetooth signal strength", name, baseTopic, mqtt_topic_lock_rssi, deviceType, "signal_strength", "measurement", "diagnostic", "dBm");
|
publishHassTopic("sensor",
|
||||||
|
"bluetooth_signal_strength",
|
||||||
|
uidString,
|
||||||
|
"_bluetooth_signal_strength",
|
||||||
|
"bluetooth signal strength",
|
||||||
|
name,
|
||||||
|
baseTopic,
|
||||||
|
mqtt_topic_lock_rssi,
|
||||||
|
deviceType,
|
||||||
|
"signal_strength",
|
||||||
|
"measurement",
|
||||||
|
"diagnostic",
|
||||||
|
{ {"unit_of_meas", "dBm"} });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,12 +786,8 @@ void Network::publishHassTopic(const String& mqttDeviceType,
|
|||||||
const String& deviceClass,
|
const String& deviceClass,
|
||||||
const String& stateClass,
|
const String& stateClass,
|
||||||
const String& entityCat,
|
const String& entityCat,
|
||||||
const String& unitOfMeasurement,
|
std::vector<std::pair<char*, char*>> additionalEntries
|
||||||
const String& plOn,
|
)
|
||||||
const String& plOff,
|
|
||||||
const String& plNotAvailable,
|
|
||||||
const String& enabledByDefault
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
String discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery);
|
||||||
|
|
||||||
@@ -805,26 +822,9 @@ void Network::publishHassTopic(const String& mqttDeviceType,
|
|||||||
json["ent_cat"] = entityCat;
|
json["ent_cat"] = entityCat;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitOfMeasurement != "")
|
for(const auto& entry : additionalEntries)
|
||||||
{
|
{
|
||||||
json["unit_of_meas"] = unitOfMeasurement;
|
json[entry.first] = entry.second;
|
||||||
}
|
|
||||||
|
|
||||||
if (plOff != "")
|
|
||||||
{
|
|
||||||
json["pl_off"] = plOff;
|
|
||||||
}
|
|
||||||
if (plOn != "")
|
|
||||||
{
|
|
||||||
json["pl_on"] = plOn;
|
|
||||||
}
|
|
||||||
if (plNotAvailable != "")
|
|
||||||
{
|
|
||||||
json["pl_not_avail"] = plNotAvailable;
|
|
||||||
}
|
|
||||||
if (enabledByDefault != "")
|
|
||||||
{
|
|
||||||
json["enabled_by_default"] = "true";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serializeJson(json, reinterpret_cast<char (&)[JSON_BUFFER_SIZE]>(*jsonOut));
|
serializeJson(json, reinterpret_cast<char (&)[JSON_BUFFER_SIZE]>(*jsonOut));
|
||||||
|
|||||||
@@ -76,11 +76,7 @@ private:
|
|||||||
const String& deviceClass,
|
const String& deviceClass,
|
||||||
const String& stateClass = "",
|
const String& stateClass = "",
|
||||||
const String& entityCat = "",
|
const String& entityCat = "",
|
||||||
const String& unitOfMeasurement = "",
|
std::vector<std::pair<char*, char*>> additionalEntries = {}
|
||||||
const String& plOn = "",
|
|
||||||
const String& plOff = "",
|
|
||||||
const String& plNotAvailable = "",
|
|
||||||
const String& enabledByDefault = ""
|
|
||||||
);
|
);
|
||||||
|
|
||||||
void onMqttConnect(const bool& sessionPresent);
|
void onMqttConnect(const bool& sessionPresent);
|
||||||
|
|||||||
Reference in New Issue
Block a user