homebridge-enphase-envoy 9.3.4-beta.8 → 9.3.4

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.
package/CHANGELOG.md CHANGED
@@ -5,12 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [9.3.4] - (xx.08.2024)
8
+ ## [9.3.4] - (27.08.2024)
9
9
 
10
10
  ## Changes
11
11
 
12
12
  - fix restFul data sampling response
13
13
  - fix duplicate start run afer error occur
14
+ - fix characteristic Rest Power warning
15
+ - increase axios timeout to 20sec
14
16
  - cleanup
15
17
 
16
18
  ## [9.3.3] - (23.08.2024)
package/index.js CHANGED
@@ -60,29 +60,25 @@ class EnvoyPlatform {
60
60
  };
61
61
  const debug1 = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(config, null, 2)}`) : false;
62
62
 
63
-
63
+ //define directory and file paths
64
+ const prefDir = path.join(api.user.storagePath(), 'enphaseEnvoy');
65
+ const postFix = host.split('.').join('');
66
+ const envoyIdFile = path.join(prefDir, `envoyId_${postFix}`);
67
+ const envoyTokenFile = path.join(prefDir, `envoyToken_${postFix}`);
68
+ const envoyInstallerPasswordFile = path.join(prefDir, `envoyInstallerPassword_${postFix}`);
69
+ const files = [envoyIdFile, envoyTokenFile, envoyInstallerPasswordFile];
64
70
  try {
65
- // Define directory and file paths
66
- const prefDir = path.join(api.user.storagePath(), 'enphaseEnvoy');
67
- const postFix = host.split('.').join('');
68
-
69
- const envoyIdFile = path.join(prefDir, `envoyId_${postFix}`);
70
- const envoyTokenFile = path.join(prefDir, `envoyToken_${postFix}`);
71
- const envoyInstallerPasswordFile = path.join(prefDir, `envoyInstallerPassword_${postFix}`);
72
-
73
- const files = [envoyIdFile, envoyTokenFile, envoyInstallerPasswordFile];
74
-
75
- // Create directory if it doesn't exist
71
+ //create directory if it doesn't exist
76
72
  fs.mkdirSync(prefDir, { recursive: true });
77
73
 
78
- // Create files if they don't exist
74
+ //create files if they don't exist
79
75
  files.forEach((file) => {
80
76
  if (!fs.existsSync(file)) {
81
77
  fs.writeFileSync(file, '0');
82
78
  }
83
79
  });
84
80
  } catch (error) {
85
- log.error(`Device: ${host} ${deviceName}, prepare files error: ${error.message ?? error}`);
81
+ log.error(`Device: ${host} ${deviceName}, prepare directory and files error: ${error.message ?? error}`);
86
82
  return;
87
83
  }
88
84
 
@@ -109,12 +105,16 @@ class EnvoyPlatform {
109
105
  log.warn(`Device: ${host} ${deviceName}, ${message}`);
110
106
  })
111
107
  .on('error', async (error) => {
112
- const errorString = JSON.stringify(error);
108
+ //stop impulse generator
109
+ envoyDevice.impulseGenerator.stop();
110
+
111
+ //handle error
112
+ const errorString = error.toString();
113
113
  const tokenNotValid = envoyFirmware7xx && errorString.includes('status code 401');
114
114
  const tokenExpired = envoyFirmware7xx && errorString.includes('JWT token expired');
115
115
  const displayError = tokenNotValid ? log.warn(`Device: ${host} ${deviceName}, JWT token not valid, refreshing.`) : tokenExpired ? log.warn(`Device: ${host} ${deviceName}, ${error}, refreshing.`) : log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
116
116
 
117
- //wait and try again
117
+ //wait and try connect again
118
118
  await new Promise(resolve => setTimeout(resolve, 20000));
119
119
  envoyDevice.start();
120
120
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "private": false,
3
3
  "displayName": "Enphase Envoy",
4
4
  "name": "homebridge-enphase-envoy",
5
- "version": "9.3.4-beta.8",
5
+ "version": "9.3.4",
6
6
  "description": "Homebridge plugin for Photovoltaic Energy System manufactured by Enphase.",
7
7
  "license": "MIT",
8
8
  "author": "grzegorz914",
@@ -767,7 +767,7 @@ class EnvoyDevice extends EventEmitter {
767
767
  tariff: {},
768
768
  dryContacts: [],
769
769
  generator: {},
770
- arfProfile: {},
770
+ arfProfile: {}
771
771
  };
772
772
 
773
773
  //url
@@ -781,7 +781,7 @@ class EnvoyDevice extends EventEmitter {
781
781
  headers: {
782
782
  Accept: 'application/json'
783
783
  },
784
- timeout: 15000
784
+ timeout: 20000
785
785
  });
786
786
 
787
787
  //RESTFul server
@@ -853,7 +853,6 @@ class EnvoyDevice extends EventEmitter {
853
853
  const updateHome = tokenExpired ? false : await this.updateHome();
854
854
  const updateInventory = updateHome ? await this.updateInventory() : false;
855
855
  } catch (error) {
856
- this.impulseGenerator.stop();
857
856
  this.emit('error', error);
858
857
  };
859
858
  }).on('updateMeters', async () => {
@@ -862,7 +861,6 @@ class EnvoyDevice extends EventEmitter {
862
861
  const updateMeters = tokenExpired ? false : await this.updateMeters();
863
862
  const updateMetersReading = updateMeters ? await this.updateMetersReading() : false;
864
863
  } catch (error) {
865
- this.impulseGenerator.stop();
866
864
  this.emit('error', error);
867
865
  };
868
866
  }).on('updateMicroinvertersStatus', async () => {
@@ -870,7 +868,6 @@ class EnvoyDevice extends EventEmitter {
870
868
  const tokenExpired = await this.checkJwtToken();
871
869
  const updateMicroinvertersStatus = tokenExpired ? false : await this.updateMicroinvertersStatus();
872
870
  } catch (error) {
873
- this.impulseGenerator.stop();
874
871
  this.emit('error', error);
875
872
  };
876
873
  }).on('updateProduction', async () => {
@@ -879,7 +876,6 @@ class EnvoyDevice extends EventEmitter {
879
876
  const updateProduction = tokenExpired ? false : await this.updateProduction();
880
877
  const updateProductionCt = updateProduction ? await this.updateProductionCt() : false;
881
878
  } catch (error) {
882
- this.impulseGenerator.stop();
883
879
  this.emit('error', error);
884
880
  };
885
881
  }).on('updateEnsemble', async () => {
@@ -894,7 +890,6 @@ class EnvoyDevice extends EventEmitter {
894
890
  const updateGenerator = updateEnsemble ? await this.updateGenerator() : false;
895
891
  const updateGeneratorSettings = updateGenerator ? await this.updateGeneratorSettings() : false;
896
892
  } catch (error) {
897
- this.impulseGenerator.stop();
898
893
  this.emit('error', error);
899
894
  };
900
895
  }).on('updateLiveData', async () => {
@@ -902,7 +897,6 @@ class EnvoyDevice extends EventEmitter {
902
897
  const tokenExpired = await this.checkJwtToken();
903
898
  const updateLiveData = tokenExpired ? false : await this.updateLiveData();
904
899
  } catch (error) {
905
- this.impulseGenerator.stop();
906
900
  this.emit('error', error);
907
901
  };
908
902
  }).on('state', (state) => {
@@ -959,7 +953,7 @@ class EnvoyDevice extends EventEmitter {
959
953
  const validJwtToken = getJwtToken ? await this.validateJwtToken() : false;
960
954
 
961
955
  //update grid profile
962
- const updateGridProfileData = await this.updateGridProfile();
956
+ await this.updateGridProfile();
963
957
 
964
958
  //get envoy dev id
965
959
  const envoyDevIdExist = this.supportPowerProductionState ? await this.getEnvoyBackboneApp() : false;
@@ -972,7 +966,7 @@ class EnvoyDevice extends EventEmitter {
972
966
  const calculateInstallerPassword = !this.envoyFirmware7xx && updateInfo ? await this.calculateInstallerPassword() : false;
973
967
 
974
968
  //get home and inventory
975
- const updateHome = await this.updateHome();
969
+ const updateHome = updateInfo ? await this.updateHome() : false;
976
970
  const updateInventory = updateHome ? await this.updateInventory() : false;
977
971
 
978
972
  //get meters
@@ -1021,7 +1015,6 @@ class EnvoyDevice extends EventEmitter {
1021
1015
  const pushTimer5 = updateLiveData ? this.timers.push({ name: 'updateLiveData', sampling: this.liveDataRefreshTime }) : false;
1022
1016
  this.impulseGenerator.start(this.timers);
1023
1017
  } catch (error) {
1024
- this.impulseGenerator.stop();
1025
1018
  this.emit('error', error);
1026
1019
  };
1027
1020
  };
@@ -1087,7 +1080,7 @@ class EnvoyDevice extends EventEmitter {
1087
1080
  keepAlive: false,
1088
1081
  rejectUnauthorized: false
1089
1082
  }),
1090
- timeout: 15000
1083
+ timeout: 20000
1091
1084
  });
1092
1085
 
1093
1086
  const response = await axiosInstanceToken(CONSTANTS.ApiUrls.CheckJwt);
@@ -1107,7 +1100,7 @@ class EnvoyDevice extends EventEmitter {
1107
1100
  keepAlive: false,
1108
1101
  rejectUnauthorized: false
1109
1102
  }),
1110
- timeout: 15000
1103
+ timeout: 20000
1111
1104
  });
1112
1105
 
1113
1106
  this.cookie = cookie;
@@ -1801,8 +1794,8 @@ class EnvoyDevice extends EventEmitter {
1801
1794
  const debug = this.enableDebugMode ? this.emit('debug', `Meters:`, meters) : false;
1802
1795
 
1803
1796
  //meters count
1804
- const metersSupported = meters.length > 0;
1805
- if (metersSupported) {
1797
+ const metersExist = meters.length > 0;
1798
+ if (metersExist) {
1806
1799
 
1807
1800
  //meters
1808
1801
  this.pv.meters = [];
@@ -1860,9 +1853,6 @@ class EnvoyDevice extends EventEmitter {
1860
1853
  this.feature.meters.count = meters.length;
1861
1854
  }
1862
1855
 
1863
- //meters supported
1864
- this.feature.meters.supported = metersSupported;
1865
-
1866
1856
  //meters enabled
1867
1857
  const metersEnabled = this.pv.meters.some(meter => meter.state);
1868
1858
 
@@ -2081,7 +2071,6 @@ class EnvoyDevice extends EventEmitter {
2081
2071
  //add to pv object
2082
2072
  this.pv.production.ct.inverters = inverters;
2083
2073
  }
2084
-
2085
2074
  //production inverters supported
2086
2075
  this.feature.production.ct.inverters.supported = productionCtInvertersSupported
2087
2076
 
@@ -2214,7 +2203,6 @@ class EnvoyDevice extends EventEmitter {
2214
2203
  }
2215
2204
  }
2216
2205
  }
2217
-
2218
2206
  //production ct production supported
2219
2207
  this.feature.production.ct.production.supported = productionCtProductionSupported;
2220
2208
  }
@@ -2410,15 +2398,14 @@ class EnvoyDevice extends EventEmitter {
2410
2398
  }
2411
2399
  })
2412
2400
  };
2413
-
2414
- //consumption suppered
2401
+ //consumption supported
2415
2402
  this.feature.production.ct.consumption.supported = productionCtConsumptionSupported
2416
2403
 
2417
2404
  //ac btteries summary 3
2418
2405
  this.pv.production.ct.acBatterie = {};
2419
- const storageExist = productionCtKeys.includes('storage');
2420
- const acBatteriesSupported = storageExist && Array.isArray(productionCtData.storage);
2421
- if (acBatteriesSupported && acBatteriesInstalled) {
2406
+ const productionCtAcBatterieExist = productionCtKeys.includes('storage');
2407
+ const productionCtAcBatterieSupported = productionCtAcBatterieExist && Array.isArray(productionCtData.storage);
2408
+ if (productionCtAcBatterieSupported && acBatteriesInstalled) {
2422
2409
  const acBatteries = productionCtData.storage[0] ?? {};
2423
2410
  const acBatterie = {
2424
2411
  type: CONSTANTS.ApiCodes[acBatteries.type] ?? 'AC Batterie',
@@ -2452,9 +2439,8 @@ class EnvoyDevice extends EventEmitter {
2452
2439
  .updateCharacteristic(Characteristic.enphaseAcBatterieSummaryState, acBatterie.chargeStatus);
2453
2440
  }
2454
2441
  };
2455
-
2456
- //production ct supported
2457
- this.feature.production.ct.acBatterie.supported = acBatteriesSupported;
2442
+ //ac batterie supported
2443
+ this.feature.production.ct.acBatterie.supported = productionCtAcBatterieSupported;
2458
2444
 
2459
2445
  //restFul
2460
2446
  const restFul = this.restFulConnected ? this.restFul.update('productionct', productionCtData) : false;
@@ -2882,8 +2868,8 @@ class EnvoyDevice extends EventEmitter {
2882
2868
  restRelayGet: counterData.rest_RelayGet ?? 0,
2883
2869
  restRelayPost: counterData.rest_RelayPost ?? 0,
2884
2870
  restCommCheckGet: counterData.rest_CommCheckGet ?? 0,
2885
- restPower: counterData.rest_Power ?? 0,
2886
- restPowerKw: counterData.rest_Power / 1000 ?? 0, //in kW
2871
+ restPower: counterData.rest_Power === 'number' && counterData.rest_Power > 0 ? counterData.rest_Power : 0,
2872
+ restPowerKw: counterData.rest_Power === 'number' && counterData.rest_Power > 0 ? counterData.rest_Power / 1000 : 0, //in kW
2887
2873
  extZbRemove: counterData.ext_zb_remove ?? 0,
2888
2874
  extZbRemoveErr: counterData.ext_zb_remove_err ?? 0,
2889
2875
  extZbSendMsg: counterData.ext_zb_send_msg ?? 0,
@@ -4203,11 +4189,11 @@ class EnvoyDevice extends EventEmitter {
4203
4189
  this.emit('devInfo', `Inverters: ${this.feature.microinverters.count}`);
4204
4190
  const displayLog12 = this.feature.acBatteries.installed ? this.emit('devInfo', `AC Batteries: ${this.feature.acBatteries.count}`) : false;
4205
4191
  this.emit('devInfo', `--------------------------------`);
4206
- const displayLog0 = this.feature.meters.supported ? this.emit('devInfo', `Meters: Yes`) : false;
4207
- const displayLog1 = this.feature.meters.supported && this.feature.meters.production.supported ? this.emit('devInfo', `Production: ${this.feature.meters.production.enabled ? `Enabled` : `Disabled`}`) : false;
4208
- const displayLog2 = this.feature.meters.supported && this.feature.meters.consumption.supported ? this.emit('devInfo', `Consumption: ${this.feature.meters.consumption.enabled ? `Enabled` : `Disabled`}`) : false;
4209
- const displayLog3 = this.feature.meters.supported && this.feature.meters.acBatterie.supported ? this.emit('devInfo', `Storage: ${this.feature.meters.acBatterie.enabled ? `Enabled` : `Disabled`}`) : false;
4210
- const displayLog4 = this.feature.meters.supported ? this.emit('devInfo', `--------------------------------`) : false;
4192
+ const displayLog0 = this.feature.meters.installed ? this.emit('devInfo', `Meters: Yes`) : false;
4193
+ const displayLog1 = this.feature.meters.installed && this.feature.meters.production.supported ? this.emit('devInfo', `Production: ${this.feature.meters.production.enabled ? `Enabled` : `Disabled`}`) : false;
4194
+ const displayLog2 = this.feature.meters.installed && this.feature.meters.consumption.supported ? this.emit('devInfo', `Consumption: ${this.feature.meters.consumption.enabled ? `Enabled` : `Disabled`}`) : false;
4195
+ const displayLog3 = this.feature.meters.installed && this.feature.meters.acBatterie.supported ? this.emit('devInfo', `Storage: ${this.feature.meters.acBatterie.enabled ? `Enabled` : `Disabled`}`) : false;
4196
+ const displayLog4 = this.feature.meters.installed ? this.emit('devInfo', `--------------------------------`) : false;
4211
4197
  const displayLog5 = this.feature.ensembles.installed ? this.emit('devInfo', `Ensemble: Yes`) : false;
4212
4198
  const displayLog6 = this.feature.enpowers.installed ? this.emit('devInfo', `Enpowers: ${this.feature.enpowers.count}`) : false;
4213
4199
  const displayLog7 = this.feature.encharges.installed ? this.emit('devInfo', `Encharges: ${this.feature.encharges.count}`) : false;
@@ -4228,17 +4214,13 @@ class EnvoyDevice extends EventEmitter {
4228
4214
  const microinvertersStatusSupported = this.feature.microinverters.status.supported;
4229
4215
  const qRelaysInstalled = this.feature.qRelays.installed;
4230
4216
  const acBatteriesInstalled = this.feature.acBatteries.installed;
4231
- const metersSupported = this.feature.meters.supported;
4232
4217
  const metersInstalled = this.feature.meters.installed;
4233
4218
  const metersProductionEnabled = this.feature.meters.production.enabled;
4234
4219
  const metersConsumptionEnabled = this.feature.meters.consumption.enabled;
4235
- const productionMicroinvertersSupported = this.feature.production.microinverters.supported
4236
- const productionCtInvertersSupported = this.feature.production.ct.inverters.supported;
4237
4220
  const productionCtProductionSupported = this.feature.production.ct.production.supported;
4238
4221
  const productionCtConsumptionSupported = this.feature.production.ct.consumption.supported;
4239
- const productionCtStorageSupported = this.feature.production.ct.acBatterie.supported
4222
+ const productionCtAcBatterieSupported = this.feature.production.ct.acBatterie.supported
4240
4223
  const powerProductionStateSupported = this.feature.powerProductionState.supported;
4241
- const ensemblesInventorySupported = this.feature.ensembles.inventory.supported;
4242
4224
  const ensemblesInventoryInstalled = this.feature.ensembles.inventory.installed;
4243
4225
  const ensemblesInstalled = this.feature.ensembles.installed;
4244
4226
  const ensemblesSupported = this.feature.ensembles.supported;
@@ -4266,7 +4248,7 @@ class EnvoyDevice extends EventEmitter {
4266
4248
  .setCharacteristic(Characteristic.SerialNumber, this.pv.envoy.serialNumber ?? 'Serial Number')
4267
4249
  .setCharacteristic(Characteristic.FirmwareRevision, this.pv.envoy.software.replace(/[a-zA-Z]/g, '') ?? '0');
4268
4250
 
4269
- //system service
4251
+ //system and envoy
4270
4252
  if (envoyInstalled) {
4271
4253
  const serialNumber = this.pv.envoy.serialNumber;
4272
4254
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare System Service`) : false;
@@ -4647,7 +4629,7 @@ class EnvoyDevice extends EventEmitter {
4647
4629
  this.wirelessConnektionsKitServices.push(enphaseWirelessConnectionKitService);
4648
4630
  }
4649
4631
  }
4650
- }
4632
+ };
4651
4633
 
4652
4634
  //microinverters
4653
4635
  if (microinvertersInstalled) {
@@ -4731,7 +4713,7 @@ class EnvoyDevice extends EventEmitter {
4731
4713
  };
4732
4714
  this.microinvertersServices.push(enphaseMicroinverterService);
4733
4715
  }
4734
- }
4716
+ };
4735
4717
 
4736
4718
  //qrelays
4737
4719
  if (qRelaysInstalled) {
@@ -4837,76 +4819,80 @@ class EnvoyDevice extends EventEmitter {
4837
4819
  }
4838
4820
  this.qRelaysServices.push(enphaseQrelayService);
4839
4821
  }
4840
- }
4822
+ };
4841
4823
 
4842
4824
  //ac batteries
4843
4825
  if (acBatteriesInstalled) {
4844
- //ac batteries summary level and state
4845
- const debug2 = this.enableDebugMode ? this.emit('debug', `Prepare AC Batteries Summary Service`) : false;
4846
- this.enphaseAcBatterieSummaryLevelAndStateService = accessory.addService(Service.Lightbulb, `AC Batteries`, `enphaseAcBatterieSummaryLevelAndStateService`);
4847
- this.enphaseAcBatterieSummaryLevelAndStateService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4848
- this.enphaseAcBatterieSummaryLevelAndStateService.setCharacteristic(Characteristic.ConfiguredName, `AC Batteries`);
4849
- this.enphaseAcBatterieSummaryLevelAndStateService.getCharacteristic(Characteristic.On)
4850
- .onGet(async () => {
4851
- const state = this.pv.production.ct.acBatterie.energyState;
4852
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries energy state: ${state ? 'Charged' : 'Discharged'}`);
4853
- return state;
4854
- })
4855
- .onSet(async (state) => {
4856
- this.enphaseAcBatterieSummaryLevelAndStateService.updateCharacteristic(Characteristic.On, this.pv.production.ct.acBatterie.energyState);
4857
- })
4858
- this.enphaseAcBatterieSummaryLevelAndStateService.getCharacteristic(Characteristic.Brightness)
4859
- .onGet(async () => {
4860
- const state = this.pv.production.ct.acBatterie.percentFull;
4861
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries energy level: ${this.pv.production.ct.acBatterie.percentFull} %`);
4862
- return state;
4863
- })
4864
- .onSet(async (value) => {
4865
- this.enphaseAcBatterieSummaryLevelAndStateService.updateCharacteristic(Characteristic.Brightness, this.pv.production.ct.acBatterie.percentFull);
4866
- })
4826
+ //ac batteries summary
4827
+ if (productionCtAcBatterieSupported) {
4828
+ //ac batteries summary level and state
4829
+ const debug2 = this.enableDebugMode ? this.emit('debug', `Prepare AC Batteries Summary Service`) : false;
4830
+ this.enphaseAcBatterieSummaryLevelAndStateService = accessory.addService(Service.Lightbulb, `AC Batteries`, `enphaseAcBatterieSummaryLevelAndStateService`);
4831
+ this.enphaseAcBatterieSummaryLevelAndStateService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4832
+ this.enphaseAcBatterieSummaryLevelAndStateService.setCharacteristic(Characteristic.ConfiguredName, `AC Batteries`);
4833
+ this.enphaseAcBatterieSummaryLevelAndStateService.getCharacteristic(Characteristic.On)
4834
+ .onGet(async () => {
4835
+ const state = this.pv.production.ct.acBatterie.energyState;
4836
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries energy state: ${state ? 'Charged' : 'Discharged'}`);
4837
+ return state;
4838
+ })
4839
+ .onSet(async (state) => {
4840
+ this.enphaseAcBatterieSummaryLevelAndStateService.updateCharacteristic(Characteristic.On, this.pv.production.ct.acBatterie.energyState);
4841
+ })
4842
+ this.enphaseAcBatterieSummaryLevelAndStateService.getCharacteristic(Characteristic.Brightness)
4843
+ .onGet(async () => {
4844
+ const state = this.pv.production.ct.acBatterie.percentFull;
4845
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries energy level: ${this.pv.production.ct.acBatterie.percentFull} %`);
4846
+ return state;
4847
+ })
4848
+ .onSet(async (value) => {
4849
+ this.enphaseAcBatterieSummaryLevelAndStateService.updateCharacteristic(Characteristic.Brightness, this.pv.production.ct.acBatterie.percentFull);
4850
+ })
4867
4851
 
