From 4e2bbb6260157ec4663bb2830409c297682233db Mon Sep 17 00:00:00 2001 From: NoBl Date: Wed, 11 Oct 2023 00:48:19 +0200 Subject: [PATCH] Added switch to enable/disable forced charging --- README.md | 3 +++ io-package.json | 44 ++++++++++++++++++++++++++++++++++++++++---- main.js | 37 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 81 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 63c0788..4371ee7 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,9 @@ This channel contains values polled from SENEC App-API. ## Changelog +### 1.6.8 (NoBl) +* Added switch control.ForceLoadBattery to start/stop charging battery. Use this to start/stop forced charging (like with dynamic power prices, ...). + ### 1.6.7 (NoBl) * Added option to turn off local polling. diff --git a/io-package.json b/io-package.json index 84a2576..fccadf1 100644 --- a/io-package.json +++ b/io-package.json @@ -1,8 +1,21 @@ { "common": { "name": "senec", - "version": "1.6.7", + "version": "1.6.8", "news": { + "1.6.8": { + "en": "Added switch control.ForceLoadBattery to start/stop charging battery. Use this to start/stop forced charging (like with dynamic power prices, ...).", + "de": "Schalter control.ForceLoadBattery hinzugefügt, um ein Laden des Speichers zu forcieren (analog zur Funktion im lokalen Interface). Nützlich in Verbindung mit dynamischen Stromtarifen, etc.", + "ru": "Добавлен контроль переключателя. СилаLoad Батарея для начала / остановки зарядки батареи. Используйте это для начала / остановки принудительного зарядки (например, с динамическими ценами питания, ...).", + "pt": "Adicionado controle de interruptor. Força Bateria para iniciar / parar de carregar bateria. Use isso para iniciar / parar de carga forçada (como com preços de energia dinâmica, ...).", + "nl": "Veranderingscontrole. Force Batterijen om te starten/ stop met batterijen. Gebruik dit om te beginnen en stop met het opladen van dynamische krachtprijzen.", + "fr": "Ajout de la commande. ForceLoad Batterie de démarrage/arrêt de batterie de charge. Utilisez ceci pour commencer / arrêter la charge forcée (comme avec les prix de puissance dynamique, ...).", + "it": "Aggiunta di controllo dell'interruttore. Forza! Batteria per avviare / fermare la batteria di ricarica. Utilizzare questo per avviare / fermare la ricarica forzata (come con i prezzi di potenza dinamica, ...).", + "es": "Control de cambio añadido. ForceLoad Batería para iniciar / detener la batería de carga. Utilice esto para iniciar / detener la carga forzada (como con los precios de potencia dinámicos, ...).", + "pl": "Kontrola przełącznikowa. ForceLoad Bateria rozpoczynająca/zatrzymanie baterii. Wykorzystuje to do rozpoczęcia/stopowania (jak z dynamicznymi cenami mocy).", + "uk": "Додано контроль перемикання. Приват24 Акумулятор для запуску / зарядки акумулятора. Використовуйте це для запуску / stop примусової зарядки (наприклад, з динамічними цінами потужності, ...).", + "zh-cn": "添加了转换控制。 部队 开始/禁止劫持电池。 利用这开始/禁止强迫征集(与动态发电价格相似,......)。." + }, "1.6.7": { "en": "Added option to turn off local polling.", "de": "Option hinzugefügt, um die lokale Abfrage der Appliance abzuschalten.", @@ -250,14 +263,16 @@ "api_pwd": "" }, "objects": [], - "instanceObjects": [{ + "instanceObjects": [ + { "_id": "info", "type": "channel", "common": { "name": "Information" }, "native": {} - }, { + }, + { "_id": "info.connection", "type": "state", "common": { @@ -269,6 +284,27 @@ "def": false }, "native": {} - } + }, + { + "_id": "control", + "type": "channel", + "common": { + "name": "Control Buttons" + }, + "native": {} + }, + { + "_id": "control.ForceLoadBattery", + "type": "state", + "common": { + "role": "switch", + "name": "Force Load Battery", + "type": "boolean", + "read": true, + "write": true, + "def": false + }, + "native": {} + } ] } diff --git a/main.js b/main.js index 1bc8bde..71a9b66 100644 --- a/main.js +++ b/main.js @@ -22,6 +22,9 @@ const apiLoginUrl = apiUrl + "/login"; const apiSystemsUrl = apiUrl + "/anlagen"; const apiKnownSystems = [] +const batteryOn = '{"ENERGY":{"SAFE_CHARGE_FORCE":"u8_01"}}'; +const batteryOff = '{"ENERGY":{"SAFE_CHARGE_PROHIBIT":"u8_01"}}'; + let apiConnected = false; let lalaConnected = false; let apiLoginToken = ""; @@ -50,6 +53,7 @@ class Senec extends utils.Adapter { name: 'senec', }); this.on('ready', this.onReady.bind(this)); + this.on('stateChange', this.onStateChange.bind(this)); this.on('unload', this.onUnload.bind(this)); } @@ -84,16 +88,48 @@ class Senec extends utils.Adapter { } else { this.log.warn("Usage of SENEC App API not configured. Only polling appliance via local network if configured."); } + if (lalaConnected || apiConnected) { this.setState('info.connection', true, true); } else { this.log.error("Neither local connection nor API connection configured. Please check config!"); } + await this.subscribeStatesAsync("control.*"); // subscribe on all state changes in control. } catch (error) { this.log.error(error); this.setState('info.connection', false, true); } } + + /** + * @param {string} id + * @param {ioBroker.State | null | undefined} state + */ + onStateChange(id, state) { + if (state && !state.ack) { + this.log.debug("State changed: " + id + " ( " + JSON.stringify(state) + " )"); + + if (id === this.namespace + '.control.ForceLoadBattery' && lalaConnected) { + const url = connectVia + this.config.senecip + '/lala.cgi'; + try { + if (state.val) { + this.log.info('Enable force battery charging ...'); + this.doGet(url, batteryOn, this, this.config.pollingTimeout, true); + } else { + this.log.info('Disable force battery charging ...'); + this.doGet(url, batteryOff, this, this.config.pollingTimeout, true); + } + } catch (error) { + this.log.error(error); + this.log.error("Failed to control: setting force battery charging mode to " + state.val); + return; + } + } + + // Verarbeitung bestätigen + this.setStateAsync(id, { val: state.val, ack: true }); + } + } /** * Is called when adapter shuts down - callback has to be called under any circumstances! @@ -353,6 +389,7 @@ class Senec extends utils.Adapter { ); }); } + /** * Read values from Senec Home V2.1 diff --git a/package.json b/package.json index 373d339..4b977b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iobroker.senec", - "version": "1.6.7", + "version": "1.6.8", "description": "Senec Home", "author": { "name": "NoBl",