diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 6f00b570..f029c22b 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -315,6 +315,7 @@ bool longPressActive = false; bool wifiConnected = false; unsigned long lastTemperatureRead = 0; +unsigned long lastSystemMessage = 0; unsigned long lastErrorBlink = 0; int lastError = 0; @@ -473,6 +474,12 @@ void loop() { } if(readHanPort() || now - meterState.getLastUpdateMillis() > 30000) { + if(now - lastSystemMessage > 15000) { + if(mqtt != NULL && mqttHandler != NULL && WiFi.getMode() != WIFI_AP && WiFi.status() == WL_CONNECTED && mqtt->connected() && !topic.isEmpty()) { + lastSystemMessage = now; + mqttHandler->publishSystem(&hw); + } + } if(now - lastTemperatureRead > 15000) { unsigned long start = millis(); hw.updateTemperatures(); diff --git a/src/mqtt/HomeAssistantMqttHandler.cpp b/src/mqtt/HomeAssistantMqttHandler.cpp index 24ee83a6..10ed07ec 100644 --- a/src/mqtt/HomeAssistantMqttHandler.cpp +++ b/src/mqtt/HomeAssistantMqttHandler.cpp @@ -17,7 +17,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) { snprintf_P(json, sizeof(json), JSON1HA_JSON, data->getActiveImportPower() ); - return mqtt->publish(topic + "/data1", json); + return mqtt->publish(topic + "/power", json); } else if(data->getListType() == 2) { char json[384]; snprintf_P(json, sizeof(json), JSON2HA_JSON, @@ -35,7 +35,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) { data->getL2Voltage(), data->getL3Voltage() ); - return mqtt->publish(topic + "/data2", json); + return mqtt->publish(topic + "/sensor", json); } else if(data->getListType() == 3) { if(data->getPowerFactor() == 0) { char json[512]; @@ -59,7 +59,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) { data->getReactiveExportCounter(), data->getMeterTimestamp() ); - return mqtt->publish(topic + "/data3", json); + return mqtt->publish(topic + "/sensor", json); } else { char json[768]; snprintf_P(json, sizeof(json), JSON3HAPF_JSON, @@ -86,7 +86,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) { data->getReactiveExportCounter(), data->getMeterTimestamp() ); - return mqtt->publish(topic + "/data3pf", json); + return mqtt->publish(topic + "/sensor", json); } } return false; diff --git a/web/json2ha.json b/web/json2ha.json index 8fa16c93..b854e4cc 100644 --- a/web/json2ha.json +++ b/web/json2ha.json @@ -11,5 +11,14 @@ "I3" : %.2f, "U1" : %.2f, "U2" : %.2f, - "U3" : %.2f + "U3" : %.2f, + "PF" : null, + "PF1" : null, + "PF2" : null, + "PF3" : null, + "tPI" : null, + "tPO" : null, + "tQI" : null, + "tQO" : null, + "rtc" : null } diff --git a/web/json3ha.json b/web/json3ha.json index 55220a70..806933f3 100644 --- a/web/json3ha.json +++ b/web/json3ha.json @@ -12,6 +12,10 @@ "U1" : %.2f, "U2" : %.2f, "U3" : %.2f, + "PF" : null, + "PF1" : null, + "PF2" : null, + "PF3" : null, "tPI" : %.2f, "tPO" : %.2f, "tQI" : %.2f, diff --git a/web/jsonha.json b/web/jsonha.json new file mode 100644 index 00000000..dd3e4a5b --- /dev/null +++ b/web/jsonha.json @@ -0,0 +1,24 @@ +{ + "lv" : "%s", + "id" : "%s", + "type" : "%s", + "P" : %d, + "Q" : %d, + "PO" : %d, + "QO" : %d, + "I1" : %.2f, + "I2" : %.2f, + "I3" : %.2f, + "U1" : %.2f, + "U2" : %.2f, + "U3" : %.2f, + "PF" : %.2f, + "PF1" : %.2f, + "PF2" : %.2f, + "PF3" : %.2f, + "tPI" : %.2f, + "tPO" : %.2f, + "tQI" : %.2f, + "tQO" : %.2f, + "rtc" : %lu +}