Skip to content

Commit

Permalink
### 3.1.2 (16.08.2023)
Browse files Browse the repository at this point in the history
- (PLCHome) sendTo now also possible with objects as message data
- (PLCHome) Added message getHistory
  • Loading branch information
PLCHome committed Aug 16, 2023
1 parent 169f5a5 commit 6242e90
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 64 deletions.
114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,115 @@ The settings are accepted.

---

## sendTo for scripts

It is possible to send a command to the instance via sendTo. The adapter then responds.
The following commands are implemented.
The return value is returned depending on the parameter transfer. If the parameters are passed as a JSON string, a JSON is returned. If the parameters are passed as an object, an object is returned.

### getHistory

This command lists the history. It can be used, for example, to supplement data in a database.
Regardless of the time range, Growatt always seems to return 80 records. If the interval is set to 1 minute and more than 80 minutes are needed, the command must be executed several times and the start from 0 must be increased more and more.

| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------------------------------------------------------------ |
| type | String | The type of inverter can be found in object "growatt.<instance>.<nr>.devices.<sn>.growattType". |
| sn | String | The serialnumber of inverter can be found in object path "growatt.<instance>.<nr>.devices.<sn>". |
| startDate | Date | The atart |
| endDate | Date | The end mast be grater then start |
| start | Integer | 0 is the start page for the call with the most recent data first |

Example call:

```
sendTo('growatt.0','getHistory',{"type":"<your inverter type>","sn":"<your inverter serial>","startDate":new Date((new Date()).getTime()- 60*60*1000),"endDate":new Date() , "start":0},(res)=>{console.log(res)})
```

### getDatalogger

It gives you information about the dataloggers.
This function has no parameters. Either "{}" or {} must be passed.
The return is an array of object.

| Parameter | Type | Description |
| --------- | ---- | ----------- |

### getDataLoggerIntervalRegister

It reads out the interval and returns it. the return value is an OBJ. The interval is in msg.

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |

### setDataLoggerIntervalRegister

Writes the interval at which the logger sends the data.

| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |
| value | integer | The new value in minutes |

An object is returned with a message.

### getDataLoggerIpRegister

It reads the IP to which the logger sends the data and returns it. The return value is an OBJ. The IP is in msg.

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |

### setDataLoggerIp

It writes the IP to which the logger sends the data. It's useful for the Grott project. The return value is an object that says what happened.

| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |
| value | integer | The new value in minutes |

An object is returned with a message.

### getDataLoggerPortRegister

It reads the port to which the logger sends the data and returns it. The return value is an OBJ. The IP is in msg.

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |

### setDataLoggerPort

It writes the port to which the logger sends the data. It's useful for the Grott project. The return value is an object that says what happened.

| Parameter | Type | Description |
| --------- | ------- | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |
| value | integer | The new value in minutes |

An object is returned with a message.

### checkLoggerFirmware

Calls up the firmware check from the logger. If an update is necessary, you can see it in the answer.

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |

### restartDatalogger

Causes a warm start of the data logger.

| Parameter | Type | Description |
| --------- | ------ | ------------------------------------------------------------- |
| sn | string | The serial number of the logger is returned by getDatalogger. |

---

## Speedup data interval internal method

Have a look at Manage Loggers and Button Interval
Expand Down Expand Up @@ -211,6 +320,11 @@ Therefore, the description has also been removed.

## Changelog

### 3.1.2 (16.08.2023)

- (PLCHome) sendTo now also possible with objects as message data
- (PLCHome) Added message getHistory

### 3.1.1 (03.07.2023)

- (PLCHome) Added support for Growatt page when Plant is a C&I Plant page with indexbC or plantDo in Path of the Growatt web interface. Thanks to Denn281
Expand Down
92 changes: 80 additions & 12 deletions growattMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,26 @@ class Growatt extends utils.Adapter {
}
}

confCheckMsgObj(obj, vars) {
let res = true;
let data = obj.message;
if (typeof data === 'string') {
data = JSON.parse(data);
}
if (typeof data !== 'object') {
this.log.error(`message arg ${typeof data} not an object or json string`);
res = false;
return [data, res];
}
vars.forEach(v => {
if (typeof data[v] === 'undefined') {
this.log.error(`message <arg>.${v} is missing`);
res = false;
}
});
return [data, res];
}

