SMA: set energy values to 0 on disconnected
parent
9096691950
commit
dec0c15098
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2022, nymea GmbH
|
* Copyright 2013 - 2023, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
@ -321,6 +321,9 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
||||||
|
|
||||||
connect(meter, &SpeedwireMeter::reachableChanged, thing, [=](bool reachable){
|
connect(meter, &SpeedwireMeter::reachableChanged, thing, [=](bool reachable){
|
||||||
thing->setStateValue(speedwireMeterConnectedStateTypeId, reachable);
|
thing->setStateValue(speedwireMeterConnectedStateTypeId, reachable);
|
||||||
|
if (!reachable) {
|
||||||
|
markSpeedwireMeterAsDisconnected(thing);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(meter, &SpeedwireMeter::valuesUpdated, thing, [=](){
|
connect(meter, &SpeedwireMeter::valuesUpdated, thing, [=](){
|
||||||
|
|
@ -400,9 +403,13 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
||||||
// Runtime connections
|
// Runtime connections
|
||||||
connect(inverter, &SpeedwireInverter::reachableChanged, thing, [=](bool reachable){
|
connect(inverter, &SpeedwireInverter::reachableChanged, thing, [=](bool reachable){
|
||||||
thing->setStateValue(speedwireInverterConnectedStateTypeId, reachable);
|
thing->setStateValue(speedwireInverterConnectedStateTypeId, reachable);
|
||||||
|
if (!reachable) {
|
||||||
|
markSpeedwireInverterAsDisconnected(thing);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(inverter, &SpeedwireInverter::valuesUpdated, thing, [=](){
|
connect(inverter, &SpeedwireInverter::valuesUpdated, thing, [=](){
|
||||||
|
thing->setStateValue(speedwireInverterConnectedStateTypeId, true);
|
||||||
thing->setStateValue(speedwireInverterTotalEnergyProducedStateTypeId, inverter->totalEnergyProduced());
|
thing->setStateValue(speedwireInverterTotalEnergyProducedStateTypeId, inverter->totalEnergyProduced());
|
||||||
thing->setStateValue(speedwireInverterEnergyProducedTodayStateTypeId, inverter->todayEnergyProduced());
|
thing->setStateValue(speedwireInverterEnergyProducedTodayStateTypeId, inverter->todayEnergyProduced());
|
||||||
thing->setStateValue(speedwireInverterCurrentPowerStateTypeId, -inverter->totalAcPower());
|
thing->setStateValue(speedwireInverterCurrentPowerStateTypeId, -inverter->totalAcPower());
|
||||||
|
|
@ -497,8 +504,12 @@ void IntegrationPluginSma::postSetupThing(Thing *thing)
|
||||||
SpeedwireInverter *inverter = m_speedwireInverters.value(thing);
|
SpeedwireInverter *inverter = m_speedwireInverters.value(thing);
|
||||||
if (inverter) {
|
if (inverter) {
|
||||||
thing->setStateValue("connected", inverter->reachable());
|
thing->setStateValue("connected", inverter->reachable());
|
||||||
|
if (!inverter->reachable()) {
|
||||||
|
markSpeedwireInverterAsDisconnected(thing);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
thing->setStateValue("connected", false);
|
thing->setStateValue("connected", false);
|
||||||
|
markSpeedwireInverterAsDisconnected(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupRefreshTimer();
|
setupRefreshTimer();
|
||||||
|
|
@ -507,8 +518,12 @@ void IntegrationPluginSma::postSetupThing(Thing *thing)
|
||||||
SmaInverterModbusTcpConnection *connection = m_modbusInverters.value(thing);
|
SmaInverterModbusTcpConnection *connection = m_modbusInverters.value(thing);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
thing->setStateValue("connected", connection->reachable());
|
thing->setStateValue("connected", connection->reachable());
|
||||||
|
if (!connection->reachable()) {
|
||||||
|
markSpeedwireMeterAsDisconnected(thing);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
thing->setStateValue("connected", false);
|
thing->setStateValue("connected", false);
|
||||||
|
markSpeedwireMeterAsDisconnected(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupRefreshTimer();
|
setupRefreshTimer();
|
||||||
|
|
@ -556,6 +571,9 @@ void IntegrationPluginSma::onConnectedChanged(bool connected)
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!connected)
|
||||||
|
thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, 0);
|
||||||
|
|
||||||
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, connected);
|
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -629,6 +647,7 @@ void IntegrationPluginSma::setupModbusInverterConnection(ThingSetupInfo *info)
|
||||||
// Note: We disable autoreconnect explicitly and we will
|
// Note: We disable autoreconnect explicitly and we will
|
||||||
// connect the device once the monitor says it is reachable again
|
// connect the device once the monitor says it is reachable again
|
||||||
connection->disconnectDevice();
|
connection->disconnectDevice();
|
||||||
|
markModbusInverterAsDisconnected(thing);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -639,6 +658,7 @@ void IntegrationPluginSma::setupModbusInverterConnection(ThingSetupInfo *info)
|
||||||
connection->initialize();
|
connection->initialize();
|
||||||
} else {
|
} else {
|
||||||
thing->setStateValue("connected", false);
|
thing->setStateValue("connected", false);
|
||||||
|
markModbusInverterAsDisconnected(thing);
|
||||||
foreach (Thing *childThing, myThings().filterByParentId(thing->id())) {
|
foreach (Thing *childThing, myThings().filterByParentId(thing->id())) {
|
||||||
childThing->setStateValue("connected", false);
|
childThing->setStateValue("connected", false);
|
||||||
}
|
}
|
||||||
|
|
@ -657,6 +677,7 @@ void IntegrationPluginSma::setupModbusInverterConnection(ThingSetupInfo *info)
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// Try once to reconnect the device
|
// Try once to reconnect the device
|
||||||
connection->reconnectDevice();
|
connection->reconnectDevice();
|
||||||
|
markModbusInverterAsDisconnected(thing);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -734,6 +755,47 @@ void IntegrationPluginSma::setupModbusInverterConnection(ThingSetupInfo *info)
|
||||||
connection->connectDevice();
|
connection->connectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSma::markSpeedwireMeterAsDisconnected(Thing *thing)
|
||||||
|
{
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPowerPhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPowerPhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPowerPhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterVoltagePhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterVoltagePhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterVoltagePhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireMeterCurrentPowerStateTypeId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSma::markSpeedwireInverterAsDisconnected(Thing *thing)
|
||||||
|
{
|
||||||
|
thing->setStateValue(speedwireInverterVoltagePhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterVoltagePhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterVoltagePhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPowerMpp1StateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPowerMpp2StateTypeId, 0);
|
||||||
|
thing->setStateValue(speedwireInverterCurrentPowerStateTypeId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSma::markModbusInverterAsDisconnected(Thing *thing)
|
||||||
|
{
|
||||||
|
thing->setStateValue(modbusInverterVoltagePhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterVoltagePhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterVoltagePhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPowerPhaseAStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPowerPhaseBStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPowerPhaseCStateTypeId, 0);
|
||||||
|
thing->setStateValue(modbusInverterCurrentPowerStateTypeId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool IntegrationPluginSma::isModbusValueValid(quint32 value)
|
bool IntegrationPluginSma::isModbusValueValid(quint32 value)
|
||||||
{
|
{
|
||||||
return value != 0xffffffff;
|
return value != 0xffffffff;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2022, nymea GmbH
|
* Copyright 2013 - 2023, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
@ -83,6 +83,10 @@ private:
|
||||||
// Shared interface accross meters
|
// Shared interface accross meters
|
||||||
SpeedwireInterface *m_multicastInterface = nullptr;
|
SpeedwireInterface *m_multicastInterface = nullptr;
|
||||||
|
|
||||||
|
void markSpeedwireMeterAsDisconnected(Thing *thing);
|
||||||
|
void markSpeedwireInverterAsDisconnected(Thing *thing);
|
||||||
|
void markModbusInverterAsDisconnected(Thing *thing);
|
||||||
|
|
||||||
// Sma modbus data validation
|
// Sma modbus data validation
|
||||||
bool isModbusValueValid(quint32 value);
|
bool isModbusValueValid(quint32 value);
|
||||||
bool isModbusValueValid(qint32 value);
|
bool isModbusValueValid(qint32 value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue