homebridge-solaxcloud-api 1.5.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +28 -18
  2. package/config.schema.json +28 -0
  3. package/dist/lightSensorAccessory.d.ts +36 -0
  4. package/dist/lightSensorAccessory.d.ts.map +1 -0
  5. package/dist/lightSensorAccessory.js +60 -0
  6. package/dist/lightSensorAccessory.js.map +1 -0
  7. package/dist/outletAccessory.d.ts +23 -4
  8. package/dist/outletAccessory.d.ts.map +1 -1
  9. package/dist/outletAccessory.js +70 -18
  10. package/dist/outletAccessory.js.map +1 -1
  11. package/dist/platform.d.ts +45 -14
  12. package/dist/platform.d.ts.map +1 -1
  13. package/dist/platform.js +231 -67
  14. package/dist/platform.js.map +1 -1
  15. package/dist/platformAccessory.d.ts +5 -0
  16. package/dist/platformAccessory.d.ts.map +1 -1
  17. package/dist/platformAccessory.js +10 -3
  18. package/dist/platformAccessory.js.map +1 -1
  19. package/dist/platformMeters.d.ts +53 -0
  20. package/dist/platformMeters.d.ts.map +1 -0
  21. package/dist/platformMeters.js +3 -0
  22. package/dist/platformMeters.js.map +1 -0
  23. package/dist/solaxcloudfetch.d.ts +2 -0
  24. package/dist/solaxcloudfetch.d.ts.map +1 -0
  25. package/dist/solaxcloudfetch.js +19 -0
  26. package/dist/solaxcloudfetch.js.map +1 -0
  27. package/dist/statistics.d.ts +36 -1
  28. package/dist/statistics.d.ts.map +1 -1
  29. package/dist/statistics.js +86 -16
  30. package/dist/statistics.js.map +1 -1
  31. package/images/homebridge-ui.png +0 -0
  32. package/images/plugin-accessories-home-pure.png +0 -0
  33. package/images/plugin-accessories-home.png +0 -0
  34. package/images/plugin-outlet-consumption.png +0 -0
  35. package/package.json +3 -3
  36. package/test/solaxcloudapi.test.ts +1 -1
  37. package/test/statistics.test.ts +51 -0
