fixed power calculation

pull/1/head
bernhard.trinnes 2020-07-29 15:00:49 +02:00 committed by Michael Zanetti
parent 69f2cdf406
commit f25f1eeabd
1 changed files with 3 additions and 1 deletions

View File

@ -190,6 +190,7 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
int timeframe = thing->setting(extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId).toInt();
smartMeterTimer->setInterval(timeframe * 1000);
m_smartMeterTimer.insert(thing, smartMeterTimer);
smartMeterTimer->start();
connect(thing, &Thing::settingChanged, smartMeterTimer, [smartMeterTimer] (const ParamTypeId &paramTypeId, const QVariant &value) {
if (paramTypeId == extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId) {
smartMeterTimer->setInterval(value.toInt() * 1000);
@ -198,7 +199,8 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info)
connect(smartMeterTimer, &QTimer::timeout, thing, [this, smartMeterTimer, thing] {
double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble();
double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(smartMeterTimer->interval()/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh
int interval = smartMeterTimer->interval()/1000;
double power = (m_pulsesPerTimeframe.value(thing)/impulsePerKwh)/(interval/3600.00); // Power = Energy/Time; Energy = Impulses/ImpPerkWh
thing->setStateValue(extendedSmartMeterConsumerCurrentPowerStateTypeId, power*1000);
m_pulsesPerTimeframe.insert(thing, 0);
});