From a17852e17a49fb5a610dd9a2739b22252c120bf9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 23 Feb 2023 22:33:31 +0100 Subject: [PATCH 1/2] Add generic energy meter --- .../integrationplugingenericenergy.cpp | 13 ++++ .../integrationplugingenericenergy.json | 59 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/genericenergy/integrationplugingenericenergy.cpp b/genericenergy/integrationplugingenericenergy.cpp index a1c497a..f26d792 100644 --- a/genericenergy/integrationplugingenericenergy.cpp +++ b/genericenergy/integrationplugingenericenergy.cpp @@ -89,6 +89,19 @@ void IntegrationPluginGenericEnergy::executeAction(ThingActionInfo *info) } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } + } else if (thing->thingClassId() == energyMeterThingClassId) { + if (action.actionTypeId() == energyMeterCurrentPowerActionTypeId) { + thing->setStateValue(energyMeterCurrentPowerStateTypeId, action.paramValue(energyMeterCurrentPowerActionCurrentPowerParamTypeId)); + } else if (action.actionTypeId() == energyMeterTotalEnergyConsumedActionTypeId) { + thing->setStateValue(energyMeterTotalEnergyConsumedStateTypeId, action.paramValue(energyMeterTotalEnergyConsumedActionTotalEnergyConsumedParamTypeId)); + } else if (action.actionTypeId() == energyMeterTotalEnergyProducedActionTypeId) { + thing->setStateValue(energyMeterTotalEnergyProducedStateTypeId, action.paramValue(energyMeterTotalEnergyProducedActionTotalEnergyProducedParamTypeId)); + } else if (action.actionTypeId() == energyMeterCurrentPhaseAActionTypeId) { + thing->setStateValue(energyMeterCurrentPhaseAStateTypeId, action.paramValue(energyMeterCurrentPhaseAActionCurrentPhaseAParamTypeId)); + } else if (action.actionTypeId() == energyMeterVoltagePhaseAActionTypeId) { + thing->setStateValue(energyMeterVoltagePhaseAStateTypeId, action.paramValue(energyMeterVoltagePhaseAActionVoltagePhaseAParamTypeId)); + } + info->finish(Thing::ThingErrorNoError); } else if (thing->thingClassId() == impulseSmartMeterThingClassId) { if (action.actionTypeId() == impulseSmartMeterImpulseInputActionTypeId) { bool value = info->action().param(impulseSmartMeterImpulseInputActionImpulseInputParamTypeId).value().toBool(); diff --git a/genericenergy/integrationplugingenericenergy.json b/genericenergy/integrationplugingenericenergy.json index 3767668..e394d3f 100644 --- a/genericenergy/integrationplugingenericenergy.json +++ b/genericenergy/integrationplugingenericenergy.json @@ -28,6 +28,65 @@ } ] }, + { + "id": "7bba50d7-e18a-41a8-8267-7aa4876ec475", + "name": "energyMeter", + "displayName": "Generic energy meter", + "createMethods": ["user"], + "interfaces": ["energymeter"], + "stateTypes": [ + { + "id": "d5f3fb79-3654-4aaf-ae30-3a761fe2dfd8", + "name": "currentPower", + "displayName": "Current Power usage", + "displayNameAction": "Set current Power usage", + "type": "double", + "defaultValue": 0.00, + "unit": "Watt", + "writable": true + }, + { + "id": "db36a37d-7c48-4208-8b6e-a1b93acb827f", + "name": "totalEnergyConsumed", + "displayName": "Total obtained energy", + "displayNameAction": "Set total obtained energy", + "type": "double", + "defaultValue": 0.00, + "unit": "KiloWattHour", + "writable": true + }, + { + "id": "e73d72f3-b172-4db0-9120-0f713e210bdf", + "name": "totalEnergyProduced", + "displayName": "Total returned energy", + "displayNameAction": "Set total returned energy", + "type": "double", + "defaultValue": 0.00, + "unit": "KiloWattHour", + "writable": true + }, + { + "id": "e493ec25-fb8a-4e36-84d9-4430418b3b6f", + "name": "currentPhaseA", + "displayName": "Current on phase A", + "displayNameAction": "Set current on phase A", + "type": "double", + "defaultValue": 0.00, + "unit": "Ampere", + "writable": true + }, + { + "id": "03deaf24-e515-4649-8979-ef8ae8ee7c02", + "name": "voltagePhaseA", + "displayName": "Voltage on phase A", + "displayNameAction": "Set voltage on phase A", + "type": "double", + "defaultValue": 0.00, + "unit": "Volt", + "writable": true + } + ] + }, { "id": "c3123967-f741-4fe1-a0d4-9a3e405d7e52", "name": "impulseSmartMeter", From 6c8b576522f48f817d85ecc6a6eb27ff19e1f064 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 23 Feb 2023 23:06:36 +0100 Subject: [PATCH 2/2] Rework generic battery/energy storage --- .../integrationplugingenericenergy.cpp | 32 ++++++------ .../integrationplugingenericenergy.json | 50 +++++++++++++------ 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/genericenergy/integrationplugingenericenergy.cpp b/genericenergy/integrationplugingenericenergy.cpp index f26d792..b88e3fa 100644 --- a/genericenergy/integrationplugingenericenergy.cpp +++ b/genericenergy/integrationplugingenericenergy.cpp @@ -64,11 +64,14 @@ void IntegrationPluginGenericEnergy::setupThing(ThingSetupInfo *info) thing->setStateValue(impulseSmartMeterCurrentPowerStateTypeId, power*1000); m_pulsesPerTimeframe.insert(thing, 0); }); - } else if (thing->thingClassId() == batteryThingClassId) { + } else if (thing->thingClassId() == energyStorageThingClassId) { connect(thing, &Thing::settingChanged, [thing](const ParamTypeId &settingTypeId, const QVariant &value){ - if (settingTypeId == batterySettingsCriticalLevelParamTypeId) { - int currentBatteryLevel = thing->stateValue(batteryBatteryLevelStateTypeId).toInt(); - thing->setStateValue(batteryBatteryCriticalStateTypeId, currentBatteryLevel <= value.toInt()); + if (settingTypeId == energyStorageSettingsCapacityParamTypeId) { + thing->setStateValue(energyStorageCapacityStateTypeId, value); + } + if (settingTypeId == energyStorageSettingsCriticalLevelParamTypeId) { + int currentBatteryLevel = thing->stateValue(energyStorageBatteryLevelStateTypeId).toInt(); + thing->setStateValue(energyStorageBatteryCriticalStateTypeId, currentBatteryLevel <= value.toInt()); } }); } @@ -139,17 +142,18 @@ void IntegrationPluginGenericEnergy::executeAction(ThingActionInfo *info) } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } - } else if (thing->thingClassId() == batteryThingClassId) { - if (action.actionTypeId() == batteryBatteryLevelControlActionTypeId) { - int value = action.paramValue(batteryBatteryLevelControlActionBatteryLevelControlParamTypeId).toInt(); - thing->setStateValue(batteryBatteryLevelStateTypeId, value); - thing->setStateValue(batteryBatteryLevelControlStateTypeId, value); - int criticalValue = thing->setting(batterySettingsCriticalLevelParamTypeId).toInt(); - thing->setStateValue(batteryBatteryCriticalStateTypeId, value <= criticalValue); + } else if (thing->thingClassId() == energyStorageThingClassId) { + if (action.actionTypeId() == energyStorageBatteryLevelActionTypeId) { + int value = action.paramValue(energyStorageBatteryLevelActionBatteryLevelParamTypeId).toInt(); + thing->setStateValue(energyStorageBatteryLevelStateTypeId, value); + int criticalValue = thing->setting(energyStorageSettingsCriticalLevelParamTypeId).toInt(); + thing->setStateValue(energyStorageBatteryCriticalStateTypeId, value <= criticalValue); info->finish(Thing::ThingErrorNoError); - return; - } else if (action.actionTypeId() == batteryChargingActionTypeId) { - thing->setStateValue(batteryChargingStateTypeId, action.paramValue(batteryChargingActionChargingParamTypeId)); + } else if (action.actionTypeId() == energyStorageCurrentPowerActionTypeId) { + thing->setStateValue(energyStorageCurrentPowerStateTypeId, action.paramValue(energyStorageCurrentPowerActionCurrentPowerParamTypeId)); + info->finish(Thing::ThingErrorNoError); + } else if (action.actionTypeId() == energyStorageChargingActionTypeId) { + thing->setStateValue(energyStorageChargingStateTypeId, action.paramValue(energyStorageChargingActionChargingParamTypeId)); info->finish(Thing::ThingErrorNoError); return; } diff --git a/genericenergy/integrationplugingenericenergy.json b/genericenergy/integrationplugingenericenergy.json index e394d3f..d2dd725 100644 --- a/genericenergy/integrationplugingenericenergy.json +++ b/genericenergy/integrationplugingenericenergy.json @@ -148,11 +148,20 @@ }, { "id": "81418556-cae3-4803-aa0c-9c4b3304a3eb", - "name": "battery", - "displayName": "Generic battery", + "name": "energyStorage", + "displayName": "Generic energy storage", "createMethods": ["user"], - "interfaces": ["battery"], + "interfaces": ["energystorage"], "settingsTypes": [ + { + "id": "c170df55-029d-4b67-ae09-248645dd7040", + "name": "capacity", + "displayName": "Capacity", + "type": "double", + "unit": "KiloWattHour", + "minValue": 0, + "defaultValue": 50000 + }, { "id": "8d875cb7-3a14-42d1-bf1b-759e5fd95a8f", "name": "criticalLevel", @@ -164,28 +173,29 @@ } ], "stateTypes": [ + { + "id": "8d1c43f9-4528-4797-8f6a-f7b91fbb91d0", + "name": "currentPower", + "displayName": "Current power", + "displayNameAction": "Set current power", + "type": "double", + "unit": "Watt", + "defaultValue": 0, + "writable": true, + "minValue": -10000, + "maxValue": 10000, + "ioType": "analogOutput" + }, { "id": "d37eed4a-befc-40d4-b435-40a761f99314", "name": "batteryLevel", "displayName": "Battery level", - "displayNameEvent": "Battery level changed", + "displayNameAction": "Set battery level", "type": "int", "unit": "Percentage", "defaultValue": 0, "minValue": 0, - "maxValue": 100 - }, - { - "id": "3336f0c2-158b-4353-b74f-f1bb9c4e8447", - "name": "batteryLevelControl", - "displayName": "Battery level control", - "displayNameEvent": "Battery level control changed", - "displayNameAction": "Set battery level", - "type": "double", - "minValue": 0, "maxValue": 100, - "defaultValue": 0, - "unit": "Percentage", "writable": true, "ioType": "analogOutput" }, @@ -207,6 +217,14 @@ "displayNameEvent": "Battery entered or left critical state", "type": "bool", "defaultValue": false + }, + { + "id": "bf076970-20fe-46f7-b4bc-fe34ec833829", + "name": "capacity", + "displayName": "Capacity", + "type": "double", + "unit": "KiloWattHour", + "defaultValue": 10000 } ] },