Skip to content

Commit

Permalink
Merge pull request #22 from troygNZ/raw-metrics
Browse files Browse the repository at this point in the history
Added Raw accessory based readers (configurable)
troygNZ authored Jun 14, 2020
2 parents 647e125 + 0bd2b10 commit 02b8557
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@ npm install homebridge-solax

**valueStrategy**: _Optional_: Defaults to SimpleMovingAverage. LatestReading = use the latest values at each polling period, SimpleMovingAverage for providing some smoothing of values, to handle scenarios like sporadic cloud/sun moments. Averages over the entire history. ExpoentialMovingAverage = Use standard Exponential Moving Average calculation to provide a smoothed last value. Refer to movingAverageHistoryLength for Moving Average based history tuning.

**exposeRawMetrics**: _Optional_: Defaults to true. 3 additional accessories will be exposed to provide the raw value feed (no averaging based filtering).

### Leveraging in Automations via Motion Sensor Accessories

You can then create Automations in HomeKit as a result of the motion detection events (or them ceasing to happen).
7 changes: 7 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
@@ -59,6 +59,13 @@
"required": false,
"default": true
},
"exposeRawMetrics": {
"title": "Show Accessories for the RAW values",
"type": "boolean",
"required": false,
"default": true,
"desciption": "If set to true, 3 accessories will be exposed to provide the raw value feed (no averaging based filtering)."
},
"valueStrategy": {
"title": "The value strategy to apply",
"type": "string",
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge - Solax Solar Inverter Plugin",
"name": "homebridge-solax",
"version": "1.2.2",
"version": "1.3.0",
"description": "A Solax connector that (crudely) exposes readonly metrics as Light Sensors for power generation, import, export, individual string generation, and (experimental) battery metrics. Due to the constraints around HomeKit's support for power inverters, this seemed the best fit. Also has configurable alerts, giving the ability to automate actions as a result of excess power generation, or limited power generation.",
"license": "Apache-2.0",
"repository": {
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export default interface Config {
hasBattery: boolean;
showStrings: boolean;
valueStrategy: ValueStrategy;
exposeRawMetrics: boolean;
}

export enum ValueStrategy {
@@ -23,6 +24,7 @@ export class ConfigHelper {
log.info(`Polling Freq in Seconds: ${config.pollingFrequencySeconds}`);
log.info(`Export Alert Thresholds: [${config.exportAlertThresholds.join(",")}]`);
log.info(`Battery: ${config.hasBattery}`);
log.info(`Expose Raw Metrics: ${config.exposeRawMetrics}`);
log.info(`Show Strings: ${config.showStrings}`);
log.info(`Value Strategy: ${config.valueStrategy}`);
log.info(`Moving Average History Samples Length: ${config.movingAverageHistoryLength}`);
@@ -41,6 +43,7 @@ export class ConfigHelper {
address: config.address,
hasBattery: config.hasBattery === undefined ? true : config.hasBattery,
showStrings: config.showStrings === undefined ? true : config.showStrings,
exposeRawMetrics: config.exposeRawMetrics === undefined ? true : config.exposeRawMetrics,
movingAverageHistoryLength: config.movingAverageHistoryLength === undefined ? 10 : config.movingAverageHistoryLength,
pollingFrequencySeconds: config.pollingFrequencySeconds === undefined ? 60 : config.pollingFrequencySeconds,
exportAlertThresholds: config.exportAlertThresholds === null ? [] : config.exportAlertThresholds,
19 changes: 18 additions & 1 deletion src/solaxPlatform.ts
Original file line number Diff line number Diff line change
@@ -84,7 +84,23 @@ Where the polling frequency is ${this.config.pollingFrequencySeconds} seconds. K
}),
];

let battery = null;
const rawAccessories: AccessoryPlugin[] = this.config.exposeRawMetrics
? [
new WattsReadingAccessory(this.api.hap, this.log, "Exported Watts Raw", this.inverterStateEmitter, () => {
const result = this.history.getLatestRawValues().exportedWatts;
return result >= 0 ? result : 0;
}),
new WattsReadingAccessory(this.api.hap, this.log, "Imported Watts Raw", this.inverterStateEmitter, () => {
const result = this.history.getLatestRawValues().exportedWatts;
return result < 0 ? Math.abs(result) : 0;
}),
new WattsReadingAccessory(this.api.hap, this.log, "Power Gen Watts Raw", this.inverterStateEmitter, () => {
return this.history.getLatestRawValues().generationWatts;
}),
]
: [];

let battery: SolarBattery | null = null;
if (this.config.hasBattery) {
const getDetails = () => {
const result = this.history.getFilteredValues();
@@ -128,6 +144,7 @@ Where the polling frequency is ${this.config.pollingFrequencySeconds} seconds. K
.concat(exportAlarms)
.concat(battery === null ? [] : battery)
.concat(inverterStrings)
.concat(rawAccessories)
);
}
}

0 comments on commit 02b8557

Please sign in to comment.