diff --git a/.github/workflows/rules-vm-255.yml b/.github/workflows/rules-vm-255.yml index 3e3c9cc9..dfcc30c6 100644 --- a/.github/workflows/rules-vm-255.yml +++ b/.github/workflows/rules-vm-255.yml @@ -5,6 +5,7 @@ on: branches: - feature/rules-255-variable-slots - experiment/rules-255-compact-bytecode + - test/2611-13-parameter-handoff pull_request: paths: - 'HeishaMon/src/rules/**' @@ -22,6 +23,10 @@ jobs: run: bash Examples/Rules/Variable-Slot-Limits/test_variable_slots.sh - name: Reject oversized compact-bytecode jumps run: bash Examples/Rules/Variable-Slot-Limits/test_jump_offsets.sh + - name: Parse two-part TaShift 2611.13 with the real Rules VM + run: HARNESS_VERBOSE=1 ./Examples/Rules/harness/harness Examples/Rules/tests/2611_13_parameter_handoff.rules parse + - name: Exercise positional parameter and conditional Z1 command + run: ./Examples/Rules/harness/harness Examples/Rules/tests/2611_13_parameter_test.rules Examples/Rules/tests/2611_13_parameter_test.scenario - name: Fetch current reference Rules uses: actions/checkout@v4 with: diff --git a/Examples/Rules/tests/2611_13_parameter_handoff.rules b/Examples/Rules/tests/2611_13_parameter_handoff.rules new file mode 100644 index 00000000..99e68370 --- /dev/null +++ b/Examples/Rules/tests/2611_13_parameter_handoff.rules @@ -0,0 +1,459 @@ +on System#Boot then + print('BLB Heishamon_rules_2611.13.lua'); + #chEnableOnMin = -1; + #chEnableChangeTime = -1; + #chEnableTimeOff = -1; + #CompFreqTarget = -1; + #CompRunSec = -1; + #CompRunMin = -1; + #CoolingEnable = -1; + #DHWComfortDay = 4; + #DHWRun = -1; + #DHWSterilizationDay = 7; + #Heat = -1; + #OMP = -1; + #QMR = -1; + #PIDintegral = 0; + #RoomTempDelta = 0; + #RoomTempControl = 0; + #TaPIStepTime = -1; + setTimer(1,10); +end + +on timer=1 then + if isset(@Heatpump_State) && isset(@Operating_Mode_State) && isset(@Outside_Temp) && isset(@Z1_Heat_Request_Temp) && isset(@Compressor_Freq) && isset(?roomTempSet) && isset(?roomTemp) && isset(?chEnable) then + #Time = %day * 1440 + %hour * 60 + %minute; + #CompStateChangeTime = #Time; + #chEnableChangeTime = #Time; + #HPStateR = @Heatpump_State; + #HPStateP = @Heatpump_State; + #OMR = @Operating_Mode_State; + #OutsideTemp = @Outside_Temp; + #RoomSetpoint = min(max(?roomTempSet, 10), 22); + #RoomTemp = ?roomTemp; + #WCS = @Z1_Heat_Request_Temp; + if @Compressor_Freq > 18 then + #CompState = 2; + #TaPIStepTime = #Time; + #CompRunSec = 1999; + else + #CompState = 0; + end + if @ThreeWay_Valve_State then + #DHWRun = 3; + end + #chEnable = ?chEnable; + #DHWTempP = @DHW_Temp; + setTimer(2,10); + setTimer(3,25); + setTimer(4,30); + setTimer(5,35); + setTimer(6,40); + setTimer(7,45); + setTimer(8,50); + setTimer(9,55); + setTimer(10,22); + else + print('timer=1: waiting for HP/OT values'); + setTimer(1,5); + end +end + +on timer=2 then + setTimer(2,60); + #Time = %day * 1440 + %hour * 60 + %minute; + $CompElapsed = (#Time - #CompStateChangeTime + 10080) % 10080; + if @Compressor_Freq > 10 then + #CompRunMin = $CompElapsed; + else + #CompRunMin = 0 - $CompElapsed; + end +end + +on @Compressor_Freq then + if @Compressor_Freq > 10 && #CompState == 0 then + #CompStateChangeTime = #Time; + #CompState = 1; + #CompRunSec = 0; + #CompRunMin = 0; + #TaPIStepTime = -1; + setTimer(11,1); + elseif @Compressor_Freq < 10 && #CompState > 0 then + #CompStateChangeTime = #Time; + #CompState = 0; + #CompRunMin = 0; + #TaDeltaTimer = 0; + #TaPIStepTime = -1; + end +end + +on @Main_Outlet_Temp then + if isset(#Time) then + TaShift(); + end +end + +on timer=3 then + if #CompRunSec < 150 || #TaDeltaTimer > 0 then + setTimer(3,15); + else + setTimer(3,60); + end + TaShift(); +end + +on TaShift then + if @Defrosting_State == 1 then + #TaPIStepTime = -1; + end + #NoDefrost = @Defrosting_State == 0 || (@Pump_Flow > 5 && @Pump_Flow < 30); + if #Heat == 1 && @ThreeWay_Valve_State == 0 && #DHWRun < 2 && #NoDefrost == 1 then + if #CompState > 0 then + $WCS = #WCS + min(max(@Z2_Heat_Request_Temp - 20,-5), 5); + #TaDelta = @Main_Outlet_Temp - @Z1_Heat_Request_Temp; + if #OutsideTemp > 7 && #CompRunSec < 130 && #CompRunSec != -1 then + #SHifT = ceil(@Main_Outlet_Temp) - 3 - $WCS; + elseif @Compressor_Freq < 21 && max(#RoomTempControl, + ceil(@Main_Outlet_Temp - 1.9 - $WCS)) < #SHifT then + print('no #SHifT required'); + else + #SHifT = max(#RoomTempControl,ceil(@Main_Outlet_Temp - 1.9 - $WCS)); + end + if #TaDelta < 2 then + #TaDeltaTimer = 0; + elseif #TaDeltaTimer == 0 then + #TaDeltaTimer = 10; + setTimer(12,10); + elseif #TaDeltaTimer >= 80 then + #SHifT = ceil(@Main_Outlet_Temp - 1.8 - $WCS); + end + if #TaDelta >= 3 then + #SHifT = ceil(@Main_Outlet_Temp) - 2 - $WCS; + end + elseif (%hour < 7 || %hour > 22 || #RoomTempDelta > 0.2) then + #SHifT = -5; + elseif #CompRunMin > (-2 * #OutsideTemp - 30) && (#RoomTempDelta > 0.1 || (#RoomTempDelta > 0 && #SHifT == -5)) then + #SHifT = -5; + else + #SHifT = 0; + end + #SHifT = min(max(#SHifT, -5), 5); + #Z1HRT = coalesce($WCS, #WCS) + #SHifT; + if #CompState > 0 then + #Z1HRT = min(#Z1HRT, max($WCS - 5, ceil(@Main_Outlet_Temp) - 1)); + end + TaShift2($WCS); + end +end + +on timer=4 then + setTimer(4,60); + if @Sterilization_State == 0 && #DHWRun < 2 then + if #Heat == 1 && @ThreeWay_Valve_State == 0 && @Defrosting_State == 0 then + $OverNight = %hour > 22 || %hour < 3; + $chEnableCondition = #chEnable && #chEnableOnMin > 60 && #CompRunMin < -60 && $OverNight != 1; + + if #chEnable == 1 && (((#RoomTempDelta < 0.2 || %hour == 7) && #OutsideTemp < 11) || (#RoomTempDelta < 1 && #OutsideTemp < 2) || #RoomTempDelta < 0 || ($chEnableCondition == 1 && #RoomTempDelta < 2)) && #HPStateR != 1 then + #HPStateR = 1; + + elseif ((#RoomTempDelta > 0.2 && %hour > 9) || #RoomTempDelta > 1.5 || (#chEnable == 0 && #chEnableOnMin < -30)) && (#CompRunMin > 60 || #CompState == 0 || $OverNight) && (#OutsideTemp > 4 || (#chEnable == 0 && $OverNight)) && $chEnableCondition == 0 && #HPStateR != 0 then + #HPStateR = 0; + if #OMR != 0 && #OMR != 3 then + #OMR = 0; + end + end + end + + $CoolingEnable = max(round(#CoolingEnable),0); + if $CoolingEnable == 1 then + #OMR = 1; + #HPStateR = 1; + $CoolForce = 0; + if #CompState == 1 then + $CoolReqTempMin = min(round(@Main_Outlet_Temp), 19); + else + $CoolReqTempMin = 0; + if @Main_Outlet_Temp > (@Main_Target_Temp + 3) then + $CoolForce = -2; + end + end + + $CoolingControl = max((?coolingControl + $CoolForce), 12, $CoolReqTempMin); + if @Z1_Cool_Request_Temp != $CoolingControl then + @SetZ1CoolRequestTemperature = $CoolingControl; + end + elseif $CoolingEnable == 0 && #OMR == 1 && #DHWRun < 2 && #CompState == 0 then + #OMR = 0; + #HPStateR = 0; + end + end +end + +on timer=5 then + setTimer(5,900); + if @Defrosting_State == 0 && ?dhwEnable then + $DHWTime = 13; + if (%month > 3 && %month < 9) && %hour == 8 && #OutsideTemp > 20 then + $DHWTime = 8; + elseif #OutsideTemp < 4 then + $DHWTime = 0; + end + $DHW10Condition = @DHW_Temp <= (@DHW_Target_Temp + @DHW_Heat_Delta - 10); + $DHW9hCondition = @DHW_Temp <= (@DHW_Target_Temp + @DHW_Heat_Delta - 5) || @DHW_Temp < (#DHWTempP - 5); + $DHWTimeCondition = (%day == #DHWSterilizationDay && @DHW_Temp < 50) || (%day == #DHWComfortDay && @DHW_Temp < (@DHW_Target_Temp - 3)) || (@DHW_Temp < (@DHW_Target_Temp + @DHW_Heat_Delta)); + if #DHWRun < 1 && @ThreeWay_Valve_State == 0 && (($DHW10Condition) || (%hour >= 9 && ($DHW9hCondition)) || (%hour == $DHWTime && ($DHWTimeCondition))) then + #DHWRun = 2; + #OMP = @Operating_Mode_State; + #HPStateP = @Heatpump_State; + if #OMP == 0 then + #OMR = 4; + elseif #OMP == 1 then + #OMR = 5; + else + #OMR = 3; + end + #HPStateR = 1; + elseif #DHWRun > 0 && #DHWRun < 3 then + if %day > (#DHWSterilizationDay - 2) && @ThreeWay_Valve_State == 1 && #CompState > 0 && @Sterilization_State != 1 then + @SetForceSterilization = 1; + #DHWSterilizationDay = #DHWSterilizationDay + 10; + elseif @ThreeWay_Valve_State == 0 && @DHW_Temp >= @DHW_Target_Temp && @Defrosting_State == 0 && @Sterilization_State == 1 then + #DHWRun = 1; + elseif @ThreeWay_Valve_State == 0 && @DHW_Temp >= @DHW_Target_Temp && @Defrosting_State == 0 && @Sterilization_State == 0 then + #OMR = max(0,#OMP); + #OMP = @Operating_Mode_State; + #HPStateR = #HPStateP; + #HPStateP = 1; + #DHWRun = 0; + #TaPIStepTime = -1; + #TaDeltaTimer = 0; + #TaDelta = 0; + end + end + if %day == (#DHWSterilizationDay - 10) && %hour > 15 then + #DHWSterilizationDay = #DHWSterilizationDay - 10; + end + #DHWTempP = @DHW_Temp; + end +end + +on timer=6 then + setTimer(6, 60); + $MaxPumpDuty = 102 - 4 * @Heat_Delta; + if @ThreeWay_Valve_State == 1 then + $MaxPumpDuty = 140; + if (@Sterilization_State == 0 && @DHW_Temp > @DHW_Target_Temp) || (@Sterilization_State == 1 && @DHW_Temp > 57) then + $MaxPumpDuty = $MaxPumpDuty - 10; + end + elseif @Operating_Mode_State == 1 then + $MaxPumpDuty = 92; + elseif @Heatpump_State == 1 then + if @Compressor_Freq == 0 && @Defrosting_State != 1 then + $MaxPumpDuty = 112 - 4 * @Heat_Delta; + else + $MaxPumpFlow = min(max(ceil(10 + (11 - #OutsideTemp) * 6 / 14), 10), 16); + if @Pump_Flow > 1 && @Pump_Flow < 8 && $MaxPumpDuty <= @Max_Pump_Duty then + $MaxPumpDuty = @Max_Pump_Duty + 1; + else + $MaxPumpDuty = 55 + floor($MaxPumpFlow * 3); + if (@Pump_Speed / @Pump_Flow) > 145 then + if @Pump_Flow > 8 then + $MaxPumpDuty = @Max_Pump_Duty - 1; + else + $MaxPumpDuty = @Max_Pump_Duty; + end + end + end + end + end + $MaxPumpDuty = max($MaxPumpDuty, 82); + if @Max_Pump_Duty != $MaxPumpDuty then + @SetMaxPumpDuty = $MaxPumpDuty; + end +end + +on timer=7 then + setTimer(7,120); + #CompFreqTarget = min(max(ceil(24 + (6 - #OutsideTemp) * 30 / 9), 24), 54); + if @Defrosting_State == 1 || #CompState < 1 || #CompRunMin < 5 || %hour < 7 || @Operating_Mode_State == 1 then + #QMR = 3; + elseif @Compressor_Freq < #CompFreqTarget || (#QMR == 0 && @Compressor_Freq < #CompFreqTarget + 6) then + #QMR = 0; + elseif @Compressor_Freq < #CompFreqTarget + 6 || (#QMR == 1 && @Compressor_Freq < #CompFreqTarget + 12) then + #QMR = 1; + elseif @Compressor_Freq < #CompFreqTarget + 26 || (#QMR == 2 && @Compressor_Freq < #CompFreqTarget + 32) then + #QMR = 2; + else + #QMR = 3; + end + $QMDHW = 0; + if #QMR > 0 && @ThreeWay_Valve_State && %hour > 9 && %hour < 17 then + $QMDHW = -1; + end + if @Buffer_Tank_Delta < 4 then + @SetQuietMode = @Buffer_Tank_Delta; + elseif #QMR != @Quiet_Mode_Level then + @SetQuietMode = #QMR + $QMDHW; + end +end + +on timer=8 then + setTimer(8,30); + ?outletTemp = round(@Main_Outlet_Temp); + ?inletTemp = round(@Main_Inlet_Temp); + ?outsideTemp = round(#OutsideTemp); + ?dhwTemp = round(@DHW_Temp); + ?dhwSetpoint = @DHW_Target_Temp; + #CoolingEnable = #CoolingEnable + 0.1 * (?CoolingEnable - #CoolingEnable); + #RoomSetpoint = min(max(?roomTempSet, 10), 22); + #RoomTemp = ?roomTemp; + #RoomTempDelta = #RoomTemp - #RoomSetpoint; + if gpio(33) == 1 then + #chEnableTimeOff = -1; + if (#RoomTempDelta < 0 && #chEnable == 0) || (#RoomTempDelta > 0.2 && #chEnable == 1) then + #chEnable = 1 - #chEnable; + #chEnableChangeTime = #Time; + end + else + if ?chEnable == 1 then + #chEnableTimeOff = -1; + if #chEnable == 0 then + #chEnableChangeTime = #Time; + #chEnable = 1; + end + else + if #chEnableTimeOff < 0 then + #chEnableTimeOff = #Time; + end + $chEnableOffElapsed = (#Time - #chEnableTimeOff + 10080) % 10080; + if $chEnableOffElapsed > 15 && #chEnable == 1 then + #chEnable = 0; + #chEnableChangeTime = #Time; + end + end + end + $chEnableElapsed = (#Time - #chEnableChangeTime + 10080) % 10080; + if #chEnable == 1 then + #chEnableOnMin = $chEnableElapsed; + else + #chEnableOnMin = 0 - $chEnableElapsed; + end + ?maxTSet = #WCS + 5; + ?relativeModulation = round(@Compressor_Current / 15 * 100); + if #CompState > 0 then + ?flameState = 1; + if @Heat_Power_Consumption > 0 then + ?chState = 1; + else + ?chState = 0; + end + if @DHW_Power_Consumption > 0 then + ?dhwState = 1; + else + ?dhwState = 0; + end + if @Cool_Power_Consumption > 0 then + ?coolingState = 1; + else + ?coolingState = 0; + end + else + ?flameState = 0; + ?chState = 0; + ?dhwState = 0; + ?coolingState = 0; + end + #OutsideTemp = (#OutsideTemp * 59 + @Outside_Temp) / 60; + if @Operating_Mode_State != #OMR then + @SetOperationMode = #OMR; + end + if @Heatpump_State != #HPStateR && #DHWRun != 3 then + @SetHeatpump = #HPStateR; + end + if @Operating_Mode_State == 0 || @Operating_Mode_State == 4 then + #Heat = 1; + else + #Heat = 0; + end +end + +on timer=9 then + setTimer(9,300); + $Kp = 1.2; + $Ki = 0.05; + $Ilimit = 5; + $PIlimit = 5; + if #DHWRun < 1 && @ThreeWay_Valve_State == 0 && ?roomTempSet > 12 && #RoomSetpoint > 12 then + $RoomError = #RoomTempDelta * -1; + $PIp = $Kp * $RoomError; + if #chEnable == 1 && #Heat == 1 && #DHWRun < 2 && @ThreeWay_Valve_State == 0 && @Defrosting_State == 0 && #RoomTempDelta <= 0.2 then + $PIintegralNext = min(max(#PIDintegral + $Ki * $RoomError, $Ilimit * -1), $Ilimit); + $PIcandidate = $PIp + $PIintegralNext; + if ($PIcandidate <= $PIlimit || $RoomError <= 0) && ($PIcandidate >= $PIlimit * -1 || $RoomError >= 0) then + #PIDintegral = $PIintegralNext; + end + end + $PIoutput = $PIp + #PIDintegral; + #RoomTempControl = round(min(max($PIoutput, $PIlimit * -1), $PIlimit)); + end +end + +on timer=10 then + setTimer(10,1800); + $Ta1 = @Z1_Heat_Curve_Target_Low_Temp; + $Ta2 = 36; + $Tb1 = @Z1_Heat_Curve_Outside_High_Temp; + $Tb2 = @Z1_Heat_Curve_Outside_Low_Temp; + + #WCS = min(max(ceil($Ta1 + ($Tb1 - #OutsideTemp) * ($Ta2 - $Ta1) / ($Tb1 - $Tb2)), $Ta1), $Ta2); +end + +on timer=11 then + #CompRunSec = #CompRunSec + 5; + if #CompRunSec < 1100 then + setTimer(11,5); + end +end + +on timer=12 then + if #TaDeltaTimer < 200 && #TaDelta >= 2 then + #TaDeltaTimer = #TaDeltaTimer + 10; + setTimer(12, 10); + end +end + +on TaShift2($WCS) then + if #CompState > 0 && @Defrosting_State == 0 && @Z2_Heat_Request_Temp <= 25 then + if #TaPIStepTime >= 0 then + #Z1HRT = @Z1_Heat_Request_Temp; + end + if (#OutsideTemp <= 7 || #CompRunSec >= 130 || #CompRunSec == -1) && ((#TaPIStepTime < 0 && (#CompRunMin >= 15 || (#CompRunMin >= 2 && @Compressor_Freq <= #CompFreqTarget))) || (#TaPIStepTime >= 0 && ((#Time - #TaPIStepTime + 10080) % 10080 >= 15 || ((#Time - #TaPIStepTime + 10080) % 10080 >= 10 && @Compressor_Freq <= #CompFreqTarget)))) then + if $WCS + #RoomTempControl > @Z1_Heat_Request_Temp then + #Z1HRT = min(@Z1_Heat_Request_Temp + 1, $WCS + #RoomTempControl); + elseif $WCS + #RoomTempControl < @Z1_Heat_Request_Temp && @Main_Outlet_Temp <= @Z1_Heat_Request_Temp + 0.8 then + #Z1HRT = max(@Z1_Heat_Request_Temp - 1, $WCS + #RoomTempControl); + else + #Z1HRT = @Z1_Heat_Request_Temp; + end + if #TaPIStepTime < 0 || #Z1HRT != @Z1_Heat_Request_Temp then + #TaPIStepTime = #Time; + end + end + if #TaPIStepTime >= 0 then + if #TaDeltaTimer >= 80 && ceil(@Main_Outlet_Temp - 1.8) > @Z1_Heat_Request_Temp then + #Z1HRT = max(#Z1HRT, min(@Z1_Heat_Request_Temp + 1, ceil(@Main_Outlet_Temp - 1.8))); + #TaPIStepTime = #Time; + end + if #TaDelta >= 3 && ceil(@Main_Outlet_Temp) - 2 > @Z1_Heat_Request_Temp then + #Z1HRT = max(#Z1HRT, min(@Z1_Heat_Request_Temp + 1, ceil(@Main_Outlet_Temp) - 2)); + #TaPIStepTime = #Time; + end + end + end + if @Z2_Heat_Request_Temp > 25 then + #Z1HRT = @Z2_Heat_Request_Temp; + end + if #Z1HRT != @Z1_Heat_Request_Temp then + @SetZ1HeatRequestTemperature = #Z1HRT; + end +end diff --git a/Examples/Rules/tests/2611_13_parameter_test.rules b/Examples/Rules/tests/2611_13_parameter_test.rules new file mode 100644 index 00000000..b6150167 --- /dev/null +++ b/Examples/Rules/tests/2611_13_parameter_test.rules @@ -0,0 +1,17 @@ +on System#Boot then + #CompState = 1; + #WCS = 30; + TaShift2(31); + #CompState = 0; + #Z1HRT = 27; + TaShift2($unused); +end + +on TaShift2($WCS) then + if #CompState > 0 then + #Z1HRT = $WCS; + end + if #Z1HRT != @Z1_Heat_Request_Temp then + @SetZ1HeatRequestTemperature = #Z1HRT; + end +end diff --git a/Examples/Rules/tests/2611_13_parameter_test.scenario b/Examples/Rules/tests/2611_13_parameter_test.scenario new file mode 100644 index 00000000..debece15 --- /dev/null +++ b/Examples/Rules/tests/2611_13_parameter_test.scenario @@ -0,0 +1,5 @@ +silent Z1_Heat_Request_Temp 30 +boot +expectcmd SetZ1HeatRequestTemperature 31 +expectcmd SetZ1HeatRequestTemperature 27 +expectnone