// Only adapted for 1 on/off per day//use Format 00//CT1-CT7 = Hour on day 1-7//CT11-CT17 = Minute on day 1-7//CF1-CF7 = Hour off day 1-7//CF17-CF17 = Minute off day 1-7//00:00 - 24:00 = always on//00:00 - 00:00 = always offfunctionread(){schedule.DefaultValue="0";for(vari=1;i<=7;i++){varday=i;varonHours=tagValue(prefix+"_CT"+day);varonMinutes=tagValue(prefix+"_CT1"+day);varoffHours=tagValue(prefix+"_CF"+day);varoffMinutes=tagValue(prefix+"_CF1"+day);onHours=pad(onHours,2);onMinutes=pad(onMinutes,2);offHours=pad(offHours,2);offMinutes=pad(offMinutes,2);on=onHours+""+onMinutes;off=offHours+""+offMinutes;if(onHours=="00"&&onMinutes=="00"&&offHours=="00"&&offMinutes=="00"){// do nothing}elseif(offHours=="24"&&offMinutes=="00")schedule.AddEvent("1",on+"-0000:"+i);elseschedule.AddEvent("1",on+"-"+off+":"+i);}returntrue;}functionwrite(){vardays=[0,0,0,0,0,0,0,0,0];varday=0;for(vari=0;i<schedule.Events.Count;i++){if(schedule.Events[i].Value!=schedule.DefaultValue&&schedule.Events[i].Time.Length==11){day=schedule.Events[i].Time.Substring(10);vard=day-1;day+=days[d]*10;days[d]++;varonHours=schedule.Events[i].Time.Substring(0,2);varonMinutes=schedule.Events[i].Time.Substring(2,2);varoffHours=schedule.Events[i].Time.Substring(5,2);varoffMinutes=schedule.Events[i].Time.Substring(7,2);if(offHours=="00"&&offMinutes=="00")offHours="24";tagWrite(prefix+"_CT"+day,onHours);tagWrite(prefix+"_CT1"+day,onMinutes);tagWrite(prefix+"_CF"+day,offHours);tagWrite(prefix+"_CF1"+day,offMinutes);}}for(vari=1;i<=7;i++){for(varn=days[i-1];n<nbrOnOff;n++){day=i+n*10;tagWrite(prefix+"_CT"+day,"00");tagWrite(prefix+"_CT1"+day,"00");tagWrite(prefix+"_CF"+day,"00");tagWrite(prefix+"_CF1"+day,"00");}}returntrue;}functionpad(n,width){varresult='';for(vari=n.length;i<width;i++){result+='0';}result+=n;returnresult;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.