diff --git a/genericthings/integrationplugingenericthings.cpp b/genericthings/integrationplugingenericthings.cpp index f224ee10..10ae19be 100644 --- a/genericthings/integrationplugingenericthings.cpp +++ b/genericthings/integrationplugingenericthings.cpp @@ -40,15 +40,10 @@ IntegrationPluginGenericThings::IntegrationPluginGenericThings() } -void IntegrationPluginGenericThings::init() -{ - -} - void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info) { - info->finish(Thing::ThingErrorNoError); Thing *thing = info->thing(); + if (thing->thingClassId() == extendedBlindThingClassId) { uint closingTime = thing->setting(extendedBlindSettingsClosingTimeParamTypeId).toUInt(); if (closingTime == 0) { @@ -189,7 +184,28 @@ void IntegrationPluginGenericThings::setupThing(ThingSetupInfo *info) } } }); + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + + QTimer* smartMeterTimer = new QTimer(this); + 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 ¶mTypeId, const QVariant &value) { + if (paramTypeId == extendedSmartMeterConsumerSettingsImpulseTimeframeParamTypeId) { + smartMeterTimer->setInterval(value.toInt() * 1000); + } + }); + + connect(smartMeterTimer, &QTimer::timeout, thing, [this, smartMeterTimer, thing] { + double impulsePerKwh = thing->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toDouble(); + 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); + }); } + info->finish(Thing::ThingErrorNoError); } void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) @@ -475,6 +491,21 @@ void IntegrationPluginGenericThings::executeAction(ThingActionInfo *info) } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + if (action.actionTypeId() == extendedSmartMeterConsumerImpulseInputActionTypeId) { + bool value = info->action().param(extendedSmartMeterConsumerImpulseInputActionImpulseInputParamTypeId).value().toBool(); + thing->setStateValue(extendedSmartMeterConsumerImpulseInputStateTypeId, value); + int impulsePerKwh = info->thing()->setting(extendedSmartMeterConsumerSettingsImpulsePerKwhParamTypeId).toInt(); + if (value) { + double currentEnergy = thing->stateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId).toDouble(); + thing->setStateValue(extendedSmartMeterConsumerTotalEnergyConsumedStateTypeId ,currentEnergy + (1.00/impulsePerKwh)); + m_pulsesPerTimeframe[thing]++; + } + info->finish(Thing::ThingErrorNoError); + return; + } else { + Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); + } } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); } @@ -490,6 +521,11 @@ void IntegrationPluginGenericThings::thingRemoved(Thing *thing) m_extendedBlindTargetPercentage.remove(thing); m_venetianBlindAngleTimer.take(thing)->deleteLater(); m_venetianBlindTargetAngle.remove(thing); + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + m_pulsesPerTimeframe.remove(thing); + } else if (thing->thingClassId() == extendedSmartMeterConsumerThingClassId) { + m_smartMeterTimer.take(thing)->deleteLater(); + m_pulsesPerTimeframe.remove(thing); } } diff --git a/genericthings/integrationplugingenericthings.h b/genericthings/integrationplugingenericthings.h index a98c466a..bba4e8ff 100644 --- a/genericthings/integrationplugingenericthings.h +++ b/genericthings/integrationplugingenericthings.h @@ -32,6 +32,8 @@ #define INTEGRATIONPLUGINGENERICTHINGS_H #include "integrations/integrationplugin.h" +#include "plugintimer.h" + #include class IntegrationPluginGenericThings: public IntegrationPlugin @@ -43,16 +45,18 @@ class IntegrationPluginGenericThings: public IntegrationPlugin public: explicit IntegrationPluginGenericThings(); - void init() override; void setupThing(ThingSetupInfo *info) override; void executeAction(ThingActionInfo *info) override; void thingRemoved(Thing *thing) override; private: + QHash m_pulsesPerTimeframe; + double mapDoubleValue(double value, double fromMin, double fromMax, double toMin, double toMax); QHash m_extendedBlindPercentageTimer; QHash m_venetianBlindAngleTimer; + QHash m_smartMeterTimer; QHash m_extendedBlindTargetPercentage; QHash m_venetianBlindTargetAngle; diff --git a/genericthings/integrationplugingenericthings.json b/genericthings/integrationplugingenericthings.json index fc4cfeca..049fa0eb 100644 --- a/genericthings/integrationplugingenericthings.json +++ b/genericthings/integrationplugingenericthings.json @@ -693,6 +693,65 @@ "ioType": "analogOutput" } ] + }, + { + "id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52", + "name": "extendedSmartMeterConsumer", + "displayName": "Impulse based energy meter", + "createMethods": ["user"], + "interfaces": ["extendedsmartmeterconsumer"], + "settingsTypes": [ + { + "id": "c361732b-68eb-447e-a434-e84031231871", + "name": "impulsePerKwh", + "displayName": "Impulse/kWh", + "type": "int", + "minValue": 1, + "maxValue": 1000000, + "defaultValue": 1000 + }, + { + "id": "73c9acc3-8f76-40d7-a79b-a1f08bb308d4", + "name": "impulseTimeframe", + "displayName": "Timeframe for power calculation", + "type": "int", + "unit": "Seconds", + "minValue": 1, + "maxValue": 600, + "defaultValue": 10 + } + ], + "stateTypes": [ + { + "id": "5983d714-5f80-42d8-bee2-9228b6382b3b", + "name": "currentPower", + "displayName": "Power", + "displayNameEvent": "Power changed", + "type": "double", + "defaultValue": 0.00, + "unit": "Watt" + }, + { + "id": "5821edb7-e6cb-4e5a-9d0b-3375126d3367", + "name": "totalEnergyConsumed", + "displayName": "Energy", + "displayNameEvent": "Energy changed", + "type": "double", + "defaultValue": 0.00, + "unit": "KiloWattHour" + }, + { + "id": "9cd7e5ca-f8f8-48d5-9785-911ae75158c3", + "name": "impulseInput", + "displayName": "Impulse input", + "displayNameEvent": "Impulse input changed", + "displayNameAction": "Set impulse input", + "type": "bool", + "defaultValue": false, + "writable": true, + "ioType": "digitalOutput" + } + ] } ] } diff --git a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts index e2076c93..25a6b0d5 100644 --- a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts +++ b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-de.ts @@ -28,7 +28,7 @@ The name of the StateType ({fcb700c4-5da8-4385-85b0-6616e807974e}) of ThingClass Angle end to end time [MilliSecond] - The name of the ParamType (ThingClass: venetianBlind, Type: thing, ID: {6c8340bf-7fd3-43e3-a75b-dfa2f6426e11}) + The name of the ParamType (ThingClass: venetianBlind, Type: settings, ID: {6c8340bf-7fd3-43e3-a75b-dfa2f6426e11}) End- zu Endwinkelzeit @@ -92,9 +92,9 @@ The name of the EventType ({59bfd575-709f-4e43-9726-de26e6d4ca8b}) of ThingClass Closing time [MilliSecond] - The name of the ParamType (ThingClass: venetianBlind, Type: thing, ID: {4c0bf07d-aaab-4f67-af65-00ceaefbaa84}) + The name of the ParamType (ThingClass: venetianBlind, Type: settings, ID: {4c0bf07d-aaab-4f67-af65-00ceaefbaa84}) ---------- -The name of the ParamType (ThingClass: extendedBlind, Type: thing, ID: {27a95b8d-7f97-441b-a3be-0646c517cb06}) +The name of the ParamType (ThingClass: extendedBlind, Type: settings, ID: {27a95b8d-7f97-441b-a3be-0646c517cb06}) Schließdauer [Millisekunden] @@ -340,7 +340,11 @@ The name of the EventType ({181df603-d45f-4d3d-a358-97aa3e4ac0bd}) of ThingClass Power - The name of the ParamType (ThingClass: ventilation, ActionType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: currentPower, ID: {5983d714-5f80-42d8-bee2-9228b6382b3b}) +---------- +The name of the StateType ({5983d714-5f80-42d8-bee2-9228b6382b3b}) of ThingClass extendedSmartMeterConsumer +---------- +The name of the ParamType (ThingClass: ventilation, ActionType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) ---------- The name of the ParamType (ThingClass: ventilation, EventType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) ---------- @@ -379,7 +383,9 @@ The name of the StateType ({018038d7-1d02-4b17-8fe3-babca044b087}) of ThingClass Power changed - The name of the EventType ({409b635e-a754-4b5c-b3f0-d1c5a0fb3f03}) of ThingClass heating + The name of the EventType ({5983d714-5f80-42d8-bee2-9228b6382b3b}) of ThingClass extendedSmartMeterConsumer +---------- +The name of the EventType ({409b635e-a754-4b5c-b3f0-d1c5a0fb3f03}) of ThingClass heating ---------- The name of the EventType ({8b6e4a67-6522-408b-b676-8d2f09ed2d54}) of ThingClass light ---------- @@ -549,5 +555,62 @@ The name of the EventType ({0212a287-c5ae-4644-8803-adfdd8caeb9a}) of ThingClass The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea + + Energy + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: totalEnergyConsumed, ID: {5821edb7-e6cb-4e5a-9d0b-3375126d3367}) +---------- +The name of the StateType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer + Energie + + + Energy changed + The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer + Energie geändert + + + Impulse/kWh + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871}) + Impulse/kWh + + + Impulse input + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) +---------- +The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) +---------- +The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + Impulseingang + + + Impulse input changed + The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + Impulseingang geändert + + + Set impulse input + The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + Setze Impulseingang + + + Timeframe for power calculation + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {73c9acc3-8f76-40d7-a79b-a1f08bb308d4}) + Zeitfenster für Leistungsberechnung + + + Impulse based energy meter + The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52}) + Impulsbasierter Energiezähler + + + + IntegrationPluginGenericThings + + Invalid closing time + Ungültige Schließzeit + + + Invalid closing or angle time + Ungültige Schließ- oder Winkelstellzeit + diff --git a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts index 0025225d..fd67c5f9 100644 --- a/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts +++ b/genericthings/translations/b3188696-2585-4806-bf98-30ab576ce5c8-en_US.ts @@ -28,7 +28,7 @@ The name of the StateType ({fcb700c4-5da8-4385-85b0-6616e807974e}) of ThingClass Angle end to end time [MilliSecond] - The name of the ParamType (ThingClass: venetianBlind, Type: thing, ID: {6c8340bf-7fd3-43e3-a75b-dfa2f6426e11}) + The name of the ParamType (ThingClass: venetianBlind, Type: settings, ID: {6c8340bf-7fd3-43e3-a75b-dfa2f6426e11}) @@ -92,9 +92,9 @@ The name of the EventType ({59bfd575-709f-4e43-9726-de26e6d4ca8b}) of ThingClass Closing time [MilliSecond] - The name of the ParamType (ThingClass: venetianBlind, Type: thing, ID: {4c0bf07d-aaab-4f67-af65-00ceaefbaa84}) + The name of the ParamType (ThingClass: venetianBlind, Type: settings, ID: {4c0bf07d-aaab-4f67-af65-00ceaefbaa84}) ---------- -The name of the ParamType (ThingClass: extendedBlind, Type: thing, ID: {27a95b8d-7f97-441b-a3be-0646c517cb06}) +The name of the ParamType (ThingClass: extendedBlind, Type: settings, ID: {27a95b8d-7f97-441b-a3be-0646c517cb06}) @@ -340,7 +340,11 @@ The name of the EventType ({181df603-d45f-4d3d-a358-97aa3e4ac0bd}) of ThingClass Power - The name of the ParamType (ThingClass: ventilation, ActionType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: currentPower, ID: {5983d714-5f80-42d8-bee2-9228b6382b3b}) +---------- +The name of the StateType ({5983d714-5f80-42d8-bee2-9228b6382b3b}) of ThingClass extendedSmartMeterConsumer +---------- +The name of the ParamType (ThingClass: ventilation, ActionType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) ---------- The name of the ParamType (ThingClass: ventilation, EventType: power, ID: {846711b7-ea5a-4c66-a267-001c60406509}) ---------- @@ -379,7 +383,9 @@ The name of the StateType ({018038d7-1d02-4b17-8fe3-babca044b087}) of ThingClass Power changed - The name of the EventType ({409b635e-a754-4b5c-b3f0-d1c5a0fb3f03}) of ThingClass heating + The name of the EventType ({5983d714-5f80-42d8-bee2-9228b6382b3b}) of ThingClass extendedSmartMeterConsumer +---------- +The name of the EventType ({409b635e-a754-4b5c-b3f0-d1c5a0fb3f03}) of ThingClass heating ---------- The name of the EventType ({8b6e4a67-6522-408b-b676-8d2f09ed2d54}) of ThingClass light ---------- @@ -549,5 +555,62 @@ The name of the EventType ({0212a287-c5ae-4644-8803-adfdd8caeb9a}) of ThingClass The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) + + Energy + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: totalEnergyConsumed, ID: {5821edb7-e6cb-4e5a-9d0b-3375126d3367}) +---------- +The name of the StateType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer + + + + Energy changed + The name of the EventType ({5821edb7-e6cb-4e5a-9d0b-3375126d3367}) of ThingClass extendedSmartMeterConsumer + + + + Impulse/kWh + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {c361732b-68eb-447e-a434-e84031231871}) + + + + Impulse input + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, ActionType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) +---------- +The name of the ParamType (ThingClass: extendedSmartMeterConsumer, EventType: impulseInput, ID: {9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) +---------- +The name of the StateType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + + + + Impulse input changed + The name of the EventType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + + + + Set impulse input + The name of the ActionType ({9cd7e5ca-f8f8-48d5-9785-911ae75158c3}) of ThingClass extendedSmartMeterConsumer + + + + Timeframe for power calculation + The name of the ParamType (ThingClass: extendedSmartMeterConsumer, Type: settings, ID: {73c9acc3-8f76-40d7-a79b-a1f08bb308d4}) + + + + Impulse based energy meter + The name of the ThingClass ({c3123967-f741-4fe1-a0d4-9a3e405d7e52}) + + + + + IntegrationPluginGenericThings + + Invalid closing time + + + + Invalid closing or angle time + +