7. Seasons
A building on a heating schedule often shouldn't heat at all in summer, whatever the thermostat thinks. This script only allows heat from 1 October to 31 May, and adds an override for the odd cold week in June or September.
' Heating season only: October 1 to May 31. Relay 2 is an override switch
' on the control page that allows heat in summer too.
' Day of year (0 = January 1) from date, leap years included:
' days since 2000-01-01 (date 10957), within its 4-year cycle (1461 days).
' extvar0 = setpoint, extvar1 = swing.
do
let c = temp1
let i = date - 10957
let i = i % 1461
if i < 366 then
if i > 59 then
let i = i - 1
end if
else
let i = i - 366
let i = i % 365
end if
let e = 1
if i > 150 then
if i < 273 then
if relay2 = 0 then
let e = 0
end if
end if
end if
if e = 0 then
let relay1 = 0
else
let b = extvar0 - extvar1
if relay1 = 0 then
if c < b then
let relay1 = 1
end if
else
if c > extvar0 then
let relay1 = 0
end if
end if
end if
loop
end
The day of the year
Months have different lengths and leap years add a day, so "is it between June and September?" is easiest to answer from the day of the year (0 = 1 January). Getting there from date takes a few lines:
date - 10957counts days from 1 January 2000 instead of 1970.% 1461gives the position inside a four-year cycle (365 × 3 + 366 = 1461 days). Each cycle starts with a leap year: 2000, 2004, … 2028.- In the leap year (the first 366 days of the cycle), days after 29 February are moved back by one so that 1 March is always day 59.
- In the other three years, subtract the leap year and take
% 365.
After that, 31 May is day 150 and 1 October is day 273, in every year. Summer is "day 151 to 272". (The four-year rule is right for every year from 2000 to 2099, which covers any X-300 still running.)
The script uses the same e flag as lesson 6: summer sets it to 0 unless the override is on.
A control-page switch as an input
The X-300 has three relays. If one isn't wired to anything, you can still show it on the control page and use its ON/OFF buttons as a switch that the script reads: relay2 = 0 means "automatic", relay2 = 1 means "allow heat anyway". Nothing clicks in the field because nothing is connected, but the state is there for the script to read. Give it a clear name on the unit's relay setup page.
Try it
- The example starts on 15 July. The room is below setpoint, but the heat stays off.
- Press ON for the season override: the thermostat takes over.
- Change the date to 30 September and then 1 October to see the boundary.
That's the end of the lessons. The case study shows these ideas combined in a script that ran a real building.