diff --git a/README.md b/README.md index b8ca322..8d051f0 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/config.schema.json b/config.schema.json index 004ad64..9b0ed3f 100644 --- a/config.schema.json +++ b/config.schema.json @@ -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", diff --git a/package.json b/package.json index b0a3d09..c6b5761 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/config.ts b/src/config.ts index 008a4a3..b947eb6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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, diff --git a/src/solaxPlatform.ts b/src/solaxPlatform.ts index 19dbdaf..ffed623 100644 --- a/src/solaxPlatform.ts +++ b/src/solaxPlatform.ts @@ -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) ); } }