mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-13 15:37:03 +00:00
move energy to separate topic
This commit is contained in:
parent
2e4e4328f2
commit
b79e6112b1
@ -4,7 +4,6 @@
|
||||
#include "web/root/ha1_json.h"
|
||||
#include "web/root/ha2_json.h"
|
||||
#include "web/root/ha3_json.h"
|
||||
#include "web/root/ha3pf_json.h"
|
||||
#include "web/root/jsonsys_json.h"
|
||||
#include "web/root/jsonprices_json.h"
|
||||
#include "web/root/hadiscover1_json.h"
|
||||
@ -15,15 +14,28 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
return false;
|
||||
|
||||
listType = data->getListType(); // for discovery stuff in publishSystem()
|
||||
if(data->getListType() == 1) {
|
||||
if(data->getListType() == 3) { // publish energy counts
|
||||
if(data->getActiveExportCounter() > 0){
|
||||
char json[256];
|
||||
snprintf_P(json, sizeof(json), HA2_JSON,
|
||||
data->getActiveImportCounter(),
|
||||
data->getActiveExportCounter(),
|
||||
data->getReactiveImportCounter(),
|
||||
data->getReactiveExportCounter(),
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
mqtt->publish(topic + "/energy", json);
|
||||
}
|
||||
}
|
||||
if(data->getListType() == 1) { // publish power counts
|
||||
char json[192];
|
||||
snprintf_P(json, sizeof(json), HA1_JSON,
|
||||
data->getActiveImportPower()
|
||||
);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
} else if(data->getListType() == 2) {
|
||||
char json[384];
|
||||
snprintf_P(json, sizeof(json), HA2_JSON,
|
||||
return mqtt->publish(topic + "/power", json);
|
||||
} else if(data->getListType() == 2 || data->getListType() == 3) {
|
||||
char json[768];
|
||||
snprintf_P(json, sizeof(json), HA3_JSON,
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
@ -36,69 +48,20 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
data->getL3Current(),
|
||||
data->getL1Voltage(),
|
||||
data->getL2Voltage(),
|
||||
data->getL3Voltage()
|
||||
data->getL3Voltage(),
|
||||
data->getPowerFactor() == 0 ? 1 : data->getPowerFactor(),
|
||||
data->getPowerFactor() == 0 ? 1 : data->getL1PowerFactor(),
|
||||
data->getPowerFactor() == 0 ? 1 : data->getL2PowerFactor(),
|
||||
data->getPowerFactor() == 0 ? 1 : data->getL3PowerFactor()
|
||||
);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
} else if(data->getListType() == 3) {
|
||||
if(data->getPowerFactor() == 0) {
|
||||
char json[512];
|
||||
snprintf_P(json, sizeof(json), HA3_JSON,
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
data->getReactiveExportPower(),
|
||||
data->getL1Current(),
|
||||
data->getL2Current(),
|
||||
data->getL3Current(),
|
||||
data->getL1Voltage(),
|
||||
data->getL2Voltage(),
|
||||
data->getL3Voltage(),
|
||||
data->getActiveImportCounter(),
|
||||
data->getActiveExportCounter(),
|
||||
data->getReactiveImportCounter(),
|
||||
data->getReactiveExportCounter(),
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
} else {
|
||||
char json[768];
|
||||
snprintf_P(json, sizeof(json), HA3PF_JSON,
|
||||
data->getListId().c_str(),
|
||||
data->getMeterId().c_str(),
|
||||
data->getMeterModel().c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
data->getActiveExportPower(),
|
||||
data->getReactiveExportPower(),
|
||||
data->getL1Current(),
|
||||
data->getL2Current(),
|
||||
data->getL3Current(),
|
||||
data->getL1Voltage(),
|
||||
data->getL2Voltage(),
|
||||
data->getL3Voltage(),
|
||||
data->getPowerFactor(),
|
||||
data->getL1PowerFactor(),
|
||||
data->getL2PowerFactor(),
|
||||
data->getL3PowerFactor(),
|
||||
data->getActiveImportCounter(),
|
||||
data->getActiveExportCounter(),
|
||||
data->getReactiveImportCounter(),
|
||||
data->getReactiveExportCounter(),
|
||||
data->getMeterTimestamp()
|
||||
);
|
||||
return mqtt->publish(topic + "/sensor", json);
|
||||
}
|
||||
return mqtt->publish(topic + "/power", json);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HomeAssistantMqttHandler::publishTemperatures(AmsConfiguration* config, HwTools* hw) {
|
||||
int count = hw->getTempSensorCount();
|
||||
if(count == 0)
|
||||
return false;
|
||||
if(count == 0) return false;
|
||||
|
||||
int size = 32 + (count * 26);
|
||||
|
||||
@ -269,7 +232,7 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) {
|
||||
|
||||
snprintf_P(json, sizeof(json), HADISCOVER2_JSON,
|
||||
"AMS active import",
|
||||
(topic + "/sensor").c_str(),
|
||||
(topic + "/power").c_str(),
|
||||
(haUID + "_activeI").c_str(),
|
||||
(haUID + "_activeI").c_str(),
|
||||
"W",
|
||||
@ -282,7 +245,7 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) {
|
||||
|
||||
snprintf_P(json, sizeof(json), HADISCOVER2_JSON,
|
||||
"AMS accumulated active energy",
|
||||
(topic + "/sensor").c_str(),
|
||||
(topic + "/energy").c_str(),
|
||||
(haUID + "_accumI").c_str(),
|
||||
(haUID + "_accumI").c_str(),
|
||||
"kWh",
|
||||
|
||||
27
web/ha2.json
27
web/ha2.json
@ -1,24 +1,7 @@
|
||||
{
|
||||
"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" : null,
|
||||
"PF1" : null,
|
||||
"PF2" : null,
|
||||
"PF3" : null,
|
||||
"tPI" : null,
|
||||
"tPO" : null,
|
||||
"tQI" : null,
|
||||
"tQO" : null,
|
||||
"rtc" : null
|
||||
"tPI" : %.2f,
|
||||
"tPO" : %.2f,
|
||||
"tQI" : %.2f,
|
||||
"tQO" : %.2f,
|
||||
"rtc" : %llu
|
||||
}
|
||||
|
||||
13
web/ha3.json
13
web/ha3.json
@ -12,13 +12,8 @@
|
||||
"U1" : %.2f,
|
||||
"U2" : %.2f,
|
||||
"U3" : %.2f,
|
||||
"PF" : null,
|
||||
"PF1" : null,
|
||||
"PF2" : null,
|
||||
"PF3" : null,
|
||||
"tPI" : %.2f,
|
||||
"tPO" : %.2f,
|
||||
"tQI" : %.2f,
|
||||
"tQO" : %.2f,
|
||||
"rtc" : %lu
|
||||
"PF" : %.2f,
|
||||
"PF1" : %.2f,
|
||||
"PF2" : %.2f,
|
||||
"PF3" : %.2f
|
||||
}
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user