Fix first consumption of an Asset
MODIFY
src/integration/asset/greencom/GreencomAssetIntegration.ts
src/integration/asset/greencom/GreencomAssetIntegration.ts
@@ -32,7 +32,8 @@ export default class GreencomAssetIntegration extends AssetIntegration<AssetSett
const token = await this.connect();
const request = manualCall ?
`${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${moment().subtract(1, 'minutes').toISOString()}&to=${moment().toISOString()}&step=PT1M` :
- `${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${asset.lastConsumption.timestamp.toISOString()}&to=${moment().toISOString()}&step=PT1M`;
+ // Check if it is first consumption for this asset
+ `${this.connection.url}/site-api/${asset.meterID}?withEnergy=true&withPower=true&from=${(asset.lastConsumption?.timestamp) ? asset.lastConsumption.timestamp.toISOString() : moment().subtract(1, 'minutes').toISOString()}&to=${moment().toISOString()}&step=PT1M`;
try {
// Get consumption
const response = await this.axiosInstance.get(

MODIFY
src/scheduler/tasks/AssetGetConsumptionTask.ts
src/scheduler/tasks/AssetGetConsumptionTask.ts
@@ -15,6 +15,7 @@ import { TaskConfig } from '../../types/TaskConfig';
import Tenant from '../../types/Tenant';
import TenantComponents from '../../types/TenantComponents';
import Utils from '../../utils/Utils';
+import moment from 'moment';
const MODULE_NAME = 'AssetGetConsumptionTask';
@@ -51,7 +52,7 @@ export default class AssetGetConsumptionTask extends SchedulerTask {
for (const consumption of assetConsumptions) {
// Create Consumption to save
const consumptionToSave: Consumption = {
- startedAt: asset.lastConsumption.timestamp,
+ startedAt: asset.lastConsumption?.timestamp ? asset.lastConsumption.timestamp : moment(consumption.lastConsumption.timestamp).subtract(1, 'minutes').toDate(),
endedAt: consumption.lastConsumption.timestamp,
assetID: asset.id,
cumulatedConsumptionWh: consumption.currentConsumptionWh,

Fix first consumption of an Asset