Wattsonic: Update connection behavior and fix PV production value
parent
25671f284b
commit
6ec122a097
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2023, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
@ -142,7 +142,7 @@ void IntegrationPluginWattsonic::postSetupThing(Thing *thing)
|
||||||
void IntegrationPluginWattsonic::thingRemoved(Thing *thing)
|
void IntegrationPluginWattsonic::thingRemoved(Thing *thing)
|
||||||
{
|
{
|
||||||
if (thing->thingClassId() == inverterThingClassId && m_connections.contains(thing)) {
|
if (thing->thingClassId() == inverterThingClassId && m_connections.contains(thing)) {
|
||||||
delete m_connections.take(thing);
|
m_connections.take(thing)->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myThings().isEmpty() && m_pluginTimer) {
|
if (myThings().isEmpty() && m_pluginTimer) {
|
||||||
|
|
@ -170,27 +170,16 @@ void IntegrationPluginWattsonic::setupWattsonicConnection(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
WattsonicModbusRtuConnection *connection = new WattsonicModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), slaveId, this);
|
WattsonicModbusRtuConnection *connection = new WattsonicModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), slaveId, this);
|
||||||
connect(info, &ThingSetupInfo::aborted, connection, &ModbusRtuMaster::deleteLater);
|
|
||||||
|
|
||||||
m_connections.insert(thing, connection);
|
m_connections.insert(thing, connection);
|
||||||
|
|
||||||
|
// Only for setup
|
||||||
|
connect(info, &ThingSetupInfo::aborted, connection, &WattsonicModbusRtuConnection::deleteLater);
|
||||||
connect(info, &ThingSetupInfo::aborted, this, [=](){
|
connect(info, &ThingSetupInfo::aborted, this, [=](){
|
||||||
m_connections.take(info->thing())->deleteLater();
|
m_connections.take(info->thing())->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(connection, &WattsonicModbusRtuConnection::reachableChanged, thing, [connection, thing, this](bool reachable){
|
|
||||||
qCDebug(dcWattsonic()) << "Reachable state changed" << reachable;
|
|
||||||
if (reachable) {
|
|
||||||
connection->initialize();
|
|
||||||
} else {
|
|
||||||
thing->setStateValue("connected", false);
|
|
||||||
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
|
||||||
child->setStateValue("connected", true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(connection, &WattsonicModbusRtuConnection::initializationFinished, info, [=](bool success){
|
connect(connection, &WattsonicModbusRtuConnection::initializationFinished, info, [=](bool success){
|
||||||
qCDebug(dcWattsonic()) << "Initialisation finished" << success;
|
qCDebug(dcWattsonic()) << "Initialization finished" << success;
|
||||||
if (info->isInitialSetup() && !success) {
|
if (info->isInitialSetup() && !success) {
|
||||||
m_connections.take(info->thing())->deleteLater();
|
m_connections.take(info->thing())->deleteLater();
|
||||||
info->finish(Thing::ThingErrorHardwareNotAvailable);
|
info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||||
|
|
@ -198,27 +187,31 @@ void IntegrationPluginWattsonic::setupWattsonicConnection(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
if (success) {
|
|
||||||
qCDebug(dcWattsonic) << "Firmware version:" << connection->firmwareVersion();
|
qCDebug(dcWattsonic) << "Firmware version:" << connection->firmwareVersion();
|
||||||
// info->thing()->setStateValue(inverterCurrentVersionStateTypeId, compact20Connection->firmwareVersion());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(connection, &WattsonicModbusRtuConnection::reachableChanged, thing, [=](bool reachable){
|
// Runtime connections
|
||||||
thing->setStateValue(inverterConnectedStateTypeId, reachable);
|
connect(connection, &WattsonicModbusRtuConnection::reachableChanged, thing, [connection, thing, this](bool reachable){
|
||||||
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
qCDebug(dcWattsonic()) << "Reachable state changed" << reachable;
|
||||||
child->setStateValue("connected", reachable);
|
if (reachable) {
|
||||||
|
connection->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setConnectedStates(thing, reachable);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(connection, &WattsonicModbusRtuConnection::reachableChanged, thing, [this, thing](bool reachable){
|
||||||
|
setConnectedStates(thing, reachable);
|
||||||
|
});
|
||||||
|
|
||||||
connect(connection, &WattsonicModbusRtuConnection::updateFinished, thing, [this, connection, thing](){
|
connect(connection, &WattsonicModbusRtuConnection::updateFinished, thing, [this, connection, thing](){
|
||||||
qCDebug(dcWattsonic()) << "Update finished:" << thing->name() << connection;
|
qCDebug(dcWattsonic()) << "Update finished:" << thing->name() << connection;
|
||||||
|
|
||||||
Thing *inverter = thing;
|
// We received an update, make sure we are connected
|
||||||
|
setConnectedStates(thing, true);
|
||||||
|
|
||||||
inverter->setStateValue(inverterCurrentPowerStateTypeId, connection->pAC() * -1.0);
|
Thing *inverter = thing;
|
||||||
|
inverter->setStateValue(inverterCurrentPowerStateTypeId, connection->pvInputTotalPower() * -1.0);
|
||||||
inverter->setStateValue(inverterTotalEnergyProducedStateTypeId, connection->totalPVGenerationFromInstallation() * 0.1);
|
inverter->setStateValue(inverterTotalEnergyProducedStateTypeId, connection->totalPVGenerationFromInstallation() * 0.1);
|
||||||
qCInfo(dcWattsonic()) << "Updating inverter:" << inverter->stateValue(inverterCurrentPowerStateTypeId).toDouble() << "W" << inverter->stateValue(inverterTotalEnergyProducedStateTypeId).toDouble() << "kWh";
|
qCInfo(dcWattsonic()) << "Updating inverter:" << inverter->stateValue(inverterCurrentPowerStateTypeId).toDouble() << "W" << inverter->stateValue(inverterTotalEnergyProducedStateTypeId).toDouble() << "kWh";
|
||||||
|
|
||||||
|
|
@ -243,6 +236,7 @@ void IntegrationPluginWattsonic::setupWattsonicConnection(ThingSetupInfo *info)
|
||||||
meter->setStateValue(meterCurrentPhaseCStateTypeId, (connection->phaseCPower() * -1.0) / (connection->gridPhaseCVoltage() / 10.0));
|
meter->setStateValue(meterCurrentPhaseCStateTypeId, (connection->phaseCPower() * -1.0) / (connection->gridPhaseCVoltage() / 10.0));
|
||||||
qCInfo(dcWattsonic()) << "Updating meter:" << meter->stateValue(meterCurrentPowerStateTypeId).toDouble() << "W" << meter->stateValue(meterTotalEnergyProducedStateTypeId).toDouble() << "kWh";
|
qCInfo(dcWattsonic()) << "Updating meter:" << meter->stateValue(meterCurrentPowerStateTypeId).toDouble() << "W" << meter->stateValue(meterTotalEnergyProducedStateTypeId).toDouble() << "kWh";
|
||||||
}
|
}
|
||||||
|
|
||||||
Things batteries = myThings().filterByParentId(thing->id()).filterByThingClassId(batteryThingClassId);
|
Things batteries = myThings().filterByParentId(thing->id()).filterByThingClassId(batteryThingClassId);
|
||||||
if (!batteries.isEmpty() && connection->SOC() > 0) {
|
if (!batteries.isEmpty() && connection->SOC() > 0) {
|
||||||
Thing *battery = batteries.first();
|
Thing *battery = batteries.first();
|
||||||
|
|
@ -255,8 +249,13 @@ void IntegrationPluginWattsonic::setupWattsonicConnection(ThingSetupInfo *info)
|
||||||
battery->setStateValue(batteryBatteryLevelStateTypeId, connection->SOC() / 100.0);
|
battery->setStateValue(batteryBatteryLevelStateTypeId, connection->SOC() / 100.0);
|
||||||
battery->setStateValue(batteryBatteryCriticalStateTypeId, connection->SOC() < 500);
|
battery->setStateValue(batteryBatteryCriticalStateTypeId, connection->SOC() < 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginWattsonic::setConnectedStates(Thing *thing, bool connected)
|
||||||
|
{
|
||||||
|
thing->setStateValue("connected", connected);
|
||||||
|
foreach (Thing *child, myThings().filterByParentId(thing->id())) {
|
||||||
|
child->setStateValue("connected", connected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2023, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
@ -59,6 +59,8 @@ private:
|
||||||
|
|
||||||
PluginTimer *m_pluginTimer = nullptr;
|
PluginTimer *m_pluginTimer = nullptr;
|
||||||
QHash<Thing *, WattsonicModbusRtuConnection *> m_connections;
|
QHash<Thing *, WattsonicModbusRtuConnection *> m_connections;
|
||||||
|
|
||||||
|
void setConnectedStates(Thing * thing, bool connected);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INTEGRATIONPLUGINWATTSONIC_H
|
#endif // INTEGRATIONPLUGINWATTSONIC_H
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Phase A power",
|
"description": "Phase A power",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Phase B power",
|
"description": "Phase B power",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -116,7 +116,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Phase C power",
|
"description": "Phase C power",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -128,7 +128,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Total power on meter",
|
"description": "Total power on meter",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -236,7 +236,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "P_AC",
|
"description": "P_AC",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -260,7 +260,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "PV Total Input Power",
|
"description": "PV Total Input Power",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -271,7 +271,7 @@
|
||||||
"readSchedule": "update",
|
"readSchedule": "update",
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Total_Backup_P/AC Active Power",
|
"description": "Total_Backup_P/AC Active Power",
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
|
|
@ -296,7 +296,7 @@
|
||||||
"registerType": "holdingRegister",
|
"registerType": "holdingRegister",
|
||||||
"description": "Battery power",
|
"description": "Battery power",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"unit": "1/1000 kW",
|
"unit": "W",
|
||||||
"access": "RO"
|
"access": "RO"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue