It's part of my pass2php script at
https://egregius.be/2016/lua-pass2php-v2-0/
Line 288 till 381.
Operational, messy coded, should try to make it nicer coded but then again, it works for me so why bother
Example of 1 room with comments inline:
Code: Select all
//default temperature of none of the lower lines are true
$Setliving=14.0;
//get a simple variable. 0=normal operation, 1= preheat (not used anymore), 2=manual override
$setpointliving=cget('setpointliving');
//reset the manual override if it's set more than 3 hours ago.
if($setpointliving!=0&&strtotime($t['living_set'])<drieuur){cset('setpointliving',0);$setpointliving=0;}
//if variable is not manual override check the schedule
if($setpointliving!=2){
//check if outside temperature is lower than 20°, the dummy switch 'heating' is on and the windows of the room is closed
if($buiten_temp<20&&$s['heating']=='On'&&$s['raamliving']=='Closed'){
//if above is all true risen the setpoint to 17°
$Setliving=17.0;
//if time of day is between 3:00 and 18:00 check is dummy switch 'sleep' is on, if true rise to 20.5°
if(time>=strtotime('3:00')&&time<strtotime('18:00'))$s['slapen']=='Off'?$Setliving=20.5:$Setliving=17.0;
//else if time is between 18:00 and 22:30 rise temp to 21°
elseif(time>=strtotime('18:00')&&time<strtotime('22:30'))$s['slapen']=='Off'?$Setliving=21:$Setliving=17.0;
}
//Finally is all above is done and the variable is other then the virtual setpoint of the room update the setpoint in domoticz to the new value
if($s['living_set']!= $Setliving){
ud($i['living_set'],0,$Setliving,'Rliving_set');
$s['living_set']=$Setliving;
}
}
Let's do some magic on all rooms:
Code: Select all
//arrays of all the rooms, and the rooms that are heated by the gas burner
$kamers=array('living','badkamer','tobi','alex','kamer');
$kamersgas=array('living','tobi','alex','kamer');
//set a variable really high
$bigdif=100;
//state of the gas burner
$brander=$s['brander'];
//last update time of the burner
$Tbrander=strtotime($t['brander']);
//idx of the bruner
$Ibrander=$i['brander'];
//loop thru all rooms
foreach($kamers as $kamer){
//set a variable with the difference between real temperature and setpoint, round the number to 1 decimal place.
${'dif'.$kamer}=number_format($s[$kamer.'_temp']-$s[$kamer.'_set'],1);
//if the room is heated by gas and the difference is smaller than the biggest difference update the $bigdiff variable
if(in_array($kamer,$kamersgas))if(${'dif'.$kamer} < $bigdif) $bigdif=${'dif'.$kamer};
//
${'Set'.$kamer}=number_format($s[$kamer.'_set'],1);
}
//loop thru all rooms again, now that we know all temp differences we can calculate the setpoint for the valves, the coldest rooms get a higher setting so the valves are already open when needed.
foreach($kamers as $kamer){
if(${'dif'.$kamer}<=number_format(($bigdif+ 0.2),1)&&${'dif'.$kamer}<1)${'RSet'.$kamer}=setradiator($kamer,${'dif'.$kamer},true,$s[$kamer.'_set']);
else ${'RSet'.$kamer}=setradiator($kamer,${'dif'.$kamer},false,$s[$kamer.'_set']);
}
Update the real valves with the calculated values, this room has 3 valves:
Code: Select all
if($s['livingZ']!=$RSetliving)ud($i['livingZ'],0,$RSetliving,'RlivingZ');
if($s['livingZZ']!=$RSetliving)ud($i['livingZZ'],0,$RSetliving,'RlivingZZ');
if($s['livingZE']!=$RSetliving)ud($i['livingZE'],0,$RSetliving,'RlivingZE');
And at last turn on the burner depending on the biggest difference and the last switch time:
Code: Select all
if($bigdif<=-0.3&&$brander=="Off"&& $Tbrander<time-60)sw($Ibrander,'On','brander dif = '.$bigdif);
elseif($bigdif<=-0.2&&$brander=="Off"&& $Tbrander<time-120)sw($Ibrander,'On','brander dif = '.$bigdif);
elseif($bigdif<=-0.1&&$brander=="Off"&& $Tbrander<time-180)sw($Ibrander,'On','brander dif = '.$bigdif);
elseif($bigdif<=0&&$brander=="Off"&& $Tbrander<time-240)sw($Ibrander,'On','brander dif = '.$bigdif);
elseif($bigdif>=0.1&&$brander=="On"&& $Tbrander<time)sw($Ibrander,'Off','brander dif = '.$bigdif);
elseif($bigdif>=0&&$brander=="On"&& $Tbrander<time-60)sw($Ibrander,'Off','brander dif = '.$bigdif);
elseif($bigdif>=-0.1&&$brander=="On"&& $Tbrander<time-120)sw($Ibrander,'Off','brander dif = '.$bigdif);
elseif($bigdif>=-0.2&&$brander=="On"&& $Tbrander<time-180)sw($Ibrander,'Off','brander dif = '.$bigdif);
elseif($bigdif>=-0.3&&$brander=="On"&& $Tbrander<time-240)sw($Ibrander,'Off','brander dif = '.$bigdif);
It took quite some time to get it this way but it works really good. I have a histeris of 0.1°, the heating is fast because only the valves that require heat are open, and because they go open before the difference drops below 0 there's no delay caused by the wake-up time.