Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes bug when Solar Panel is not generating
Browse files Browse the repository at this point in the history
Values go to their maximum when the solar power is not generating.
  • Loading branch information
codyc1515 committed Oct 6, 2019
1 parent e7303ea commit a2ec522
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
38 changes: 23 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,31 @@ SMAInverter.prototype = {

client.readHoldingRegisters(30057, 10, function(err, data) {this.value.SerialNumber = data.buffer.readUInt32BE();}.bind(this));

client.readHoldingRegisters(30977, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomAmperes).updateValue(data.buffer.readUInt32BE() / 1000);}.bind(this));
client.readHoldingRegisters(30775, 10, function(err, data) {
this.SMAInverter.getCharacteristic(Characteristic.CustomWatts).updateValue(data.buffer.readUInt32BE());

this.loggingService.addEntry({time: moment().unix(), power: data.buffer.readUInt32BE()});

if(data.buffer.readUInt32BE() > 0) {
this.SMAInverter.getCharacteristic(Characteristic.On).updateValue(1);
this.SMAInverter.getCharacteristic(Characteristic.OutletInUse).updateValue(1);
}
else {
this.SMAInverter.getCharacteristic(Characteristic.On).updateValue(0);
this.SMAInverter.getCharacteristic(Characteristic.OutletInUse).updateValue(0);
}
// Check if the value is unrealistic (the inverter is not generating)
if(data.buffer.readUInt32BE() > 999999) {
this.SMAInverter.getCharacteristic(Characteristic.On).updateValue(0);
this.SMAInverter.getCharacteristic(Characteristic.OutletInUse).updateValue(0);
}
else {
this.SMAInverter.getCharacteristic(Characteristic.CustomWatts).updateValue(data.buffer.readUInt32BE());

this.loggingService.addEntry({time: moment().unix(), power: data.buffer.readUInt32BE()});

if(data.buffer.readUInt32BE() > 0) {
this.SMAInverter.getCharacteristic(Characteristic.On).updateValue(1);
this.SMAInverter.getCharacteristic(Characteristic.OutletInUse).updateValue(1);
}
else {
this.SMAInverter.getCharacteristic(Characteristic.On).updateValue(0);
this.SMAInverter.getCharacteristic(Characteristic.OutletInUse).updateValue(0);
}

client.readHoldingRegisters(30977, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomAmperes).updateValue(data.buffer.readUInt32BE() / 1000);}.bind(this));
client.readHoldingRegisters(30783, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomVolts).updateValue(data.buffer.readUInt32BE() / 100);}.bind(this));
client.readHoldingRegisters(30529, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomKilowattHours).updateValue(data.buffer.readUInt32BE() / 1000);}.bind(this));
}
}.bind(this));
client.readHoldingRegisters(30783, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomVolts).updateValue(data.buffer.readUInt32BE() / 100);}.bind(this));
client.readHoldingRegisters(30529, 10, function(err, data) {this.SMAInverter.getCharacteristic(Characteristic.CustomKilowattHours).updateValue(data.buffer.readUInt32BE() / 1000);}.bind(this));
}.bind(this), 1000);

this.loggingService = new FakeGatoHistoryService("energy", Accessory);
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_from": "homebridge-sma-inverter@latest",
"_from": "homebridge-sma-inverter",
"_id": "homebridge-sma-inverter@1.0.0",
"_inBundle": false,
"_integrity": "sha512-MmDmK2PeXwNioaoDvZZL6SZfMWIK7nEuPtJMzcAtlb4WWDvIKoSIlnaw/tURKEaZJoRrx0/EIKVqZE5YAWF/0w==",
Expand All @@ -8,10 +8,10 @@
"_requested": {
"type": "tag",
"registry": true,
"raw": "homebridge-sma-inverter@latest",
"raw": "homebridge-sma-inverter",
"name": "homebridge-sma-inverter",
"escapedName": "homebridge-sma-inverter",
"rawSpec": "latest",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
Expand All @@ -20,8 +20,8 @@
],
"_resolved": "https://registry.npmjs.org/homebridge-sma-inverter/-/homebridge-sma-inverter-1.0.0.tgz",
"_shasum": "8c12765d091453855ae9bfcdd7700a0c04bfa8a2",
"_spec": "homebridge-sma-inverter@latest",
"_where": "/usr/local/lib",
"_spec": "homebridge-sma-inverter",
"_where": "/home/pi",
"author": {
"name": "codyc1515"
},
Expand All @@ -30,7 +30,8 @@
},
"bundleDependencies": false,
"dependencies": {
"request": "^2.81.0",
"fakegato-history": "^0.5.5",
"moment": "^2.24.0",
"utils": "^0.3.1"
},
"deprecated": false,
Expand Down Expand Up @@ -59,5 +60,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.1.0"
"version": "2.0.0"
}

0 comments on commit a2ec522

Please sign in to comment.