/**
* spinoff onMessage, reads a register
* @param {string} sn serielnumber of datalogger
Expand All @@ -671,13 +691,16 @@ class Growatt extends utils.Adapter {
*/
readLoggerRegister(register, obj) {
if (this.growatt && this.growatt.isConnected()) {
const data = JSON.parse(obj.message);
const [data, ok] = this.confCheckMsgObj(obj, ['sn']);
if (!ok) {
return;
}
this.growatt
.getDataLoggerRegister(data.sn, register)
.then(res => {
this.log.debug(`readLoggerRegister: ${JSON.stringify(res, getJSONCircularReplacer())}`);
if (obj.callback && typeof res.success !== 'undefined') {
this.sendTo(obj.from, obj.command, JSON.stringify(res, getJSONCircularReplacer()), obj.callback);
this.sendTo(obj.from, obj.command, typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res, obj.callback);
}
})
.catch(e => {
Expand All @@ -695,13 +718,16 @@ class Growatt extends utils.Adapter {
*/
writeLoggerRegister(register, obj) {
if (this.growatt && this.growatt.isConnected()) {
const data = JSON.parse(obj.message);
const [data, ok] = this.confCheckMsgObj(obj, ['sn', 'value']);
if (!ok) {
return;
}
this.growatt
.setDataLoggerRegister(data.sn, register, data.value)
.then(res => {
this.log.debug(`writeLoggerRegister: ${JSON.stringify(res, getJSONCircularReplacer())}`);
if (obj.callback && typeof res.success !== 'undefined') {
this.sendTo(obj.from, obj.command, JSON.stringify(res, getJSONCircularReplacer()), obj.callback);
this.sendTo(obj.from, obj.command, typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res, obj.callback);
}
})
.catch(e => {
Expand All @@ -719,13 +745,16 @@ class Growatt extends utils.Adapter {
*/
writeLoggerFunction(func, obj) {
if (this.growatt && this.growatt.isConnected()) {
const data = JSON.parse(obj.message);
const [data, ok] = this.confCheckMsgObj(obj, ['sn', 'value']);
if (!ok) {
return;
}
this.growatt
.setDataLoggerParam(data.sn, func, data.value)
.then(res => {
this.log.debug(`writeLoggerFunction: ${JSON.stringify(res, getJSONCircularReplacer())}`);
if (obj.callback && typeof res.success !== 'undefined') {
this.sendTo(obj.from, obj.command, JSON.stringify(res, getJSONCircularReplacer()), obj.callback);
this.sendTo(obj.from, obj.command, typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res, obj.callback);
}
})
.catch(e => {
Expand All @@ -751,7 +780,12 @@ class Growatt extends utils.Adapter {
.then(res => {
this.log.debug(`getDatalogger: ${JSON.stringify(res, getJSONCircularReplacer())}`);
if (obj.callback) {
this.sendTo(obj.from, obj.command, JSON.stringify(res, getJSONCircularReplacer()), obj.callback);
this.sendTo(
obj.from,
obj.command,
typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res,
obj.callback
);
}
})
.catch(e => {
Expand Down Expand Up @@ -786,13 +820,21 @@ class Growatt extends utils.Adapter {
case 'checkLoggerFirmware':
if (this.growatt && this.growatt.isConnected()) {
wait = true;
const data = JSON.parse(obj.message);
const [data, ok] = this.confCheckMsgObj(obj, ['sn']);
if (!ok) {
return;
}
this.growatt
.checkDataLoggerFirmware(data.type, data.version)
.then(res => {
this.log.debug(`checkDataLoggerFirmware: ${JSON.stringify(res, getJSONCircularReplacer())}`);
if (obj.callback && typeof res.success !== 'undefined') {
this.sendTo(obj.from, obj.command, JSON.stringify(res, getJSONCircularReplacer()), obj.callback);
this.sendTo(
obj.from,
obj.command,
typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res,
obj.callback
);
}
})
.catch(e => {
Expand All @@ -803,7 +845,10 @@ class Growatt extends utils.Adapter {
case 'restartDatalogger':
if (this.growatt && this.growatt.isConnected()) {
wait = true;
const data = JSON.parse(obj.message);
const [data, ok] = this.confCheckMsgObj(obj, ['sn']);
if (!ok) {
return;
}
this.growatt
.setDataLoggerRestart(data.sn)
.then(res => {
Expand All @@ -816,15 +861,38 @@ class Growatt extends utils.Adapter {
});
}
break;
case 'getHistory':
if (this.growatt && this.growatt.isConnected()) {
wait = true;
const [data, ok] = this.confCheckMsgObj(obj, ['type', 'sn', 'startDate', 'endDate', 'start']);
if (!ok) {
return;
}
this.growatt
.getHistory(data.type, data.sn, new Date(data.startDate), new Date(data.endDate), data.start, true)
.then(res => {
if (obj.callback) {
this.sendTo(
obj.from,
obj.command,
typeof obj.message === 'string' ? JSON.stringify(res, getJSONCircularReplacer()) : res,
obj.callback
);
}
})
.catch(e => {
this.log.error(e);
});
}
break;
default:
this.log.warn(`Unknown command: ${obj.command}`);
return false;
return;
}
}
if (!wait && obj.callback) {
this.sendTo(obj.from, obj.command, obj.message, obj.callback);
}
return true;
}
}

Expand Down
39 changes: 13 additions & 26 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"common": {
"name": "growatt",
"version": "3.1.1",
"version": "3.1.2",
"news": {
"3.1.1": {
"en": "Added support for Growatt page when Plant is a C&I Plant page with indexbC or plantDo in Path of the Growatt web interface.",
"de": "Unterstützung für Growatt-Seite, wenn Anlage eine C&I-Pflanze-Seite mit indexbC oder Pflanze ist Tun Sie im Pfad der Growatt-Weboberfläche.",
"ru": "Добавлена поддержка страницы Growatt, когда Plant является C&I Plant page с indexbC или растение Сделайте в пути веб-интерфейса Growatt.",
"pt": "Adicionado suporte para página Growatt quando Plant é uma página Planta C&I com indexbC ou planta Faça no caminho da interface web Growatt.",
"nl": "Aangename steun voor Growatt pagina als Plant een CI Plant pagina is met indexbC of plant Doen in Path of the Growatt web interface.",
"fr": "Ajout d'un support pour la page Growatt lorsque Plant est une page de plante CôneI avec indexbC ou plante Faire dans Path of the Growatt interface web.",
"it": "Aggiunto il supporto per pagina Growatt quando Plant è una pagina C&I Plant con indexbC o pianta Fare in Path of the Growatt web interface.",
"es": "Apoyo añadido a la página Growatt cuando la planta es una página de planta CENTEI con indexbC o planta Hacer en Sendero de la interfaz web de Growatt.",
"pl": "Wsparcie dla strony Growata, gdy Plant jest stroną C&I Plant z indeksem bC lub rośliną roślinną. Do in Path of the Growatt web interface (ang.).",
"uk": "Додано підтримку сторінки Growatt, коли Завод є C&I Заводська сторінка з індексом BC або рослиною Do in Шлях веб-інтерфейсу Growatt.",
"zh-cn": "在有指数、C或植物的C&I Plant页的植物种植园时,添加对Growatt页的支持 Growatt网接口的Path"
"3.1.2": {
"en": "Added support for Growatt page when Plant is a C&I Plant page with indexbC or plantDo in Growatt web interface path.\nAdded getHistory message.",
"de": "Unterstützung für Growatt-Seite, wenn Anlage eine C&I-Pflanze-Seite mit indexbC oder Pflanze ist Machen Sie in Growatt Web-Schnittstellenpfad.\nHinzugefügt getHistory-Nachricht.",
"ru": "Добавлена поддержка страницы Growatt, когда Plant является C&I Plant page с indexbC или растение Сделайте в Growatt web интерфейс пути.\nДобавлено getHistory сообщение.",
"pt": "Adicionado suporte para página Growatt quando Plant é uma página Planta C&I com indexbC ou planta Faça no caminho de interface web Growatt.\nAdicionada mensagem getHistory.",
"nl": "Aangename steun voor Growatt pagina als Plant een CI Plant pagina is met indexbC of plant Doe in Growatt interface pad.\nIk heb zijn boodschap toegevoegd.",
"fr": "Ajout d'un support pour la page Growatt lorsque Plant est une page de plante CôneI avec indexbC ou plante Faites dans le chemin d'interface Web de Growatt.\nAjout du message getHistory.",
"it": "Aggiunto il supporto per pagina Growatt quando Plant è una pagina C&I Plant con indexbC o pianta Fai il percorso dell'interfaccia web di Growatt.\nAggiunto getHistory messaggio.",
"es": "Apoyo añadido a la página Growatt cuando la planta es una página de planta CENTEI con indexbC o planta Hacer en Growatt ruta de interfaz web.\nSe agregó mensaje de historia.",
"pl": "Wsparcie dla strony Growata, gdy Plant jest stroną C&I Plant z indeksem bC lub rośliną roślinną. Do in Growatt web path (ang.).\nAdded getHistory message (ang.).",
"uk": "Додано підтримку сторінки Growatt, коли Завод є C&I Заводська сторінка з індексом BC або рослиною Відвідайте веб-сайт Growatt.\nДодано getHistory повідомлення.",
"zh-cn": "在有指数、C或植物的C&I Plant页的植物种植园时,添加对Growatt页的支持 在Growatt网络接口中。.\n增加获取信息。."
},
"3.0.4": {
"en": "No retrieval of the other parameters value possible after parameter error.\nSetting Grid first and Battery first setting on MIX improved.\nSetting for tlx/tlxh time improved.",
Expand Down Expand Up @@ -54,19 +54,6 @@
"pl": "Struktura kalendarzowa nie zawsze była zmieniana na znaczek czasowy.\nPoprawa w wewnętrznej obsługi obiektów bez uwzględniania ich sprawy.\n",
"uk": "Структура календаря не завжди була змінена на час.\nУдосконалення внутрішніх робіт об’єктів без розгляду справи.\n",
"zh-cn": "降级结构并不总是随着时间推移而改变。.\n改进物体的内部处理,而不考虑其情况。.\n"
},
"2.1.0": {
"en": "TLX Hybrid is now working.\nStatus data now also from TLX/TLXH.\nIf there are different inverters, these are now shown.",
"de": "TLX Hybrid arbeitet jetzt.\nStatusdaten nun auch von TLX/TLXH.\nSind verschiedene Wechselrichter vorhanden, werden diese nun angezeigt.",
"ru": "ТЛС Гибрид теперь работает.\nДанные о состоянии теперь также от TLX/TLXH.\nЕсли есть разные инверторы, они теперь показаны.",
"pt": "TLX O híbrido está a funcionar.\nDados de status agora também de TLX/TLXH.\nSe houver inversores diferentes, estes são agora mostrados.",
"nl": "TLX Hybrid werkt nu.\nStatus gegevens van TLTLXH.\nAls er verschillende inverters zijn, zijn deze nu getoond.",
"fr": "TLX Hybrid travaille maintenant.\nLes données de statut sont maintenant également de TLX/TLXH.\nS'il y a différents inverseurs, ils sont maintenant montrés.",
"it": "TLX Hybrid sta lavorando.\nDati di stato ora anche da TLX/TLXH.\nSe ci sono diversi inverter, questi sono ora mostrati.",
"es": "TLX híbrido está funcionando.\nDatos de estado ahora también de TLX/TLXH.\nSi hay diferentes inversores, estos se muestran ahora.",
"pl": "TLX Obecnie pracuje Hybrid.\nDane statystyczne pochodzą z TLX/TLXH.\nJeśli istnieją różne odwzorowania, są one teraz pokazane.",
"uk": "ТЛКС Гібрид тепер працює.\nСтатус на сервери.\nЯкщо є різні інвертори, це зараз показано.",
"zh-cn": "B. 建 议 目前正努力解决这一问题。.\n现状数据现在也来自TLX/TLXH。.\n如果有不同的防污者,现在就有这种资料。."
}
},
"titleLang": {
Expand Down
Loading

0 comments on commit 6242e90

Please sign in to comment.