Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for APsystem micro-converters using ECU-R #176

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions @types/alltypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'apsystems';
35 changes: 30 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
{
"name": "Dries Hooghe",
"email": "dries@drieshooghe.com"
},
{
"name": "Roy K"
}
]
},
Expand All @@ -74,16 +77,38 @@
"drivers": [
{
"name": {
"en": "Enphase Enlighten"
"en": "APsystems ECU-R",
"nl": "APsystems ECU-R"
},
"pair": [
{
"id": "pair"
}
],
"images": {
"large": "./drivers/apsystems/assets/images/large.jpg",
"small": "./drivers/apsystems/assets/images/small.jpg"
},
"class": "solarpanel",
"capabilities": [
"measure_power",
"meter_power"
],
"images": {
"large": "/drivers/enphase/assets/images/large.jpg",
"small": "/drivers/enphase/assets/images/small.jpg"
"settings": [
{
"id": "ip",
"type": "text",
"label": {
"en": "APsystems ECU-R IP address"
}
}
],
"id": "apsystems"
},
{
"name": {
"en": "Enphase Enlighten",
"nl": "Enphase Enlighten"
},
"connectivity": [
"cloud"
Expand Down Expand Up @@ -590,4 +615,4 @@
"id": "{{txt.serialnum}}"
}
}
}
}
96 changes: 96 additions & 0 deletions drivers/apsystems/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/apsystems/assets/images/large.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/apsystems/assets/images/small.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions drivers/apsystems/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Inverter } from "../../inverter";
import { apsystems } from 'apsystems';
import { DeviceSettings, EcurData } from "./types";

class APsystemsECUR extends Inverter {
interval = 2;

async checkProduction(): Promise<void> {
this.homey.log("Checking production");

const self = this;
const settings: DeviceSettings = await this.getSettings();

const ecur = new apsystems.ECUR(settings.ip, 8899);
ecur.getECUdata(async (error: Error, result: EcurData) => {

// Handle error
if (error) {
self.homey.log(`Unavailable (${error})`);
await self.setUnavailable(`Error retrieving data (${error})`);

return;
}

// Verify availability
if (!self.getAvailable())
await self.setAvailable();

// Set capabilities
await self.setCapabilityValue('meter_power', result.today_energy);
await self.setCapabilityValue('measure_power', result.current_power);

self.homey.log(`Current energy is ${result.today_energy}kWh`);
self.homey.log(`Current power is ${result.current_power}W`);
});
}
}

module.exports = APsystemsECUR;
30 changes: 30 additions & 0 deletions drivers/apsystems/driver.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": {
"en": "APsystems ECU-R",
"nl": "APsystems ECU-R"
},
"class": "solarpanel",
"capabilities": [
"measure_power",
"meter_power"
],
"connectivity": ["lan"],
"images": {
"large": "{{driverAssetsPath}}/images/large.jpg",
"small": "{{driverAssetsPath}}/images/small.jpg"
},
"pair": [
{
"id": "pair"
}
],
"settings": [
{
"id": "ip",
"type": "text",
"label": {
"en": "APsystems ECU-R IP address"
}
}
]
}
20 changes: 20 additions & 0 deletions drivers/apsystems/driver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Driver } from "homey";
import PairSession from "homey/lib/PairSession";
import { DeviceSettings, EcurData } from "./types";

import { apsystems } from 'apsystems';

class APsystems extends Driver {

async onPair(session: PairSession) {
session.setHandler('validate', async (data: DeviceSettings) => {

const ecur = new apsystems.ECUR(data.ip, 8899);
ecur.getECUdata(async (err: Error, result: EcurData) => {
if (err !== null) new Error(this.homey.__('ip_error'));
});
});
}
}

module.exports = APsystems;
63 changes: 63 additions & 0 deletions drivers/apsystems/pair/pair.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<style type="text/css">
.form-group, .input-field {
display: flex;
flex-direction: column;
align-items: center;
}

.input-field {
margin-top: 10px;
}

.submit-button {
margin-top: 10px;
}
</style>

<div class="form-group">
<div class="input-field">
<label>Please enter the IP address or hostname of your Fronius Datamanager:</label>
<input type="text" id="ip" placeholder="IP address" value="" />
</div>

<div class="input-field">
<label>Give your inverter a name:</label>
<input type="text" id="name" placeholder="Name" value="" />
</div>

<button class="submit-button" id="validate">Connect</button>
</div>

<script type="text/javascript">
$(() => {
$('#validate').click(() => {
Homey.showLoadingOverlay();

var ip = $('#ip').val();
var name = $('#name').val();

var deviceDefinition = {
name,
data: {},
settings: { ip }
};

Homey.emit('validate', { ip })
.then(() => {
Homey.createDevice(deviceDefinition, (error, result) => {
if (error) {
Homey.hideLoadingOverlay();
Homey.alert(error);
} else {
Homey.done();
}
});
}
.catch((error) => {
Homey.hideLoadingOverlay();
Homey.alert(error);
});
});
});
});
</script>
18 changes: 18 additions & 0 deletions drivers/apsystems/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

export interface DeviceSettings {
ip: string;
}

export interface EcurData {
cmdPrefix: string;
ecu_id: string;
unknown1: string;
lifetime_energy: number;
current_power: number;
today_energy: number;
unknown2: string;
qty_of_inverters: number;
unknown3: string;
firmware: string;
timezone: string;
}
Loading