topic contains all fields, null if not used

This commit is contained in:
Daniel Ekman 2021-12-21 15:56:09 +01:00
parent d7d25083dc
commit 86939d4890
5 changed files with 49 additions and 5 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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
}

View File

@ -12,6 +12,10 @@
"U1" : %.2f,
"U2" : %.2f,
"U3" : %.2f,
"PF" : null,
"PF1" : null,
"PF2" : null,
"PF3" : null,
"tPI" : %.2f,
"tPO" : %.2f,
"tQI" : %.2f,

24
web/jsonha.json Normal file
View File

@ -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
}