Skip to content

Commit

Permalink
feat: add meter_power.imported and meter_power.exported accumulat…
Browse files Browse the repository at this point in the history
…ed capabilities

By adding these capabilities Homey gets more insight into the users accumulated energy consumption and production (see developer documentation here: feat/accumulated-meter-power-capabilities).

Note: this is untested code, but based on the documentation and API explorer this should work.
  • Loading branch information
RobinBol committed Oct 29, 2024
1 parent 90db5e5 commit 269aca4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
16 changes: 12 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1208,10 +1208,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down Expand Up @@ -1451,10 +1455,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
26 changes: 26 additions & 0 deletions drivers/pulse/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,32 @@ class PulseDevice extends Device {
.catch(console.error);
});
}

const lastMeterConsumption =
result.data?.liveMeasurement?.lastMeterConsumption;
if (typeof lastMeterConsumption === 'number') {
if (this.hasCapability('meter_power.imported') !== true)
await this.addCapability('meter_power.imported').catch(console.error);

const fixedLastMeterConsumption = Number(lastMeterConsumption.toFixed(2));
this.setCapabilityValue(
'meter_power.imported',
fixedLastMeterConsumption,
).catch(console.error);
}

const lastMeterProduction =
result.data?.liveMeasurement?.lastMeterProduction;
if (typeof lastMeterProduction === 'number') {
if (this.hasCapability('meter_power.exported') !== true)
await this.addCapability('meter_power.exported').catch(console.error);

const fixedLastMeterProduction = Number(lastMeterProduction.toFixed(2));
this.setCapabilityValue(
'meter_power.exported',
fixedLastMeterProduction,
).catch(console.error);
}
}

onDeleted() {
Expand Down
8 changes: 6 additions & 2 deletions drivers/pulse/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
26 changes: 26 additions & 0 deletions drivers/watty/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,32 @@ class WattyDevice extends Device {
});
}
}

const lastMeterConsumption =
result.data?.liveMeasurement?.lastMeterConsumption;
if (typeof lastMeterConsumption === 'number') {
if (this.hasCapability('meter_power.imported') !== true)
await this.addCapability('meter_power.imported').catch(console.error);

const fixedLastMeterConsumption = Number(lastMeterConsumption.toFixed(2));
this.setCapabilityValue(
'meter_power.imported',
fixedLastMeterConsumption,
).catch(console.error);
}

const lastMeterProduction =
result.data?.liveMeasurement?.lastMeterProduction;
if (typeof lastMeterProduction === 'number') {
if (this.hasCapability('meter_power.exported') !== true)
await this.addCapability('meter_power.exported').catch(console.error);

const fixedLastMeterProduction = Number(lastMeterProduction.toFixed(2));
this.setCapabilityValue(
'meter_power.exported',
fixedLastMeterProduction,
).catch(console.error);
}
}

onDeleted() {
Expand Down
8 changes: 6 additions & 2 deletions drivers/watty/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"accumulatedCost",
"measure_current.L1",
"measure_current.L2",
"measure_current.L3"
"measure_current.L3",
"meter_power.imported",
"meter_power.exported"
],
"energy": {
"cumulative": true
"cumulative": true,
"cumulativeImportedCapability": "meter_power.imported",
"cumulativeExportedCapability": "meter_power.exported"
},
"capabilitiesOptions": {
"accumulatedCost": {
Expand Down
2 changes: 2 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface LiveMeasurement {
power: number;
accumulatedConsumption: number;
accumulatedCost: number | null;
lastMeterConsumption: number | null;
lastMeterProduction: number | null;
currency: string | null;
minPower: number;
averagePower: number;
Expand Down
2 changes: 2 additions & 0 deletions lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const queries = {
power
accumulatedConsumption
accumulatedCost
lastMeterConsumption
lastMeterProduction
currency
minPower
averagePower
Expand Down

0 comments on commit 269aca4

Please sign in to comment.