@tomstephie Hallo Thomas,
ich poste hier gerne mal meine Steuerung der Wallbox auf Basis des Moduls von @zap
Bei der Wallbox habe ich eingestellt, dass eine Freigabe durch die App erfolgen muss bevor der Ladevorgang startet. Dadurch kann ich erstmal in Ruhe alle gewünschten Parameter setzen und dann die Wallbox freischalten.
Bei mir gibt es verschiedene Modi:
- Schnellladen (Vollgas)
- Kein Laden
- Bei PV-Überschuss
- Morgen früh voll
Morgen früh voll ist mein Standard-Modus unter der Woche: ich komme am frühen Abend nach Hause, das Auto lädt alles was an Sonne im Überschuss ist, und macht dann Nachts, wenn die Tibber-Preise günstig sind, das Auto voll. Die verschiedenen Modi hängen dann natürlich von deinem Setup ab, ich beschreibe hier unten einmal das Beispiel PV-Überschuss.
Die Funktion für PV-Überschuss, die alle fünf Minuten getriggert wird:
// unit: Watt
let freeCapacity = 0;
// free capacity is what we are outputting to the grid and what we are charging to the batteries
// we have to consider that the charging process is ongoing and, therefore, also add this as free capacity
// otherwise the car will stop charging and start again, toggeling on and off
// what we are putting into the grid
let gridOutput = getState('modbus.0.inputRegisters.30867_HousePowerOut').val;
// what we are taking from the grid
let gridInput = getState('modbus.0.inputRegisters.30865_HousePowerIn').val;
// what we are charging to the battery
let batteryCharging = getState('modbus.2.inputRegisters.31393_Charge').val;
// what we are taking from the battery
let batteryDisCharging = getState('modbus.2.inputRegisters.31395_Discharge').val;
// battery level in percent
let batteryLevel = getState('modbus.2.inputRegisters.30845_LevelPercent').val;
// what is available? all that we put into the grid, but not the discharge from the battery
freeCapacity = gridOutput - gridInput - batteryDisCharging;
// we want to first charge the battery to 20% before we start charging the car
if(batteryLevel >= 20) {
// if we have at least 20%, then we decide to prioritize charging the car
// therefore, we add the batteryCharging to the freeCapacity
freeCapacity += batteryCharging;
}
// calculate the current in amps (one phase only in this case)
let freeCurrent = Math.floor(freeCapacity / 230);
// now we add what we already charge at this moment
let currentPower = getState('sma-ev-charger.0.measurement.MeteringGridMsTotWIn').val;
let currentCurrent = Math.round(currentPower / 230);
freeCurrent += currentCurrent;
if(!chargingComplete)
setChargeToWallbox(freeCurrent);
// if charging was complete, allow full power for heating/cooling
else
setChargeToWallbox(upper);
Und hier die Funktion setChargeToWallbox, fürs Debugging habe ich da noch ein paar Telegram-Messages drin
function setChargeToWallbox(current) {
// only setCharge if last set is more than 60 seconds ago
if(Date.now() - lastSetChargeToWallbox < 60 * 1000) {
return;
}
// lowest limit (usually 6 amps)
let lower = getState('0_userdata.0.wallbox.minimumCurrent').val;
// upper limit (usually 16 amps)
let upper = getState('0_userdata.0.wallbox.maximumCurrent').val;
let finalCurrent = current;
let charge = true;
if(finalCurrent < lower)
charge = false;
if(finalCurrent > upper)
finalCurrent = upper;
// lets check status of wallbox, locked or not?
let state = getState('sma-ev-charger.0.measurement.OperationEVehChaStt').val;
// start stop mode
// 4721 -> stop
// 4718 -> start
let startStop = getState('sma-ev-charger.0.parameter.ChrgActChaMod').val;
let currentCurrent = getState('sma-ev-charger.0.parameter.InverterAcALim').val;
// station is locked
if(state == 5169) {
// unlock, if charging should start
if(charge) {
sendTo('telegram', 'Activating locked station with ' + finalCurrent);
lastSetChargeToWallbox = Date.now();
setState('sma-ev-charger.0.parameter.InverterAcALim', finalCurrent);
// activate 5 seconds later, so that current is already set correctly
setTimeout(() => {
setState('sma-ev-charger.0.parameter.ChrgChrgApv', 5172);
}, 5000);
}
else {
// do nothing
}
}
// car is unplugged, we do nothing
else if(state == 200111) {
}
// car has stopped charging, either because car is fully charged, or process was stopped
else if(state == 200112) {
// we are stopped (manually)
// we should charge, so we activate the station again
if(charge && startStop == 4721) {
sendTo('telegram', 'Activating stopped station with ' + finalCurrent);
// set current
lastSetChargeToWallbox = Date.now();
setState('sma-ev-charger.0.parameter.InverterAcALim', finalCurrent);
// activate 5 seconds later, so that current is already set correctly
setTimeout(() => {
setState('sma-ev-charger.0.parameter.ChrgActChaMod', 4718);
}, 5000);
}
}
// car is charging
else if(state == 200113) {
// we can/should NOT charge
if(!charge) {
// charging is in active mode, so we stop
if(startStop == 4718) {
sendTo('telegram', 'Stopping activated station');
lastSetChargeToWallbox = Date.now();
setState('sma-ev-charger.0.parameter.ChrgActChaMod', 4721);
}
}
// we should charge
if(charge) {
// check if current is correct, if not, change it
if(finalCurrent != currentCurrent) {
sendTo('telegram', 'Updating current from ' + currentCurrent + ' to ' + finalCurrent);
lastSetChargeToWallbox = Date.now();
setState('sma-ev-charger.0.parameter.InverterAcALim', finalCurrent);
}
}
}
}
Hoffe, das hilft dir für deine eigenen Skripts weiter.
Grüße!
DrB