Fix battery power and user total pv power for the inverter
This commit is contained in:
parent
04d1b82685
commit
c7edc3ccf8
@ -394,13 +394,68 @@ void IntegrationPluginFronius::refreshConnection(FroniusSolarConnection *connect
|
|||||||
thingDescriptors.clear();
|
thingDescriptors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the inverters
|
// All devices
|
||||||
|
updatePowerFlow(connection);
|
||||||
updateInverters(connection);
|
updateInverters(connection);
|
||||||
updateMeters(connection);
|
updateMeters(connection);
|
||||||
updateStorages(connection);
|
updateStorages(connection);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginFronius::updatePowerFlow(FroniusSolarConnection *connection)
|
||||||
|
{
|
||||||
|
Thing *parentThing = m_froniusConnections.value(connection);
|
||||||
|
|
||||||
|
// Get power flow realtime data and update storage and pv power values according to the total values
|
||||||
|
// The inverter details inform about the PV production after feeding the storage, but we should use the total
|
||||||
|
// to make sure the sum is correct. Battery seems to be feeded DC to DC before the AC power convertion
|
||||||
|
FroniusNetworkReply *powerFlowReply = connection->getPowerFlowRealtimeData();
|
||||||
|
connect(powerFlowReply, &FroniusNetworkReply::finished, this, [=]() {
|
||||||
|
if (powerFlowReply->networkReply()->error() != QNetworkReply::NoError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray data = powerFlowReply->networkReply()->readAll();
|
||||||
|
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
qCWarning(dcFronius()) << "Meter: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the data and update the states of our device
|
||||||
|
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
||||||
|
//qCDebug(dcFronius()) << "Power flow data" << qUtf8Printable(QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
|
// Find the inverter for this connection and set the total power
|
||||||
|
Things availableInverters = myThings().filterByParentId(parentThing->id()).filterByThingClassId(inverterThingClassId);
|
||||||
|
if (availableInverters.count() == 1) {
|
||||||
|
Thing *inverterThing = availableInverters.first();
|
||||||
|
double pvPower = dataMap.value("Site").toMap().value("P_PV").toDouble();
|
||||||
|
inverterThing->setStateValue(inverterCurrentPowerStateTypeId, - pvPower);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the storage for this connection and update the current power
|
||||||
|
Things availableStorages = myThings().filterByParentId(parentThing->id()).filterByThingClassId(storageThingClassId);
|
||||||
|
if (availableStorages.count() == 1) {
|
||||||
|
Thing *storageThing = availableStorages.first();
|
||||||
|
// Note: negative (charge), positiv (discharge)
|
||||||
|
double akkuPower = - dataMap.value("Site").toMap().value("P_Akku").toDouble();
|
||||||
|
storageThing->setStateValue(storageCurrentPowerStateTypeId, akkuPower);
|
||||||
|
if (akkuPower < 0) {
|
||||||
|
storageThing->setStateValue(storageChargingStateStateTypeId, "discharging");
|
||||||
|
} else if (akkuPower > 0) {
|
||||||
|
storageThing->setStateValue(storageChargingStateStateTypeId, "charging");
|
||||||
|
} else {
|
||||||
|
storageThing->setStateValue(storageChargingStateStateTypeId, "idle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void IntegrationPluginFronius::updateInverters(FroniusSolarConnection *connection)
|
void IntegrationPluginFronius::updateInverters(FroniusSolarConnection *connection)
|
||||||
{
|
{
|
||||||
Thing *parentThing = m_froniusConnections.value(connection);
|
Thing *parentThing = m_froniusConnections.value(connection);
|
||||||
@ -430,14 +485,15 @@ void IntegrationPluginFronius::updateInverters(FroniusSolarConnection *connectio
|
|||||||
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
||||||
//qCDebug(dcFronius()) << "Inverter data" << qUtf8Printable(QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Indented));
|
//qCDebug(dcFronius()) << "Inverter data" << qUtf8Printable(QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
// Set the inverter device state
|
// Note: this is the PV power after feeding the battery, we have to use the total PV production from the power flow
|
||||||
if (dataMap.contains("PAC")) {
|
//if (dataMap.contains("PAC")) {
|
||||||
QVariantMap map = dataMap.value("PAC").toMap();
|
// QVariantMap map = dataMap.value("PAC").toMap();
|
||||||
if (map.value("Unit") == "W") {
|
// if (map.value("Unit") == "W") {
|
||||||
inverterThing->setStateValue(inverterCurrentPowerStateTypeId, - map.value("Value").toDouble());
|
// inverterThing->setStateValue(inverterCurrentPowerStateTypeId, - map.value("Value").toDouble());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
// Set the inverter device state
|
||||||
if (dataMap.contains("DAY_ENERGY")) {
|
if (dataMap.contains("DAY_ENERGY")) {
|
||||||
QVariantMap map = dataMap.value("DAY_ENERGY").toMap();
|
QVariantMap map = dataMap.value("DAY_ENERGY").toMap();
|
||||||
if (map.value("Unit") == "Wh") {
|
if (map.value("Unit") == "Wh") {
|
||||||
@ -561,40 +617,6 @@ void IntegrationPluginFronius::updateStorages(FroniusSolarConnection *connection
|
|||||||
foreach (Thing *storageThing, myThings().filterByParentId(parentThing->id()).filterByThingClassId(storageThingClassId)) {
|
foreach (Thing *storageThing, myThings().filterByParentId(parentThing->id()).filterByThingClassId(storageThingClassId)) {
|
||||||
int storageId = storageThing->paramValue(storageThingIdParamTypeId).toInt();
|
int storageId = storageThing->paramValue(storageThingIdParamTypeId).toInt();
|
||||||
|
|
||||||
// Get power flow realtime data
|
|
||||||
FroniusNetworkReply *powerFlowReply = connection->getPowerFlowRealtimeData();
|
|
||||||
connect(powerFlowReply, &FroniusNetworkReply::finished, this, [=]() {
|
|
||||||
if (powerFlowReply->networkReply()->error() != QNetworkReply::NoError) {
|
|
||||||
// Thing does not seem to be reachable
|
|
||||||
storageThing->setStateValue("connected", false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray data = powerFlowReply->networkReply()->readAll();
|
|
||||||
|
|
||||||
QJsonParseError error;
|
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
qCWarning(dcFronius()) << "Meter: Failed to parse JSON data" << data << ":" << error.errorString();
|
|
||||||
storageThing->setStateValue("connected", false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the data and update the states of our device
|
|
||||||
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
|
||||||
//qCDebug(dcFronius()) << "Power flow data" << qUtf8Printable(QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Indented));
|
|
||||||
|
|
||||||
float charge_akku = dataMap.value("Site").toMap().value("P_Akku").toFloat();
|
|
||||||
storageThing->setStateValue(storageCurrentPowerStateTypeId, charge_akku);
|
|
||||||
if (charge_akku < 0) {
|
|
||||||
storageThing->setStateValue(storageChargingStateStateTypeId, "discharging");
|
|
||||||
} else if (charge_akku > 0) {
|
|
||||||
storageThing->setStateValue(storageChargingStateStateTypeId, "charging");
|
|
||||||
} else {
|
|
||||||
storageThing->setStateValue(storageChargingStateStateTypeId, "idle");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get the storage realtime data
|
// Get the storage realtime data
|
||||||
FroniusNetworkReply *realtimeDataReply = connection->getStorageRealtimeData(storageId);
|
FroniusNetworkReply *realtimeDataReply = connection->getStorageRealtimeData(storageId);
|
||||||
connect(realtimeDataReply, &FroniusNetworkReply::finished, this, [=]() {
|
connect(realtimeDataReply, &FroniusNetworkReply::finished, this, [=]() {
|
||||||
|
|||||||
@ -63,6 +63,7 @@ private:
|
|||||||
|
|
||||||
void refreshConnection(FroniusSolarConnection *connection);
|
void refreshConnection(FroniusSolarConnection *connection);
|
||||||
|
|
||||||
|
void updatePowerFlow(FroniusSolarConnection *connection);
|
||||||
void updateInverters(FroniusSolarConnection *connection);
|
void updateInverters(FroniusSolarConnection *connection);
|
||||||
void updateMeters(FroniusSolarConnection *connection);
|
void updateMeters(FroniusSolarConnection *connection);
|
||||||
void updateStorages(FroniusSolarConnection *connection);
|
void updateStorages(FroniusSolarConnection *connection);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user