diff --git a/src/mqtt/HomeAssistantMqttHandler.cpp b/src/mqtt/HomeAssistantMqttHandler.cpp index 1d07c749..db5f4d8b 100644 --- a/src/mqtt/HomeAssistantMqttHandler.cpp +++ b/src/mqtt/HomeAssistantMqttHandler.cpp @@ -8,8 +8,7 @@ #include "web/root/ha3_json.h" #include "web/root/jsonsys_json.h" #include "web/root/jsonprices_json.h" -#include "web/root/hadiscover1_json.h" -#include "web/root/hadiscover2_json.h" +#include "web/root/hadiscover_json.h" bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState, EnergyAccounting* ea) { if(topic.isEmpty() || !mqtt->connected()) @@ -214,40 +213,22 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) { String haUrl = "http://" + haUID + ".local/"; for(int i=0;i 0) { // TODO: reduce to single JSON, state_class: null (witout quotation). or make it some extra optional string that us appended - snprintf_P(json, BufferSize, HADISCOVER2_JSON, - FPSTR(HA_NAMES[i]), - topic, FPSTR(HA_TOPICS[i]), - haUID, FPSTR(HA_PARAMS[i]), - haUID, FPSTR(HA_PARAMS[i]), - FPSTR(HA_UOM[i]), - FPSTR(HA_PARAMS[i]), - FPSTR(HA_DEVCL[i]), - haUID.c_str(), - haName.c_str(), - haModel.c_str(), - VERSION, - haManuf.c_str(), - haUrl.c_str(), - FPSTR(HA_STACL[i]) - ); - } else { - snprintf_P(json, BufferSize, HADISCOVER1_JSON, - FPSTR(HA_NAMES[i]), - topic, FPSTR(HA_TOPICS[i]), - haUID, FPSTR(HA_PARAMS[i]), - haUID, FPSTR(HA_PARAMS[i]), - FPSTR(HA_UOM[i]), - FPSTR(HA_PARAMS[i]), - FPSTR(HA_DEVCL[i]), - haUID.c_str(), - haName.c_str(), - haModel.c_str(), - VERSION, - haManuf.c_str(), - haUrl.c_str() - ); - } + snprintf_P(json, BufferSize, HADISCOVER_JSON, + FPSTR(HA_NAMES[i]), + topic, FPSTR(HA_TOPICS[i]), + haUID, FPSTR(HA_PARAMS[i]), + haUID, FPSTR(HA_PARAMS[i]), + FPSTR(HA_UOM[i]), + FPSTR(HA_PARAMS[i]), + FPSTR(HA_DEVCL[i]), + haUID.c_str(), + haName.c_str(), + haModel.c_str(), + VERSION, + haManuf.c_str(), + haUrl.c_str(), + strlen_P(HA_STACL[i]) > 0 ? (char *) FPSTR(HA_STACL[i]) : "null" + ); mqtt->publish(haTopic + haUID + "_" + FPSTR(HA_PARAMS[i]) + "/config", json, true, 0); } autodiscoverInit = true; diff --git a/src/mqtt/HomeAssistantStatic.h b/src/mqtt/HomeAssistantStatic.h index f821715f..5f5b5b26 100644 --- a/src/mqtt/HomeAssistantStatic.h +++ b/src/mqtt/HomeAssistantStatic.h @@ -9,6 +9,6 @@ const char* HA_NAMES[17] PROGMEM = {"Status", "Supply volt", "Temperature", "Act const char* HA_PARAMS[17] PROGMEM = {"rssi", "vcc", "temp", "P", "Q", "PO", "QO", "I1", "I2", "I3", "U1", "U2", "U3", "tPI", "tPO", "tQI", "tQO"}; const char* HA_UOM[17] PROGMEM = {"dBm", "V", "C", "W", "W", "W", "W", "A", "A", "A", "V", "V", "V", "kWh", "kWh", "kWh", "kWh"}; const char* HA_DEVCL[17] PROGMEM = {"signal_strength", "voltage", "temperature", "power", "power", "power", "power", "current", "current", "current", "voltage", "voltage", "voltage", "energy", "energy", "energy", "energy"}; -const char* HA_STACL[17] PROGMEM = {"", "", "", "measurement", "measurement", "measurement", "measurement", "", "", "", "", "", "", "total_increasing", "total_increasing", "total_increasing", "total_increasing"}; +const char* HA_STACL[17] PROGMEM = {"", "", "", "\"measurement\"", "\"measurement\"", "\"measurement\"", "\"measurement\"", "", "", "", "", "", "", "\"total_increasing\"", "\"total_increasing\"", "\"total_increasing\"", "\"total_increasing\""}; #endif diff --git a/web/hadiscover2.json b/web/hadiscover.json similarity index 93% rename from web/hadiscover2.json rename to web/hadiscover.json index e60b3953..7b7dfdc9 100644 --- a/web/hadiscover2.json +++ b/web/hadiscover.json @@ -14,5 +14,5 @@ "mf" : "%s", "cu" : "%s" }, - "stat_cla" : "%s" + "stat_cla" : %s } \ No newline at end of file diff --git a/web/hadiscover1.json b/web/hadiscover1.json deleted file mode 100644 index 79ca7e15..00000000 --- a/web/hadiscover1.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name" : "%s", - "stat_t" : "%s%s", - "uniq_id" : "%s_%s", - "obj_id" : "%s_%s", - "unit_of_meas" : "%s", - "val_tpl" : "{{value_json['%s']}}", - "dev_cla" : "%s", - "dev" : { - "ids" : [ "%s" ], - "name" : "%s", - "mdl" : "%s", - "sw" : "%s", - "mf" : "%s", - "cu" : "%s" - } -} \ No newline at end of file