package/README.md CHANGED
@@ -15,15 +15,17 @@ The Solax Cloud Plugin for [Homebridge](https://homebridge.io/) was created as a
15
15
 
16
16
  As HomeKit is still clueless about what a solar panel is, this plugin exposes a set of standard HomeKit accessories though Homebridge that will allow interacting and automating your smart home based on the data made available from the Solax platform:
17
17
 
18
- - **Inverter PV** (outlet with power consumption)
19
- - **Inverter AC** (outlet with power and total energy consumptions)
20
- - **Inverter to Grid** (outlet with power consumption)
21
- - **Inverter to House** (outlet with power consumption)
22
- - **Grid To House** (outlet with power consumption)
18
+ - **PV** (PV outlet with power consumption)
19
+ - **AC** (Inverter AC outlet with power and total energy consumptions)
20
+ - **To Grid** (Inverter to Grid outlet with power consumption)
21
+ - **To House** (Inverter to House outlet with power consumption)
22
+ - **From Grid** (Grid to House outlet with power consumption)
23
23
  - **Update** (Motion sensor)
24
24
 
25
25
  <img src="images/plugin-accessories-home.png" width="50%" height="50%">
26
26
 
27
+ Please note that additional accessories are created by default with smooth power consumption curves (by applying either a simple or exponential moving average to the power series). This prevents sporadic events like a cloud passing by to have an immediate affect on provided meters.
28
+
27
29
  ## Required information
28
30
 
29
31
  For this plugin to work, two critical pieces of information are required:
@@ -42,32 +44,34 @@ Edit `config.json` manually to add your Solax inverters. See below for instructi
42
44
 
43
45
  ## Platform configuration
44
46
 
45
- Platform configuration is depicted by the example configuration file below:
47
+ Minimal platform configuration is depicted by the example configuration file below:
46
48
 
47
49
  ```json
48
50
  {
49
51
  "platforms": [
50
52
  {
51
53
  "platform": "SolaxCloudAPI",
52
- "name": "My Solax",
54
+ "name": "Solax",
53
55
  "tokenId": "20200722185111234567890",
54
- "sn": "ABCDEFGHIJ",
55
- "pollingFrequency": 60
56
+ "sn": "ABCDEFGHIJ"
56
57
  }
57
58
  ]
58
59
  }
59
60
  ```
60
61
  Configuration parameters are described on the table below:
61
62
 
62
- | **Parameter** | **Type** | **Description** | **Default** | **Mandatory?** |
63
- | ------------------ | -------- | --------------- | ----------: | :------------: |
64
- | `platform` | string | Platform name (must be SolaxCloudAPI) | - | Y |
65
- | `name` | string | Inverter name, used as prefix for accessory naming | - | Y |
66
- | `tokenId` | string | Users get information from Solax Cloud through the granted tokenID. Please obtain your tokenID on the API page of Solax Cloud. | - | Y |
67
- | `sn` | string | Registration No. (inverter module SN) | - | Y |
68
- | `pollingFrequency` | number | Plugin data polling frequency from Solax Cloud (in seconds) | 300 | N |
63
+ | **Parameter** | **Type** | **Description** | **Default** | **Mandatory?** |
64
+ | ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------- | -------------:| :------------: |
65
+ | `platform` | string | Platform name (must be SolaxCloudAPI) | - | Y |
66
+ | `name` | string | Inverter name, used as prefix for accessory naming | - | Y |
67
+ | `tokenId` | string | Users get information from Solax Cloud through the granted tokenID. Please obtain your tokenID on the API page of Solax Cloud | - | Y |
68
+ | `sn` | string | Registration No. (inverter module SN) | - | Y |
69
+ | `pollingFrequency` | number | Plugin data polling frequency from Solax Cloud (in seconds) | 300 | N |
70
+ | `smoothingMeters` | boolean | Whether to create additional meters by smoothing raw values from Solax Cloud | true | N |
71
+ | `smoothingMethod` | string | Statistical method to use for smoothing raw values from Solax Cloud (simple or exponential moving average - "sma" or "ema") | "sma" | N |
72
+ | `pureHomeApp` | boolean | Whether to create meters as standard accessories that can be used on the Home App (power will show as ambient light sensors) | false | N |
69
73
 
70
- **NOTE:** The `pollingFrequency` parameter is optional and defaults to 300 seconds, since Solax inverters update cloud data every 5 minutes.
74
+ **NOTE:** The `pollingFrequency` parameter defaults to 300 seconds, since Solax inverters update cloud data every 5 minutes.
71
75
 
72
76
  Configuration through the the use of [Homebridge UI](https://github.com/oznu/homebridge-config-ui-x) plugin is also available and recommended:
73
77
 
@@ -77,10 +81,14 @@ Configuration through the the use of [Homebridge UI](https://github.com/oznu/hom
77
81
 
78
82
  Non-standard accessory characteristics are available through the use of [Eve for HomeKit app](https://apps.apple.com/us/app/eve-for-homekit/id917695792) you may download from the App Store.
79
83
 
80
- This will allow some important non-standard characteristics to be visible (like power or total energy consumption), as depicted in the image below:
84
+ This will allow some non-standard characteristics to be visible along with its historical data (like power or total energy consumption), as depicted in the image below:
81
85
 
82
86
  <img src="images/plugin-outlet-consumption.png" width="50%" height="50%">
83
87
 
88
+ If you want to rely solely on the native Home App, please enable the `pureHomeApp` config setting. In this case, power consumption on each meter will be exposed as an Ambient Light Sensor, as shown below (minimum value for an Ambient Light Sensor is 0.1 lux):
89
+
90
+ <img src="images/plugin-accessories-home-pure.png" width="50%" height="50%">
91
+
84
92
  # Automation
85
93
 
86
94
  Automation can be achieved with the help of the virtual **Update** motion sensor that was specifically tailored for this effect. This motion sensor will be triggered whenever data gets updated from the Solax Cloud API (according to what is defined on the `pollingFrequency` configuration setting).
@@ -168,4 +176,6 @@ Next planned plugin releases should include:
168
176
 
169
177
  - [X] **Inverter AC** to include Yield Energy
170
178
  - [X] Consumption history through the [fakegato-history](https://github.com/simont77/fakegato-history) module
179
+ - [x] Enable support for "pure" Home App accessories (power meters will be exposed as Ambient Light sensors)
180
+ - [x] Add "smooth" accessories for power meters (compensating for sporadic scenarios like cloud a passing)
171
181
  - [ ] Accessories for battery state and consumptions (do not have one available)
@@ -44,6 +44,34 @@
44
44
  { "title": "900 (15 minutes)", "enum": [ 900 ] }
45
45
  ],
46
46
  "description": "Plugin data polling frequency from Solax Cloud (in seconds)."
47
+ },
48
+ "smoothMeters": {
49
+ "title": "Add accessories for smooth meters?",
50
+ "type": "boolean",
51
+ "required": false,
52
+ "default": true,
53
+ "description": "Enable this option to create accessories for smoothing raw values read from Solax Cloud."
54
+ },
55
+ "smoothingMethod": {
56
+ "title": "Smoothing method",
57
+ "type": "string",
58
+ "required": true,
59
+ "default": "sma",
60
+ "oneOf": [
61
+ { "title": "Simple moving average", "enum": [ "sma" ] },
62
+ { "title": "Exponential moving average", "enum": [ "ema" ] }
63
+ ],
64
+ "condition": {
65
+ "functionBody": "return model.smoothMeters === true;"
66
+ },
67
+ "description": "Statistical method for smoothing power consumption data."
68
+ },
69
+ "pureHomeApp": {
70
+ "title": "Add \"pure\" Home app accessories?",
71
+ "type": "boolean",
72
+ "required": false,
73
+ "default": false,
74
+ "description": "Enable this option to create light ambient sensors for power consumption."
47
75
  }
48
76
  }
49
77
  }
@@ -0,0 +1,36 @@
1
+ import { AccessoryPlugin, CharacteristicGetCallback, Logging, Service } from 'homebridge';
2
+ import { SolaxCloudAPIPlatform } from './platform';
3
+ import { SolaxPlatformAccessory } from './platformAccessory';
4
+ /**
5
+ * Solax Light Sensor Accessory.
6
+ * Virtual light sensor used to monitor and measure both power consumption from Solax devices
7
+ * (for "Home app"-only purists).
8
+ * Using Lux to display power comsumption.
9
+ */
10
+ export declare class SolaxLightSensorAccessory extends SolaxPlatformAccessory implements AccessoryPlugin {
11
+ private readonly lightService;
12
+ /**
13
+ * Ambient light level.
14
+ */
15
+ private lux;
16
+ /**
17
+ * Solax virtual light sensor class constructor.
18
+ * @param {SolaxCloudApiPlatform} platform The API Platform for Solax Cloud.
19
+ * @param {Logging} log The platform logging for homebridge.
20
+ * @param {string} name The accessory name.
21
+ * @param {string} serial "Real world" serial number for this accessory.
22
+ * @param {string} model Accessory model.
23
+ */
24
+ constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serial: string, model: string);
25
+ /**
26
+ * Gets the current ambient light level (power consumpion in Watts).
27
+ */
28
+ getAmbientLightLevel(callback: CharacteristicGetCallback): void;
29
+ /**
30
+ * Sets the current ambient light level (power consumption in Watts).
31
+ * @param {number} lux The lux (power consumption) value to set.
32
+ */
33
+ setAmbientLightLevel(lux: number): void;
34
+ getServices(): Service[];
35
+ }
36
+ //# sourceMappingURL=lightSensorAccessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightSensorAccessory.d.ts","sourceRoot":"","sources":["../src/lightSensorAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA4B,yBAAyB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,sBAAuB,YAAW,eAAe;IAC9F,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IAEvC;;OAEG;IACH,OAAO,CAAC,GAAG,CAAK;IAEhB;;;;;;;OAOG;gBACS,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAgBtG;;OAEG;IACI,oBAAoB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAMtE;;;OAGG;IACI,oBAAoB,CAAC,GAAG,EAAE,MAAM;IAavC,WAAW,IAAI,OAAO,EAAE;CAIzB"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolaxLightSensorAccessory = void 0;
4
+ const platformAccessory_1 = require("./platformAccessory");
5
+ /**
6
+ * Solax Light Sensor Accessory.
7
+ * Virtual light sensor used to monitor and measure both power consumption from Solax devices
8
+ * (for "Home app"-only purists).
9
+ * Using Lux to display power comsumption.
10
+ */
11
+ class SolaxLightSensorAccessory extends platformAccessory_1.SolaxPlatformAccessory {
12
+ /**
13
+ * Solax virtual light sensor class constructor.
14
+ * @param {SolaxCloudApiPlatform} platform The API Platform for Solax Cloud.
15
+ * @param {Logging} log The platform logging for homebridge.
16
+ * @param {string} name The accessory name.
17
+ * @param {string} serial "Real world" serial number for this accessory.
18
+ * @param {string} model Accessory model.
19
+ */
20
+ constructor(platform, log, name, serial, model) {
21
+ super(platform, log, name, serial, model);
22
+ /**
23
+ * Ambient light level.
24
+ */
25
+ this.lux = 0;
26
+ const hap = this.platform.api.hap;
27
+ this.log.debug(`Creating light "${this.name}"`);
28
+ this.lightService = new hap.Service.LightSensor(name);
29
+ this.lightService
30
+ .getCharacteristic(hap.Characteristic.CurrentAmbientLightLevel)
31
+ .on("get" /* GET */, this.getAmbientLightLevel.bind(this));
32
+ log.info(`Solax light (watts reader) ${name} created!`);
33
+ }
34
+ /**
35
+ * Gets the current ambient light level (power consumpion in Watts).
36
+ */
37
+ getAmbientLightLevel(callback) {
38
+ this.log.debug(`${this.name}: GET Ambient Light Level (lux=${this.lux})`);
39
+ callback(null, this.lux);
40
+ }
41
+ /**
42
+ * Sets the current ambient light level (power consumption in Watts).
43
+ * @param {number} lux The lux (power consumption) value to set.
44
+ */
45
+ setAmbientLightLevel(lux) {
46
+ this.log.debug(`${this.name}: SET Ambient Light Level (lux=${lux})`);
47
+ // Minimum value allowed for light sensor is 0.1
48
+ this.lux = Math.max(0.1, lux);
49
+ this.lightService.updateCharacteristic(this.platform.api.hap.Characteristic.CurrentAmbientLightLevel, this.lux);
50
+ }
51
+ /*
52
+ * This method is called directly after creation of this instance.
53
+ * It should return all services which should be added to the accessory.
54
+ */
55
+ getServices() {
56
+ return [this.informationService, this.lightService];
57
+ }
58
+ }
59
+ exports.SolaxLightSensorAccessory = SolaxLightSensorAccessory;
60
+ //# sourceMappingURL=lightSensorAccessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightSensorAccessory.js","sourceRoot":"","sources":["../src/lightSensorAccessory.ts"],"names":[],"mappings":";;;AAGA,2DAA6D;AAE7D;;;;;GAKG;AACH,MAAa,yBAA0B,SAAQ,0CAAsB;IAQnE;;;;;;;OAOG;IACH,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,MAAc,EAAE,KAAa;QACpG,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAd5C;;WAEG;QACK,QAAG,GAAG,CAAC,CAAC;QAad,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAElC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mBAAmB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAEtD,IAAI,CAAC,YAAY;aACd,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,wBAAwB,CAAC;aAC9D,EAAE,kBAA+B,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE1E,GAAG,CAAC,IAAI,CAAC,8BAA8B,IAAI,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,oBAAoB,CAAC,QAAmC;QAC7D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,kCAAkC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;QAE1E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,oBAAoB,CAAC,GAAW;QACrC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,kCAAkC,GAAG,GAAG,CAAC,CAAC;QAErE,gDAAgD;QAChD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAE9B,IAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,wBAAwB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAClH,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,CAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,YAAY,CAAE,CAAC;IACxD,CAAC;CAEF;AA9DD,8DA8DC"}
@@ -23,6 +23,14 @@ export declare class SolaxOutletAccessory extends SolaxPlatformAccessory impleme
23
23
  * Elgato Eve fake history service for energy and status.
24
24
  */
25
25
  private readonly loggingService;
26
+ /**
27
+ * Power series for smoothing operations.
28
+ */
29
+ private readonly powerSeries;
30
+ /**
31
+ * Last Exponential Moving Average.
32
+ */
33
+ private lastEMA;
26
34
  /**
27
35
  * Solax virtual outlet class constructor.
28
36
  * @param {SolaxCloudApiPlatform} platform The API Platform for Solax Cloud.
@@ -33,11 +41,22 @@ export declare class SolaxOutletAccessory extends SolaxPlatformAccessory impleme
33
41
  */
34
42
  constructor(platform: SolaxCloudAPIPlatform, log: Logging, name: string, serial: string, model: string);
35
43
  /**
36
- * Sets a characteristic value for a sepecific characteristic.
37
- * @param {string} charName The characteristic name.
38
- * @param {number} value The characteristic value to set.
44
+ * Adds new power entry to series array of power values.
45
+ * @param {number} powerConsumption Power value to add (in Watts).
46
+ */
47
+ private addPowerEntry;
48
+ /**
49
+ * Gets array series with power consumption values.
50
+ * @returns {number[]} Array with power consumption values.
51
+ */
52
+ getPowerSeries(): number[];
53
+ /**
54
+ * Get outlet power from power series by smoothing data using the desired method and window size.
55
+ * @param {string} method Method to smooth data ('SMA' or 'EMA').
56
+ * @param {number} windowSize Window size for SMA or EMA.
57
+ * @returns {number} Power value after smoothing (rounded to nearest integer number).
39
58
  */
40
- setCharacteristicValue(charName: string, value: number): void;
59
+ getSmoothPowerConsumption(method: string, windowSize: number): number;
41
60
  /**
42
61
  * Gets the current power consumpion.
43
62
  */
@@ -1 +1 @@
1
- {"version":3,"file":"outletAccessory.d.ts","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,yBAAyB,EAAkB,MAAM,YAAY,CAAC;AAE1G,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAI7D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,sBAAuB,YAAW,eAAe;IAEzF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IAExC;;O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AAQ,CAAC,cAAc,CAAyB;IAExD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAE5C;;OAEG;IACH,OAAO,CAAC,OAAO,CAAK;IAEpB;;;;;;;OAOG;gBACS,QAAQ,EAAE,qBAAqB,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IA8BtG;;;OAGG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACI,cAAc,IAAI,MAAM,EAAE;IAIjC;;;;;OAKG;IACI,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAwC5E;;OAEG;IACI,mBAAmB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAMrE;;wEAEoE;IAC7D,mBAAmB,CAAC,gBAAgB,EAAE,MAAM;IAcnD;;OAEG;IACI,yBAAyB,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAM3E;;;OAGG;IACI,yBAAyB,CAAC,sBAAsB,EAAE,MAAM;IAQ/D;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI;IAU1D,WAAW,IAAI,OAAO,EAAE;CAIzB"}
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SolaxOutletAccessory = void 0;
4
4
  const platformAccessory_1 = require("./platformAccessory");
5
+ const statistics_1 = require("./statistics");
6
+ /**
7
+ * Maximum size for the outlet power series.
8
+ */
9
+ const MAX_POWER_SERIES_SIZE = 1024;
5
10
  /**
6
11
  * Solax Outlet Accessory.
7
12
  * Virtual outlet used to monitor and measure both power and total energy consumption from Solax devices.
@@ -26,6 +31,14 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
26
31
  * Total energy readings in KWh.
27
32
  */
28
33
  this.totalEnergyConsumption = 0.0;
34
+ /**
35
+ * Power series for smoothing operations.
36
+ */
37
+ this.powerSeries = [];
38
+ /**
39
+ * Last Exponential Moving Average.
40
+ */
41
+ this.lastEMA = 0;
29
42
  const hap = this.platform.api.hap;
30
43
  this.log.debug(`Creating outlet "${this.name}"`);
31
44
  // create power meter service
@@ -41,20 +54,62 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
41
54
  this.outletService.getCharacteristic(this.platform.eve.Characteristics.TotalConsumption)
42
55
  .on("get" /* GET */, this.getTotalEnergyConsumption.bind(this));
43
56
  // history logging services
44
- this.loggingService = new this.platform.eveService('energy', this, { storage: 'fs', log: this.log });
57
+ this.loggingService = new this.platform.eveService('energy', this, { storage: 'fs', log: this.log, disableRepeatLastData: true });
45
58
  log.info(`Outlet "${name}" created!`);