4868
- //ac batteries summary service
4869
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare AC Batteries Summary Service`) : false;
4870
- this.acBatterieSummaryService = accessory.addService(Service.enphaseAcBatterieSummaryService, 'AC Batteries Summary', 'enphaseAcBatterieSummaryService');
4871
- this.acBatterieSummaryService.setCharacteristic(Characteristic.ConfiguredName, `AC Batteries Summary`);
4872
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryPower)
4873
- .onGet(async () => {
4874
- const value = this.pv.production.ct.acBatterie.powerKw;
4875
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries acBatterie power: ${value} kW`);
4876
- return value;
4877
- });
4878
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryEnergy)
4879
- .onGet(async () => {
4880
- const value = this.pv.production.ct.acBatterie.energyKw;
4881
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries acBatterie energy: ${value} kWh`);
4882
- return value;
4883
- });
4884
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryPercentFull)
4885
- .onGet(async () => {
4886
- const value = this.pv.production.ct.acBatterie.percentFull;
4887
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries percent full: ${value}`);
4888
- return value;
4889
- });
4890
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryActiveCount)
4891
- .onGet(async () => {
4892
- const value = this.pv.production.ct.acBatterie.activeCount;
4893
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries devices count: ${value}`);
4894
- return value;
4895
- });
4896
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryState)
4897
- .onGet(async () => {
4898
- const value = this.pv.production.ct.acBatterie.state;
4899
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries charge status: ${value}`);
4900
- return value;
4901
- });
4902
- this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryReadingTime)
4903
- .onGet(async () => {
4904
- const value = this.pv.production.ct.acBatterie.readingTime;
4905
- const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries last report: ${value}`);
4906
- return value;
4907
- });
4908
4852
 
4909
- //ac batteries state
4853
+ //ac batteries summary service
4854
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare AC Batteries Summary Service`) : false;
4855
+ this.acBatterieSummaryService = accessory.addService(Service.enphaseAcBatterieSummaryService, 'AC Batteries Summary', 'enphaseAcBatterieSummaryService');
4856
+ this.acBatterieSummaryService.setCharacteristic(Characteristic.ConfiguredName, `AC Batteries Summary`);
4857
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryPower)
4858
+ .onGet(async () => {
4859
+ const value = this.pv.production.ct.acBatterie.powerKw;
4860
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries acBatterie power: ${value} kW`);
4861
+ return value;
4862
+ });
4863
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryEnergy)
4864
+ .onGet(async () => {
4865
+ const value = this.pv.production.ct.acBatterie.energyKw;
4866
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries acBatterie energy: ${value} kWh`);
4867
+ return value;
4868
+ });
4869
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryPercentFull)
4870
+ .onGet(async () => {
4871
+ const value = this.pv.production.ct.acBatterie.percentFull;
4872
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries percent full: ${value}`);
4873
+ return value;
4874
+ });
4875
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryActiveCount)
4876
+ .onGet(async () => {
4877
+ const value = this.pv.production.ct.acBatterie.activeCount;
4878
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries devices count: ${value}`);
4879
+ return value;
4880
+ });
4881
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryState)
4882
+ .onGet(async () => {
4883
+ const value = this.pv.production.ct.acBatterie.state;
4884
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries charge status: ${value}`);
4885
+ return value;
4886
+ });
4887
+ this.acBatterieSummaryService.getCharacteristic(Characteristic.enphaseAcBatterieSummaryReadingTime)
4888
+ .onGet(async () => {
4889
+ const value = this.pv.production.ct.acBatterie.readingTime;
4890
+ const info = this.disableLogInfo ? false : this.emit('message', `AC Batteries last report: ${value}`);
4891
+ return value;
4892
+ });
4893
+ };
4894
+
4895
+ //indyvidual ac batterie state
4910
4896
  this.acBatteriesServices = [];
4911
4897
  for (const acBatterie of this.pv.acBatteries.devices) {
4912
4898
  const serialNumber = acBatterie.serialNumber;
@@ -5001,10 +4987,10 @@ class EnvoyDevice extends EventEmitter {
5001
4987
  });
5002
4988
  this.acBatteriesServices.push(enphaseAcBatterieService);
5003
4989
  }
5004
- }
4990
+ };
5005
4991
 
5006
4992
  //meters
5007
- if (metersSupported) {
4993
+ if (metersInstalled) {
5008
4994
  this.metersServices = [];
5009
4995
  for (const meter of this.pv.meters) {
5010
4996
  const measurementType = meter.measurementType;
@@ -5093,188 +5079,190 @@ class EnvoyDevice extends EventEmitter {
5093
5079
  }
5094
5080
  this.metersServices.push(enphaseMeterService);
5095
5081
  };
5096
- }
5082
+ };
5097
5083
 
5098
5084
  //production
5099
- const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Production Power And Energy Service`) : false;
5100
- this.productionsService = accessory.addService(Service.enphasePowerAndEnergyService, `Production Power And Energy`, 'enphaseProductionService');
5101
- this.productionsService.setCharacteristic(Characteristic.ConfiguredName, `Production Power And Energy`);
5102
- this.productionsService.getCharacteristic(Characteristic.enphasePower)
5103
- .onGet(async () => {
5104
- const value = this.pv.production.ct.production.powerKw;
5105
- const info = this.disableLogInfo ? false : this.emit('message', `Production power: ${value} kW`);
5106
- return value;
5107
- });
5108
- this.productionsService.getCharacteristic(Characteristic.enphasePowerMax)
5109
- .onGet(async () => {
5110
- const value = this.pv.production.ct.production.powerPeakKw;
5111
- const info = this.disableLogInfo ? false : this.emit('message', `Production power peak: ${value} kW`);
5112
- return value;
5113
- });
5114
- this.productionsService.getCharacteristic(Characteristic.enphasePowerMaxDetected)
5115
- .onGet(async () => {
5116
- const value = this.pv.production.ct.production.powerPeakDetected;
5117
- const info = this.disableLogInfo ? false : this.emit('message', `Production power peak detected: ${value ? 'Yes' : 'No'}`);
5118
- return value;
5119
- });
5120
- this.productionsService.getCharacteristic(Characteristic.enphaseEnergyToday)
5121
- .onGet(async () => {
5122
- const value = this.pv.production.ct.production.energyTodayKw;
5123
- const info = this.disableLogInfo ? false : this.emit('message', `Production energy today: ${value} kWh`);
5124
- return value;
5125
- });
5126
- this.productionsService.getCharacteristic(Characteristic.enphaseEnergyLastSevenDays)
5127
- .onGet(async () => {
5128
- const value = this.pv.production.ct.production.energyLastSevenDaysKw;
5129
- const info = this.disableLogInfo ? false : this.emit('message', `Production energy last seven days: ${value} kWh`);
5130
- return value;
5131
- });
5132
- this.productionsService.getCharacteristic(Characteristic.enphaseEnergyLifeTime)
5133
- .onGet(async () => {
5134
- const value = this.pv.production.ct.production.energyLifeTimeKw;
5135
- const info = this.disableLogInfo ? false : this.emit('message', `Production energy lifetime: ${value} kWh`);
5136
- return value;
5137
- });
5138
- if (metersSupported && metersProductionEnabled) {
5139
- this.productionsService.getCharacteristic(Characteristic.enphaseRmsCurrent)
5085
+ if (productionCtProductionSupported) {
5086
+ const debug4 = this.enableDebugMode ? this.emit('debug', `Prepare Production Power And Energy Service`) : false;
5087
+ this.productionsService = accessory.addService(Service.enphasePowerAndEnergyService, `Production Power And Energy`, 'enphaseProductionService');
5088
+ this.productionsService.setCharacteristic(Characteristic.ConfiguredName, `Production Power And Energy`);
5089
+ this.productionsService.getCharacteristic(Characteristic.enphasePower)
5140
5090
  .onGet(async () => {
5141
- const value = this.pv.production.ct.production.rmsCurrent;
5142
- const info = this.disableLogInfo ? false : this.emit('message', `Production current: ${value} A`);
5091
+ const value = this.pv.production.ct.production.powerKw;
5092
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power: ${value} kW`);
5143
5093
  return value;
5144
5094
  });
5145
- this.productionsService.getCharacteristic(Characteristic.enphaseRmsVoltage)
5095
+ this.productionsService.getCharacteristic(Characteristic.enphasePowerMax)
5146
5096
  .onGet(async () => {
5147
- const value = this.pv.production.ct.production.rmsVoltage;
5148
- const info = this.disableLogInfo ? false : this.emit('message', `Production voltage: ${value} V`);
5097
+ const value = this.pv.production.ct.production.powerPeakKw;
5098
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power peak: ${value} kW`);
5149
5099
  return value;
5150
5100
  });
5151
- this.productionsService.getCharacteristic(Characteristic.enphaseReactivePower)
5101
+ this.productionsService.getCharacteristic(Characteristic.enphasePowerMaxDetected)
5152
5102
  .onGet(async () => {
5153
- const value = this.pv.production.ct.production.reactivePower;
5154
- const info = this.disableLogInfo ? false : this.emit('message', `Production net reactive power: ${value} kVAr`);
5103
+ const value = this.pv.production.ct.production.powerPeakDetected;
5104
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power peak detected: ${value ? 'Yes' : 'No'}`);
5155
5105
  return value;
5156
5106
  });
5157
- this.productionsService.getCharacteristic(Characteristic.enphaseApparentPower)
5107
+ this.productionsService.getCharacteristic(Characteristic.enphaseEnergyToday)
5158
5108
  .onGet(async () => {
5159
- const value = this.pv.production.ct.production.apparentPower;
5160
- const info = this.disableLogInfo ? false : this.emit('message', `Production net apparent power: ${value} kVA`);
5109
+ const value = this.pv.production.ct.production.energyTodayKw;
5110
+ const info = this.disableLogInfo ? false : this.emit('message', `Production energy today: ${value} kWh`);
5161
5111
  return value;
5162
5112
  });
5163
- this.productionsService.getCharacteristic(Characteristic.enphasePwrFactor)
5113
+ this.productionsService.getCharacteristic(Characteristic.enphaseEnergyLastSevenDays)
5164
5114
  .onGet(async () => {
5165
- const value = this.pv.production.ct.production.pwrFactor;
5166
- const info = this.disableLogInfo ? false : this.emit('message', `Production power factor: ${value} cos φ`);
5115
+ const value = this.pv.production.ct.production.energyLastSevenDaysKw;
5116
+ const info = this.disableLogInfo ? false : this.emit('message', `Production energy last seven days: ${value} kWh`);
5167
5117
  return value;
5168
5118
  });
5169
- }
5170
- this.productionsService.getCharacteristic(Characteristic.enphaseReadingTime)
5171
- .onGet(async () => {
5172
- const value = this.pv.production.ct.production.readingTime;
5173
- const info = this.disableLogInfo ? false : this.emit('message', `Production last report: ${value}`);
5174
- return value;
5175
- });
5176
- this.productionsService.getCharacteristic(Characteristic.enphasePowerMaxReset)
5177
- .onGet(async () => {
5178
- const state = false;
5179
- const info = this.disableLogInfo ? false : this.emit('message', `Production power peak reset: Off`);
5180
- return state;
5181
- })
5182
- .onSet(async (state) => {
5183
- try {
5184
- const set = state ? this.pv.productionPowerPeak = 0 : false;
5185
- const info = this.disableLogInfo ? false : this.emit('message', `Production power peak reset: On`);
5186
- this.productionsService.updateCharacteristic(Characteristic.enphasePowerMaxReset, false);
5187
- } catch (error) {
5188
- this.emit('warn', `Production Power Peak reset error: ${error}`);
5189
- };
5190
- });
5191
-
5192
- //production state sensor service
5193
- if (this.powerProductionStateActiveSensorsCount > 0) {
5194
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Power State Sensor Service`) : false;
5195
- this.powerProductionStateSensorsServices = [];
5196
- for (let i = 0; i < this.powerProductionStateActiveSensorsCount; i++) {
5197
- const sensorName = this.powerProductionStateActiveSensors[i].namePrefix ? `${accessoryName} ${this.powerProductionStateActiveSensors[i].name}` : this.powerProductionStateActiveSensors[i].name;
5198
- const serviceType = this.powerProductionStateActiveSensors[i].serviceType;
5199
- const characteristicType = this.powerProductionStateActiveSensors[i].characteristicType;
5200
- const powerProductionStateSensorService = accessory.addService(serviceType, sensorName, `powerProductionStateSensorService${i}`);
5201
- powerProductionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5202
- powerProductionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5203
- powerProductionStateSensorService.getCharacteristic(characteristicType)
5119
+ this.productionsService.getCharacteristic(Characteristic.enphaseEnergyLifeTime)
5120
+ .onGet(async () => {
5121
+ const value = this.pv.production.ct.production.energyLifeTimeKw;
5122
+ const info = this.disableLogInfo ? false : this.emit('message', `Production energy lifetime: ${value} kWh`);
5123
+ return value;
5124
+ });
5125
+ if (metersInstalled && metersProductionEnabled) {
5126
+ this.productionsService.getCharacteristic(Characteristic.enphaseRmsCurrent)
5204
5127
  .onGet(async () => {
5205
- const state = this.powerProductionStateActiveSensors[i].state;
5206
- const info = this.disableLogInfo ? false : this.emit('message', `Production power state sensor: ${state ? 'Active' : 'Not active'}`);
5207
- return state;
5128
+ const value = this.pv.production.ct.production.rmsCurrent;
5129
+ const info = this.disableLogInfo ? false : this.emit('message', `Production current: ${value} A`);
5130
+ return value;
5208
5131
  });
5209
- this.powerProductionStateSensorsServices.push(powerProductionStateSensorService);
5210
- };
5211
- };
5212
-
5213
- //production power level sensors service
5214
- if (this.powerProductionLevelActiveSensorsCount > 0) {
5215
- this.powerProductionLevelSensorsServices = [];
5216
- for (let i = 0; i < this.powerProductionLevelActiveSensorsCount; i++) {
5217
- const sensorName = this.powerProductionLevelActiveSensors[i].namePrefix ? `${accessoryName} ${this.powerProductionLevelActiveSensors[i].name}` : this.powerProductionLevelActiveSensors[i].name;
5218
- const serviceType = this.powerProductionLevelActiveSensors[i].serviceType;
5219
- const characteristicType = this.powerProductionLevelActiveSensors[i].characteristicType;
5220
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Power Level ${sensorName} Sensor Service`) : false;
5221
- const powerProductionLevelSensorsService = accessory.addService(serviceType, sensorName, `powerProductionLevelSensorsService${i}`);
5222
- powerProductionLevelSensorsService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5223
- powerProductionLevelSensorsService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5224
- powerProductionLevelSensorsService.getCharacteristic(characteristicType)
5132
+ this.productionsService.getCharacteristic(Characteristic.enphaseRmsVoltage)
5225
5133
  .onGet(async () => {
5226
- const state = this.powerProductionLevelActiveSensors[i].state;
5227
- const info = this.disableLogInfo ? false : this.emit('message', `Production power level sensor: ${sensorName}: ${state ? 'Active' : 'Not active'}`);
5228
- return state;
5134
+ const value = this.pv.production.ct.production.rmsVoltage;
5135
+ const info = this.disableLogInfo ? false : this.emit('message', `Production voltage: ${value} V`);
5136
+ return value;
5229
5137
  });
5230
- this.powerProductionLevelSensorsServices.push(powerProductionLevelSensorsService);
5231
- };
5232
- };
5233
-
5234
- //production energy state sensor service
5235
- if (this.energyProductionStateActiveSensorsCount > 0) {
5236
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Energy State Sensor Service`) : false;
5237
- this.energyProductionStateSensorsServices = [];
5238
- for (let i = 0; i < this.energyProductionStateActiveSensorsCount; i++) {
5239
- const sensorName = this.energyProductionStateActiveSensors[i].namePrefix ? `${accessoryName} ${this.energyProductionStateActiveSensors[i].name}` : this.energyProductionStateActiveSensors[i].name;
5240
- const serviceType = this.energyProductionStateActiveSensors[i].serviceType;
5241
- const characteristicType = this.energyProductionStateActiveSensors[i].characteristicType;
5242
- const energyProductionStateSensorService = accessory.addService(serviceType, sensorName, `energyProductionStateSensorService${i}`);
5243
- energyProductionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5244
- energyProductionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5245
- energyProductionStateSensorService.getCharacteristic(characteristicType)
5138
+ this.productionsService.getCharacteristic(Characteristic.enphaseReactivePower)
5246
5139
  .onGet(async () => {
5247
- const state = this.energyProductionStateActiveSensors[i].state;
5248
- const info = this.disableLogInfo ? false : this.emit('message', `Production energy state sensor: ${state ? 'Active' : 'Not active'}`);
5249
- return state;
5140
+ const value = this.pv.production.ct.production.reactivePower;
5141
+ const info = this.disableLogInfo ? false : this.emit('message', `Production net reactive power: ${value} kVAr`);
5142
+ return value;
5250
5143
  });
5251
- this.energyProductionStateSensorsServices.push(energyProductionStateSensorService);
5252
- };
5253
- };
5254
-
5255
- //production energy level sensor service
5256
- if (this.energyProductionLevelActiveSensorsCount > 0) {
5257
- this.energyProductionLevelSensorsServices = [];
5258
- for (let i = 0; i < this.energyProductionLevelActiveSensorsCount; i++) {
5259
- const sensorName = this.energyProductionLevelActiveSensors[i].namePrefix ? `${accessoryName} ${this.energyProductionLevelActiveSensors[i].name}` : this.energyProductionLevelActiveSensors[i].name;
5260
- const serviceType = this.energyProductionLevelActiveSensors[i].serviceType;
5261
- const characteristicType = this.energyProductionLevelActiveSensors[i].characteristicType;
5262
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Energy Level ${sensorName} Sensor Service`) : false;
5263
- const energyProductionLevelSensorsService = accessory.addService(serviceType, sensorName, `energyProductionLevelSensorsService${i}`);
5264
- energyProductionLevelSensorsService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5265
- energyProductionLevelSensorsService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5266
- energyProductionLevelSensorsService.getCharacteristic(characteristicType)
5144
+ this.productionsService.getCharacteristic(Characteristic.enphaseApparentPower)
5267
5145
  .onGet(async () => {
5268
- const state = this.energyProductionLevelActiveSensors[i].state;
5269
- const info = this.disableLogInfo ? false : this.emit('message', `Production energy level sensor: ${sensorName}: ${state ? 'Active' : 'Not active'}`);
5270
- return state;
5146
+ const value = this.pv.production.ct.production.apparentPower;
5147
+ const info = this.disableLogInfo ? false : this.emit('message', `Production net apparent power: ${value} kVA`);
5148
+ return value;
5149
+ });
5150
+ this.productionsService.getCharacteristic(Characteristic.enphasePwrFactor)
5151
+ .onGet(async () => {
5152
+ const value = this.pv.production.ct.production.pwrFactor;
5153
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power factor: ${value} cos φ`);
5154
+ return value;
5271
5155
  });
5272
- this.energyProductionLevelSensorsServices.push(energyProductionLevelSensorsService);
5156
+ }
5157
+ this.productionsService.getCharacteristic(Characteristic.enphaseReadingTime)
5158
+ .onGet(async () => {
5159
+ const value = this.pv.production.ct.production.readingTime;
5160
+ const info = this.disableLogInfo ? false : this.emit('message', `Production last report: ${value}`);
5161
+ return value;
5162
+ });
5163
+ this.productionsService.getCharacteristic(Characteristic.enphasePowerMaxReset)
5164
+ .onGet(async () => {
5165
+ const state = false;
5166
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power peak reset: Off`);
5167
+ return state;
5168
+ })
5169
+ .onSet(async (state) => {
5170
+ try {
5171
+ const set = state ? this.pv.productionPowerPeak = 0 : false;
5172
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power peak reset: On`);
5173
+ this.productionsService.updateCharacteristic(Characteristic.enphasePowerMaxReset, false);
5174
+ } catch (error) {
5175
+ this.emit('warn', `Production Power Peak reset error: ${error}`);
5176
+ };
5177
+ });
5178
+
5179
+ //production state sensor service
5180
+ if (this.powerProductionStateActiveSensorsCount > 0) {
5181
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Power State Sensor Service`) : false;
5182
+ this.powerProductionStateSensorsServices = [];
5183
+ for (let i = 0; i < this.powerProductionStateActiveSensorsCount; i++) {
5184
+ const sensorName = this.powerProductionStateActiveSensors[i].namePrefix ? `${accessoryName} ${this.powerProductionStateActiveSensors[i].name}` : this.powerProductionStateActiveSensors[i].name;
5185
+ const serviceType = this.powerProductionStateActiveSensors[i].serviceType;
5186
+ const characteristicType = this.powerProductionStateActiveSensors[i].characteristicType;
5187
+ const powerProductionStateSensorService = accessory.addService(serviceType, sensorName, `powerProductionStateSensorService${i}`);
5188
+ powerProductionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5189
+ powerProductionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5190
+ powerProductionStateSensorService.getCharacteristic(characteristicType)
5191
+ .onGet(async () => {
5192
+ const state = this.powerProductionStateActiveSensors[i].state;
5193
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power state sensor: ${state ? 'Active' : 'Not active'}`);
5194
+ return state;
5195
+ });
5196
+ this.powerProductionStateSensorsServices.push(powerProductionStateSensorService);
5197
+ };
5198
+ };
5199
+
5200
+ //production power level sensors service
5201
+ if (this.powerProductionLevelActiveSensorsCount > 0) {
5202
+ this.powerProductionLevelSensorsServices = [];
5203
+ for (let i = 0; i < this.powerProductionLevelActiveSensorsCount; i++) {
5204
+ const sensorName = this.powerProductionLevelActiveSensors[i].namePrefix ? `${accessoryName} ${this.powerProductionLevelActiveSensors[i].name}` : this.powerProductionLevelActiveSensors[i].name;
5205
+ const serviceType = this.powerProductionLevelActiveSensors[i].serviceType;
5206
+ const characteristicType = this.powerProductionLevelActiveSensors[i].characteristicType;
5207
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Power Level ${sensorName} Sensor Service`) : false;
5208
+ const powerProductionLevelSensorsService = accessory.addService(serviceType, sensorName, `powerProductionLevelSensorsService${i}`);
5209
+ powerProductionLevelSensorsService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5210
+ powerProductionLevelSensorsService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5211
+ powerProductionLevelSensorsService.getCharacteristic(characteristicType)
5212
+ .onGet(async () => {
5213
+ const state = this.powerProductionLevelActiveSensors[i].state;
5214
+ const info = this.disableLogInfo ? false : this.emit('message', `Production power level sensor: ${sensorName}: ${state ? 'Active' : 'Not active'}`);
5215
+ return state;
5216
+ });
5217
+ this.powerProductionLevelSensorsServices.push(powerProductionLevelSensorsService);
5218
+ };
5219
+ };
5220
+
5221
+ //production energy state sensor service
5222
+ if (this.energyProductionStateActiveSensorsCount > 0) {
5223
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Energy State Sensor Service`) : false;
5224
+ this.energyProductionStateSensorsServices = [];
5225
+ for (let i = 0; i < this.energyProductionStateActiveSensorsCount; i++) {
5226
+ const sensorName = this.energyProductionStateActiveSensors[i].namePrefix ? `${accessoryName} ${this.energyProductionStateActiveSensors[i].name}` : this.energyProductionStateActiveSensors[i].name;
5227
+ const serviceType = this.energyProductionStateActiveSensors[i].serviceType;
5228
+ const characteristicType = this.energyProductionStateActiveSensors[i].characteristicType;
5229
+ const energyProductionStateSensorService = accessory.addService(serviceType, sensorName, `energyProductionStateSensorService${i}`);
5230
+ energyProductionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5231
+ energyProductionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5232
+ energyProductionStateSensorService.getCharacteristic(characteristicType)
5233
+ .onGet(async () => {
5234
+ const state = this.energyProductionStateActiveSensors[i].state;
5235
+ const info = this.disableLogInfo ? false : this.emit('message', `Production energy state sensor: ${state ? 'Active' : 'Not active'}`);
5236
+ return state;
5237
+ });
5238
+ this.energyProductionStateSensorsServices.push(energyProductionStateSensorService);
5239
+ };
5240
+ };
5241
+
5242
+ //production energy level sensor service
5243
+ if (this.energyProductionLevelActiveSensorsCount > 0) {
5244
+ this.energyProductionLevelSensorsServices = [];
5245
+ for (let i = 0; i < this.energyProductionLevelActiveSensorsCount; i++) {
5246
+ const sensorName = this.energyProductionLevelActiveSensors[i].namePrefix ? `${accessoryName} ${this.energyProductionLevelActiveSensors[i].name}` : this.energyProductionLevelActiveSensors[i].name;
5247
+ const serviceType = this.energyProductionLevelActiveSensors[i].serviceType;
5248
+ const characteristicType = this.energyProductionLevelActiveSensors[i].characteristicType;
5249
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production Energy Level ${sensorName} Sensor Service`) : false;
5250
+ const energyProductionLevelSensorsService = accessory.addService(serviceType, sensorName, `energyProductionLevelSensorsService${i}`);
5251
+ energyProductionLevelSensorsService.addOptionalCharacteristic(Characteristic.ConfiguredName);
5252
+ energyProductionLevelSensorsService.setCharacteristic(Characteristic.ConfiguredName, sensorName);
5253
+ energyProductionLevelSensorsService.getCharacteristic(characteristicType)
5254
+ .onGet(async () => {
5255
+ const state = this.energyProductionLevelActiveSensors[i].state;
5256
+ const info = this.disableLogInfo ? false : this.emit('message', `Production energy level sensor: ${sensorName}: ${state ? 'Active' : 'Not active'}`);
5257
+ return state;
5258
+ });
5259
+ this.energyProductionLevelSensorsServices.push(energyProductionLevelSensorsService);
5260
+ };
5273
5261
  };
5274
5262
  };
5275
5263
 
5276
5264
  //power and energy consumption
5277
- if (metersInstalled && metersConsumptionEnabled) {
5265
+ if (metersConsumptionEnabled && productionCtConsumptionSupported) {
5278
5266
  this.consumptionsServices = [];
5279
5267
  for (const consumption of this.pv.production.ct.consumption) {
5280
5268
  const measurmentType = consumption.measurmentType;
@@ -5543,7 +5531,7 @@ class EnvoyDevice extends EventEmitter {
5543
5531
  };
5544
5532
  };
5545
5533
  }
5546
- }
5534
+ };
5547
5535
 
5548
5536
  //ensemble
5549
5537
  if (ensemblesSupported) {
@@ -5593,7 +5581,7 @@ class EnvoyDevice extends EventEmitter {
5593
5581
 
5594
5582
  this.ensemblesInventoryServices.push(ensembleInventoryService);
5595
5583
  }
5596
- }
5584
+ };
5597
5585
 
5598
5586
  //ensembles status summary
5599
5587
  if (ensemblesInstalled) {
@@ -5795,11 +5783,11 @@ class EnvoyDevice extends EventEmitter {
5795
5783
  this.solarGridModeSensorsServices.push(solarGridModeSensorsService);
5796
5784
  };
5797
5785
  };
5798
- }
5786
+ };
5799
5787
 
5800
5788
  //encharges
5801
5789
  if (enchargesInstalled) {
5802
- //encharges level and state
5790
+ //encharges summary level and state
5803
5791
  const debug2 = this.enableDebugMode ? this.emit('debug', `Prepare Encharges Summary Service`) : false;
5804
5792
  this.enphaseEnchargesSummaryLevelAndStateService = accessory.addService(Service.Lightbulb, `Encharges`, `enphaseEnchargesSummaryLevelAndStateService`);
5805
5793
  this.enphaseEnchargesSummaryLevelAndStateService.addOptionalCharacteristic(Characteristic.ConfiguredName);
@@ -5816,7 +5804,7 @@ class EnvoyDevice extends EventEmitter {
5816
5804
  } catch (error) {
5817
5805
  this.emit('warn', `Set Encharges energy state error: ${error}`);
5818
5806
  };
5819
- })
5807
+ });
5820
5808
  this.enphaseEnchargesSummaryLevelAndStateService.getCharacteristic(Characteristic.Brightness)
5821
5809
  .onGet(async () => {
5822
5810
  const state = this.ensemble.encharges.percentFullSum;
@@ -5829,9 +5817,9 @@ class EnvoyDevice extends EventEmitter {
5829
5817
  } catch (error) {
5830
5818
  this.emit('warn', `Set Encharges energy level error: ${error}`);
5831
5819
  };
5832
- })
5820
+ });
5833
5821
 
5834
- //encharge state sensor services
5822
+ //encharges state sensor
5835
5823
  if (enchargeSettingsSupported) {
5836
5824
  if (this.enchargeStateActiveSensorsCount > 0) {
5837
5825
  this.enchargeStateSensorsServices = [];
@@ -5854,7 +5842,7 @@ class EnvoyDevice extends EventEmitter {
5854
5842
  };
5855
5843
  };
5856
5844
 
5857
- //encharge profile service
5845
+ //encharges profile
5858
5846
  if (tariffSupported) {
5859
5847
  const enchargeSettings = this.ensemble.encharges.settings;
5860
5848
 
@@ -5909,7 +5897,7 @@ class EnvoyDevice extends EventEmitter {
5909
5897
  };
5910
5898
  };
5911
5899
 
5912
- //encharges services
5900
+ //indyvidual encharge state
5913
5901
  this.enchargesServices = [];
5914
5902
  for (const encharge of this.ensemble.encharges.devices) {
5915
5903
  const serialNumber = encharge.serialNumber;
@@ -6023,14 +6011,14 @@ class EnvoyDevice extends EventEmitter {
6023
6011
  return value;
6024
6012
  });
6025
6013
  this.enchargesServices.push(enphaseEnchargeService);
6026
- }
6027
- }
6014
+ };
6015
+ };
6028
6016
 
6029
6017
  //enpowers
6030
6018
  if (enpowersInstalled) {
6031
6019
  const serialNumber = this.ensemble.enpowers.devices[0].serialNumber;
6032
6020
 
6033
- //grid state control service
6021
+ //grid state control
6034
6022
  if (this.enpowerGridStateActiveControlsCount > 0) {
6035
6023
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Enpower ${serialNumber} Grid State Control Service`) : false;
6036
6024
  this.enpowerGridStateControlsServices = [];
@@ -6060,7 +6048,7 @@ class EnvoyDevice extends EventEmitter {
6060
6048
  };
6061
6049
  };
