@legro hier das ganze script. Musst halt schauen was für dich sinnvoll ist :). Denn hier wird auch der Speicher in gewissen situationen blockiert ausser die Wärmepunpe läuft (großer verbraucher)
var maxChargeSetpoint = 100; // maximum charge state for charge from grid
var maxDischargeSetpoint = 60; // maximum charge state for stop discharge
var bChargeFromGrid = false; // allow to charge the battery from grid
var minChargeSetpoint = 10;
/*
allow to discharge. This runs the whole year to ensure that once a day the state is correct set to 5%
*/
var allowDischarge = schedule('0 6 * * *', function () {
log("Allow discharge scheduler started!",'debug');
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',minChargeSetpoint,false)
setState('modbus.1.holdingRegisters.1.40358_StorCtl_Mod',0,false) /* Change to normal operation */
log("Minimum charging state is set to " + minChargeSetpoint + "% and discharge allowed",'info')
});
function allowDischargeWP(isStart){
var min_set = getState('modbus.1.holdingRegisters.1.40360_MinRsvPct').val;
var curChargeState = getState('modbus.1.holdingRegisters.1.40361_ChaState').val;
var storMode = getState('modbus.1.holdingRegisters.1.40358_StorCtl_Mod').val;
log("min_set = " + min_set + ", curChargeState = " + curChargeState + ", storMode = " + storMode,'info')
if(storMode > 0 || min_set == minChargeSetpoint || ((curChargeState < minChargeSetpoint+5) && isStart)){
//log("min_set = " + min_set + ", curChargeState = " + curChargeState + ", storMode = " + storMode)
log("Start / Stop des Speichers ist nicht erlaubt!",'info');
return;
}
if(isStart){
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',minChargeSetpoint+1,false); // make sure to set it to 6% and not 5% for above check
log("Speicher ist freigegeben!",'info');
}else if(min_set < curChargeState){
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',curChargeState,false)
log("Speicher ist blockiert!",'info');
}else if(min_set == curChargeState){ // in this case the storage is empty. So change to normal operation
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',minChargeSetpoint,false)
log("Speicher ist leer, umstellung auf Normalbetrieb erfolgt!",'info');
}
}
on({ id: 'javascript.0.Pool.bWaermepumpeBoilerbetrieb', change: 'gt'}, function(obj) {
log("Wärmepumpe Boilerbetrieb hat gestartet",'info');
allowDischargeWP(true);
});
on({ id: 'javascript.0.Pool.bWaermepumpeBoilerbetrieb', change: 'lt'}, function(obj) {
log("Wärmepumpe Boilerbetrieb hat gestoppt",'info');
allowDischargeWP(false);
});
on({ id: 'javascript.0.Pool.bWaermepumpeHeizbetrieb', change: 'gt'}, function(obj) {
log("Wärmepumpe Heizbetrieb hat gestartet",'info');
allowDischargeWP(true);
});
on({ id: 'javascript.0.Pool.bWaermepumpeHeizbetrieb', change: 'lt'}, function(obj) {
log("Wärmepumpe Heizbetrieb hat gestoppt",'info');
allowDischargeWP(false);
});
var chargeFromGrid = schedule('*/15 3-5 * 1,2,11,12 *', function () { /* Aktivieren des Speicher ladens mit Nachstrom */
if (!bChargeFromGrid) { // do not execute later code if chargeFromGrid is disabled
return;
}
var curChargeState = getState('modbus.1.holdingRegisters.1.40361_ChaState').val;
// check if it is needed and time to start charging
var curDate = new Date();
var deltaTime = 5.5 - (curDate.getHours() + curDate.getMinutes()/60); // assuming we need to finish charging at 5:30
var neededTime = (maxChargeSetpoint - curChargeState)/40; // Assuming we are charging 40% per hour
if(curChargeState > (maxChargeSetpoint-10) || neededTime < deltaTime){ // do nothing because it is either not neeed to charge or too early
log("Charging from grid not started because not needed or too early!",'debug');
return
}
// really execute the charging
setState('modbus.1.holdingRegisters.1.40358_StorCtl_Mod'/*Activate hold/discharge/charge storage control mode Bitfield value bit 0: DISCHARGE bit 1: CHARGE*/,2,false); /* Activate charging and discharging limits*/
setState('modbus.1.holdingRegisters.1.40365_OutWRte'/*Percent of max charge rate For force charging it must a negativ value*/,-100,false); /* Charge with maximum possible power*/
//setState('modbus.1.holdingRegisters.1.40365_InWRte',0,false); /* Prevent discharging in that period */
log("Charging from grid is started!",'info')
});
var fullyCharged = schedule('*/5 3-5 * 1,2,11,12 *', function () { /* Stoppen des Speicher ladens mit Nachstrom */
log("Check if battery is charged to requested state, if yes -> stop!",'debug');
var curChargeState = getState('modbus.1.holdingRegisters.1.40361_ChaState').val;
var curChargeCurrent = Number(getState('modbus.1.holdingRegisters.1.40322_3_DCA'/*DC Current*/).val);
var curOperationState = getState('modbus.1.holdingRegisters.1.40358_StorCtl_Mod').val
if(curOperationState > 0){
log("Current charge current is " + curChargeCurrent + " A, charging state = " + curChargeState + " %",'info')
}
if(curOperationState > 0 && curChargeState >= maxChargeSetpoint){
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',curChargeState,false)
setState('modbus.1.holdingRegisters.1.40358_StorCtl_Mod',0,false) /* Change to normal operation */
log("Charging is finished, minimum charging state is set to " + curChargeState + "%",'info')
}
});
var stopDischarge = schedule('*/15 16-20 * 1,2,3,10,11,12 *', function () {
log("Stop discharge scheduler started!",'debug');
var curChargeState = getState('modbus.1.holdingRegisters.1.40361_ChaState').val;
var curDischargePower = getState('modbus.0.holdingRegisters.16432_AverageDischargePower').val;
if(curChargeState <= maxDischargeSetpoint && getState('modbus.1.holdingRegisters.1.40360_MinRsvPct').val <= 6 && curDischargePower < 600){
setState('modbus.1.holdingRegisters.1.40360_MinRsvPct',Math.max(curChargeState-1,5),false)
log("Minimum charging state is set to " + Math.max(curChargeState-1,5) + "%",'info')
}
});
// clear scheduler if script stopped
onStop(function () {
log("Script stopped!",'info');
// stop the scheduler
clearSchedule(allowDischarge);
clearSchedule(stopDischarge);
clearSchedule(chargeFromGrid);
clearSchedule(fullyCharged);
}, 1000 /*ms*/);