46
59
  }
47
60
  /**
48
- * Sets a characteristic value for a sepecific characteristic.
49
- * @param {string} charName The characteristic name.
50
- * @param {number} value The characteristic value to set.
61
+ * Adds new power entry to series array of power values.
62
+ * @param {number} powerConsumption Power value to add (in Watts).
63
+ */
64
+ addPowerEntry(powerConsumption) {
65
+ // check if we reached the limit
66
+ if (this.powerSeries.length === MAX_POWER_SERIES_SIZE) {
67
+ // remove first element
68
+ this.powerSeries.shift();
69
+ }
70
+ // add new element
71
+ this.powerSeries.push(powerConsumption);
72
+ }
73
+ /**
74
+ * Gets array series with power consumption values.
75
+ * @returns {number[]} Array with power consumption values.
76
+ */
77
+ getPowerSeries() {
78
+ return this.powerSeries;
79
+ }
80
+ /**
81
+ * Get outlet power from power series by smoothing data using the desired method and window size.
82
+ * @param {string} method Method to smooth data ('SMA' or 'EMA').
83
+ * @param {number} windowSize Window size for SMA or EMA.
84
+ * @returns {number} Power value after smoothing (rounded to nearest integer number).
51
85
  */
52
- setCharacteristicValue(charName, value) {
53
- // set up characteristic
54
- const char = this.outletService.getCharacteristic(charName);
55
- if (char) {
56
- char.updateValue(value);
86
+ getSmoothPowerConsumption(method, windowSize) {
87
+ this.log.debug(`${this.name}: GET Power Smooth (method=${method}, window=${windowSize})`);
88
+ let result = 0;
89
+ // get power series for window size
90
+ const series = this.getPowerSeries().slice(-windowSize);
91
+ // calculate simple moving average from given window size
92
+ const [sma] = statistics_1.Statistics.simpleMovingAverage(series, Math.min(windowSize, series.length));
93
+ // check if we have enough data for averaging
94
+ switch (method) {
95
+ case 'sma':
96
+ result = sma;
97
+ this.log.debug(`${this.name}: simple moving average (window data=[${series}], power=${result}W)`);
98
+ break;
99
+ case 'ema':
100
+ if (series.length < windowSize) {
101
+ result = sma;
102
+ this.log.debug(`${this.name}: exponential moving average (window data=[${series}], last EMA=none, power=${result}W)`);
103
+ }
104
+ else {
105
+ const lastPowerValue = series[series.length - 1];
106
+ const weight = 2 / (windowSize + 1);
107
+ result = (lastPowerValue - this.lastEMA) * weight + this.lastEMA;
108
+ this.log.debug(`${this.name}: exponential moving average (window data=[${series}], last EMA=${this.lastEMA}, power=${result}W)`);
109
+ }
110
+ this.lastEMA = result;
57
111
  }
112
+ return result;
58
113
  }
59
114
  /**
60
115
  * Gets the current power consumpion.
@@ -69,10 +124,11 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
69
124
  setPowerConsumption(powerConsumption) {
70
125
  this.log.debug(`${this.name}: SET Power (power=${powerConsumption}W)`);
71
126
  this.powerConsumption = powerConsumption >= 0 ? powerConsumption : 0;
72
- this.setCharacteristicValue(this.platform.eve.Characteristics.CurrentConsumption, this.powerConsumption);
127
+ this.outletService.getCharacteristic(this.platform.eve.Characteristics.CurrentConsumption).updateValue(this.powerConsumption);
73
128
  // add entries to history
74
- this.loggingService.
75
- addEntry({ time: Math.round(new Date().valueOf() / 1000), power: this.powerConsumption });
129
+ this.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), power: this.powerConsumption });
130
+ // add new value to power series
131
+ this.addPowerEntry(this.powerConsumption);
76
132
  }
77
133
  /**
78
134
  * Gets the total energy consumpion.
@@ -88,7 +144,7 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
88
144
  setTotalEnergyConsumption(totalEnergyConsumption) {
89
145
  this.log.debug(`${this.name}: SET Total Energy (energy=${totalEnergyConsumption}kWh)`);
90
146
  this.totalEnergyConsumption = totalEnergyConsumption;
91
- this.setCharacteristicValue(this.platform.eve.Characteristics.TotalConsumption, this.totalEnergyConsumption);
147
+ this.outletService.getCharacteristic(this.platform.eve.Characteristics.TotalConsumption).updateValue(this.totalEnergyConsumption);
92
148
  }
93
149
  /**
94
150
  * Gets the outlet state Characteristic based on its consumed power.
@@ -103,11 +159,7 @@ class SolaxOutletAccessory extends platformAccessory_1.SolaxPlatformAccessory {
103
159
  * It should return all services which should be added to the accessory.
104
160
  */
105
161
  getServices() {
106
- return [
107
- this.informationService,
108
- this.outletService,
109
- this.loggingService,
110
- ];
162
+ return [this.informationService, this.outletService, this.loggingService];
111
163
  }
112
164
  }
113
165
  exports.SolaxOutletAccessory = SolaxOutletAccessory;
@@ -1 +1 @@
1
- {"version":3,"file":"outletAccessory.js","sourceRoot":"","sources":["../src/outletAccessory.ts"],"names":[],"mappings":";;;AAGA,2DAA6D;AAI7D;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,0CAAsB;IAsB9D;;;;;;;OAOG;IACH,YAAY,QAA+B,EAAE,GAAY,EAAE,IAAY,EAAE,MAAc,EAAE,KAAa;QACpG,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAxB5C;;WAEG;QACK,qBAAgB,GAAG,CAAC,CAAC;QAE7B;;WAEG;QACK,2BAAsB,GAAG,GAAG,CAAC;QAkBnC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;QAElC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAEjD,6BAA6B;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,C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;QAE7G,gCAAgC;QAChC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,yBAAyB,CAAC,QAAmC;QAClE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,8BAA8B,IAAI,CAAC,sBAAsB,MAAM,CAAC,CAAC;QAE5F,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACI,yBAAyB,CAAC,sBAA8B;QAC7D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,8BAA8B,sBAAsB,MAAM,CAAC,CAAC;QAEvF,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;QAErD,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACpI,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,QAAmC;QACjD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,sBAAsB,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAE5E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,CAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,cAAc,CAAE,CAAC;IAC9E,CAAC;CAEF;AA5MD,oDA4MC"}
@@ -14,31 +14,34 @@ export declare class SolaxCloudAPIPlatform implements StaticPlatformPlugin {
14
14
  readonly eve: EveHomeKitTypes;
15
15
  eveService: fakegato;
16
16
  private readonly solaxCloudAPI;
17
- private apiData;
18
17
  /**
19
- * Virtual outlet used to detect and measure photovoltaic production.
20
- */
21
- private outletPV;
18
+ * Numeber of periods to use for data smoothing.
19
+ */
20
+ private smoothingWindow;
22
21
  /**
23
- * Virtual outlet used to detect and measure inverter AC production.
22
+ * Outlets with raw data gather.
24
23
  */
25
- private outletInverterAC;
24
+ private rawOutlets;
26
25
  /**
27
- * Virtual outlet used to detect and measure inverter excess production injected in the grid.
26
+ * Smooth data outlets.
27
+ * These outlets present smoothed values based on the raw data figures to
28
+ * prevent events like the temporary passage of a cloud to directly affect values.
28
29
  */
29
- private outletInverterToGrid;
30
+ private smoothOutlets;
30
31
  /**
31
- * Virtual outlet used to detect and measure inverter production directly fed into the house (self-consumption).
32
+ * Virtual motion sensor triggered by data updates from Solax Cloud.
32
33
  */
33
- private outletInverterToHouse;
34
+ private motionUpdate;
34
35
  /**
35
- * Virtual outlet used to detect and measure grid power fed into the house.
36
+ * Ambient light sensors for Power Consumption (pure Home App config)
36
37
  */
37
- private outletGridToHouse;
38
+ private rawLightSensors;
38
39
  /**
39
- * Virtual motion sensor triggered by data updates from Solax Cloud.
40
+ * Ambient light sensors for smooth power consumption lights.
41
+ * These lights present smoothed values based on the raw data figures to
42
+ * prevent events like the temporary passage of a cloud to directly affect values.
40
43
  */
41
- private motionUpdate;
44
+ private smoothLightSensors;
42
45
  /** Array with all accessories */
43
46
  private solaxAccessories;
44
47
  /**
@@ -54,6 +57,34 @@ export declare class SolaxCloudAPIPlatform implements StaticPlatformPlugin {
54
57
  * Periodically retrieves inverter data from Solax Cloud API using configured tokenID and SN.
55
58
  */
56
59
  private fetchDataPeriodically;
60
+ /**
61
+ * Update all platform accessory status based on the values read from the API.
62
+ * @param {SolaxCloudAPIResponse} apiData API data from Solax Cloud.
63
+ */
64
+ private updateAccessories;
65
+ /**
66
+ * Updates smooth ambient light sensors data from raw outlet data by applying configured smoothing function.
67
+ */
68
+ private updateSmoothLightSensors;
69
+ /**
70
+ * Update raw ambient light sensors with power consumption data from Solax Cloud API.
71
+ * @param {SolaxCloudAPIResponse} apiData API data retrieved from Solax Cloud.
72
+ */
73
+ private updateRawLightSensors;
74
+ /**
75
+ * Updates smooth outlet data from raw outlet data by applying configured smoothing function.
76
+ */
77
+ private updateSmoothOutlets;
78
+ /**
79
+ * Update raw outlet data from API data read from Solax Cloud.
80
+ * @param {SolaxCloudAPIResponse} apiData Solax Cloud API data.
81
+ * */
82
+ private updateRawOutlets;
83
+ /**
84
+ * Checks platform config validity and sets defaults whenever needed.
85
+ * @returns {boolean} Whether the config is valid.
86
+ */
87
+ private checkConfig;
57
88
  accessories(callback: (foundAccessories: AccessoryPlugin[]) => void): void;
58
89
  }
59
90
  //# sourceMappingURL=platform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,oBAAoB,EAAE,OAAO,EAAE,cAAc,EAAY,MAAM,YAAY,CAAC;AAE3G,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AA6BxC;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,oBAAoB;IAChE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,SAAgB,GAAG,EAAE,GAAG,CAAC;IAEzB,SAAgB,GAAG,EAAE,eAAe,CAAC;IAC9B,UAAU,EAAE,QAAQ,CAAC;IAE5B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,OAAO,CAAyB;IAExC;;MAEE;IACF,OAAO,CAAC,QAAQ,CAAwB;IAExC;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAwB;IAEhD;;OAEG;IACH,OAAO,CAAC,oBAAoB,CAAwB;IAEpD;;OAEG;IACH,OAAO,CAAC,qBAAqB,CAAwB;IAErD;;OAE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