6062
6050
 
6063
- //grid state sensor services
6051
+ //grid state sensor
6064
6052
  if (this.enpowerGridStateActiveSensorsCount > 0) {
6065
6053
  this.enpowerGridStateSensorsServices = [];
6066
6054
  for (let i = 0; i < this.enpowerGridStateActiveSensorsCount; i++) {
@@ -6081,7 +6069,7 @@ class EnvoyDevice extends EventEmitter {
6081
6069
  };
6082
6070
  };
6083
6071
 
6084
- //grid mode sensor services
6072
+ //grid mode sensor
6085
6073
  if (this.enpowerGridModeActiveSensorsCount > 0) {
6086
6074
  this.enpowerGridModeSensorsServices = [];
6087
6075
  for (let i = 0; i < this.enpowerGridModeActiveSensorsCount; i++) {
@@ -6102,7 +6090,7 @@ class EnvoyDevice extends EventEmitter {
6102
6090
  };
6103
6091
  };
6104
6092
 
6105
- //enpower dry contacts
6093
+ //dry contacts
6106
6094
  if (dryContactsInstalled) {
6107
6095
  if (this.enpowerDryContactsControl) {
6108
6096
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Enpower ${serialNumber} Dry Contacts Control Services`) : false;
@@ -6151,7 +6139,7 @@ class EnvoyDevice extends EventEmitter {
6151
6139
  };
6152
6140
  };
6153
6141
 
6154
- //enpower services
6142
+ //indyvidual enpower state
6155
6143
  this.enpowersServices = [];
6156
6144
  for (const enpower of this.ensemble.enpowers.devices) {
6157
6145
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Enpower ${serialNumber} Service`) : false;
@@ -6239,11 +6227,11 @@ class EnvoyDevice extends EventEmitter {
6239
6227
  });
6240
6228
  this.enpowersServices.push(enphaseEnpowerService);
6241
6229
  };
6242
- }
6230
+ };
6243
6231
 
