Skip to content

Commit

Permalink
Added switch to enable/disable forced charging
Browse files Browse the repository at this point in the history
  • Loading branch information
NoBl committed Oct 10, 2023
1 parent 4438b44 commit 4e2bbb6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
44 changes: 40 additions & 4 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -250,14 +263,16 @@
"api_pwd": ""
},
"objects": [],
"instanceObjects": [{
"instanceObjects": [
{
"_id": "info",
"type": "channel",
"common": {
"name": "Information"
},
"native": {}
}, {
},
{
"_id": "info.connection",
"type": "state",
"common": {
Expand All @@ -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": {}
}
]
}
37 changes: 37 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -353,6 +389,7 @@ class Senec extends utils.Adapter {
);
});
}


/**
* Read values from Senec Home V2.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.senec",
"version": "1.6.7",
"version": "1.6.8",
"description": "Senec Home",
"author": {
"name": "NoBl",
Expand Down

2 comments on commit 4e2bbb6

@dispo112
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I'm absolutely thrilled about this feature (I'm also a Tibber customer) THANK YOU! But how did you change your stance on this feature? Upfront on the website, it still says, "The integration of the manual safety charge function was deliberately omitted.

@nobl
Copy link
Owner

@nobl nobl commented on 4e2bbb6 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest: It has to do with how the company tries to "improve" stuff :)

Please sign in to comment.