Skip to content

Commit

Permalink
Moved to beta and changed some stuff V1.0.4-beta.1
Browse files Browse the repository at this point in the history
Moved the SOC and charging under humidity sensor to be used for automations.
Still figuring out that is why it moved to beta.
  • Loading branch information
K1LL3R234 committed Oct 11, 2024
1 parent 7d7e544 commit 31ea12c
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 103 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This change log documents all release versions of homebridge-texecom

### 1.0.4-beta.1 (2024-10-11)

- **FEATURE** - Moved the SOC and charging under humidity sensor to be used for automations.
Still figuring out that is why it moved to beta.

### 1.0.3 (2024-10-11)

- **FEATURE** - Moved the SOC and charging under the Battery Power W.
Expand Down
208 changes: 107 additions & 101 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ SunsynkPlatform.prototype = {
var batt_pw = { "name": "Battery Power W", "type": "pv" };
var acc = new SunsynkAccessory(this.log, batt_pw);
allacc.push(acc);
var batt_soc = { "name": "Battery SOC", "type": "batt" };
var acc = new SunsynkAccessory(this.log, batt_soc);
allacc.push(acc);

var load_pw = { "name": "Load Power W", "type": "pv" };
var acc = new SunsynkAccessory(this.log, load_pw);
Expand All @@ -98,50 +101,55 @@ SunsynkPlatform.prototype = {
var batt_result = await api.get(`/plant/energy/${plant_id}/flow`, null, null);

for (var i = 0; i < allacc.length; i++) {
if (allacc[i].type == 'pv') {
switch (allacc[i].name) {
case 'Current PV Power W':
allacc[i].changeHandler(real_result.pac);
break;

case 'Today PV Electricity kWh':
allacc[i].changeHandler(real_result.etoday);
break;

case 'Month PV Electricity kWh':
allacc[i].changeHandler(real_result.emonth);
break;

case 'Year PV Electricity kWh':
allacc[i].changeHandler(real_result.eyear);
break;

case 'Total PV Electricity kWh':
allacc[i].changeHandler(real_result.etotal);
break;

case 'Battery Power W':
allacc[i].changeHandler(batt_result.battPower);
break;

case 'Load Power W':
allacc[i].changeHandler(batt_result.loadOrEpsPower);
break;
}
}
else if (allacc[i].type == 'batt') {
allacc[i].changeHandler1(batt_result.soc);

switch (allacc[i].name) {
case 'Current Power W':
allacc[i].changeHandler(real_result.pac);
break;

case 'Today Electricity kWh':
allacc[i].changeHandler(real_result.etoday);
break;

case 'Month Electricity kWh':
allacc[i].changeHandler(real_result.emonth);
break;

case 'Year Electricity kWh':
allacc[i].changeHandler(real_result.eyear);
break;

case 'Total Electricity kWh':
allacc[i].changeHandler(real_result.etotal);
break;

case 'Battery Power W':
allacc[i].changeHandler(batt_result.battPower);

allacc[i].changeHandler1(batt_result.soc);
var state = Characteristic.ChargingState.NOT_CHARGING;

var state = Characteristic.ChargingState.NOT_CHARGING;
if (batt_result.toBat) {
state = Characteristic.ChargingState.CHARGING;
}
else if (batt_result.batTo) {
state = Characteristic.ChargingState.NOT_CHARGING;
}

if (batt_result.toBat) {
state = Characteristic.ChargingState.CHARGING;
}
else if (batt_result.batTo) {
state = Characteristic.ChargingState.NOT_CHARGING;
}
allacc[i].changeChargeState(state);

allacc[i].changeChargeState(state);
allacc[i].changeLevel(batt_result.soc < lowbatt ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL)

allacc[i].changeLevel(batt_result.soc < lowbatt ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL)
break;
allacc[i].changeHandler(batt_result.soc);

case 'Load Power W':
allacc[i].changeHandler(batt_result.loadOrEpsPower);
break;
}
}
}
Expand Down Expand Up @@ -181,83 +189,81 @@ SunsynkAccessory.prototype = {
.setCharacteristic(Characteristic.Model, "Sunsynk"/*+ (this.accessoryType === ""?"":"") */)
.setCharacteristic(Characteristic.SerialNumber, this.sn);

if (this.name == 'Battery Power W') {
service = new Service.LightSensor();
newService = new Service.Battery();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}
switch (this.type) {
case "pv":
service = new Service.LightSensor();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}

changeAction1 = function (newvalue) {
newService.getCharacteristic(Characteristic.BatteryLevel)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.BatteryLevel)
.updateValue(newvalue);
}
this.changeHandler = function (value) {
if (value < 0.0001) {
value = 0.0001
}

changeLevel = function (newlevel) {
newService.getCharacteristic(Characteristic.StatusLowBattery)
.setValue(newlevel);
newService.getCharacteristic(Characteristic.StatusLowBattery)
.updateValue(newlevel);
}
changeAction(value);
platform.log.debug("New Value:" + value);
}.bind(this);

changeState = function (newvalue) {
newService.getCharacteristic(Characteristic.ChargingState)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.ChargingState)
.updateValue(newvalue);
}
return [informationService, service];

this.changeHandler = function (value) {
var newValue = value;
case "batt":
service = new Service.HumiditySensor();

changeAction(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);
changeAction = function (value) {
service.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.setValue(value);
service.getCharacteristic(Characteristic.CurrentRelativeHumidity)
.updateValue(value);
}

this.changeHandler1 = function (value) {
var newValue = value;

changeAction1(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);
newService = new Service.Battery();
changeAction1 = function (newvalue) {
newService.getCharacteristic(Characteristic.BatteryLevel)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.BatteryLevel)
.updateValue(newvalue);
}

this.changeChargeState = function (value) {
var state = value;
changeLevel = function (newlevel) {
newService.getCharacteristic(Characteristic.StatusLowBattery)
.setValue(newlevel);
newService.getCharacteristic(Characteristic.StatusLowBattery)
.updateValue(newlevel);
}

changeState(state);
platform.log.debug("New State:" + state);
}.bind(this);
changeState = function (newvalue) {
newService.getCharacteristic(Characteristic.ChargingState)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.ChargingState)
.updateValue(newvalue);
}

this.changeLevel = function (value) {
var level = value;
changeLevel(level)
platform.log.debug("New Level:" + level);
}.bind(this);
this.changeHandler = function (value) {
changeAction(value);
platform.log.debug("New Value:" + value);
}.bind(this);

return [informationService, service, newService];
}
else {
service = new Service.LightSensor();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}
this.changeHandler1 = function (value) {
changeAction1(value);
platform.log.debug("New Value:" + value);
}.bind(this);

this.changeHandler = function (value) {
var newValue = value;
this.changeChargeState = function (value) {
changeState(value);
platform.log.debug("New State:" + value);
}.bind(this);

changeAction(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);
this.changeLevel = function (value) {
changeLevel(value)
platform.log.debug("New Level:" + value);
}.bind(this);

return [informationService, service];
return [informationService, service, newService];
}
}
}
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "Homebridge Sunsynk",
"name": "homebridge-sunsynk",
"description": "A plugin for homebridge (https://github.com/nfarina/homebridge) to integrate Sunsynk inverter into HomeKit",
"version": "1.0.3",
"version": "1.0.4-beta.1",
"author": {
"name": "Chris Posthumus",
"email": "[email protected]"
Expand All @@ -29,7 +29,15 @@
"preferGlobal": true,
"keywords": [
"homebridge-plugin",
"homebridge",
"inverter",
"solar",
"power-consumption",
"SOC",
"battery",
"solar-panels",
"solar-inverter",
"sensor",
"Sunsynk"
],
"engines": {
Expand All @@ -47,4 +55,4 @@
"debug": "^2.6.9",
"string": "^3.3.3"
}
}
}

0 comments on commit 31ea12c

Please sign in to comment.