6244
6232
  //generators
6245
6233
  if (generatorsInstalled) {
6246
- //generator control service
6234
+ //generator control
6247
6235
  const type = this.ensemble.generator.type;
6248
6236
  if (this.generatorStateActiveControlsCount > 0) {
6249
6237
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Generator ${type} Control Service`) : false;
@@ -6275,7 +6263,7 @@ class EnvoyDevice extends EventEmitter {
6275
6263
  };
6276
6264
  };
6277
6265
 
6278
- //generator state sensor services
6266
+ //generator state sensor
6279
6267
  if (this.generatorStateActiveSensorsCount > 0) {
6280
6268
  this.generatorStateSensorsServices = [];
6281
6269
  for (let i = 0; i < this.generatorStateActiveSensorsCount; i++) {
@@ -6296,7 +6284,7 @@ class EnvoyDevice extends EventEmitter {
6296
6284
  };
6297
6285
  };
6298
6286
 
6299
- //generator mode control services
6287
+ //generator mode control
6300
6288
  if (this.generatorModeActiveControlsCount > 0) {
6301
6289
  this.generatorModeControlsServices = [];
6302
6290
  for (let i = 0; i < this.generatorModeActiveControlsCount; i++) {
@@ -6327,7 +6315,7 @@ class EnvoyDevice extends EventEmitter {
6327
6315
  };
6328
6316
  };
6329
6317
 
6330
- //generator mode sensor services
6318
+ //generator mode sensor
6331
6319
  if (this.generatorModeActiveSensorsCount > 0) {
6332
6320
  this.generatorModeSensorsServices = [];
6333
6321
  for (let i = 0; i < this.generatorModeActiveSensorsCount; i++) {
@@ -6348,7 +6336,7 @@ class EnvoyDevice extends EventEmitter {
6348
6336
  };
6349
6337
  };
6350
6338
 
6351
- //generator services
6339
+ //indyvidual generator state
6352
6340
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare Generator ${type} Service`) : false;
6353
6341
  this.generatorService = accessory.addService(Service.enphaseGerneratorService, `Generator ${type}`, type);
6354
6342
  this.generatorService.setCharacteristic(Characteristic.ConfiguredName, `Generator ${type}`);
@@ -6406,8 +6394,8 @@ class EnvoyDevice extends EventEmitter {
6406
6394
  const info = this.disableLogInfo ? false : this.emit('message', `Generator: ${type}, present: ${value}`);
6407
6395
  return value;
6408
6396
  });
6409
- }
6410
- }
6397
+ };
6398
+ };
6411
6399
 
6412
6400
  //live data
6413
6401
  if (liveDataSupported) {
@@ -6467,7 +6455,7 @@ class EnvoyDevice extends EventEmitter {
6467
6455
  });
6468
6456
  this.liveDataServices.push(liveDataService);
6469
6457
  }
6470
- }
6458
+ };
6471
6459
 
6472
6460
  return accessory;
6473
6461
  } catch (error) {