X-300 Script Simulator unofficial

4. Weekdays

An office only needs heat during working hours on working days. The X-300 doesn't give you the day of the week directly, but it gives you the date as a number, and the day of the week falls out of that with one line of arithmetic.

' Office hours: day setpoint 08:00-18:00 Monday to Friday, setback otherwise.
' date counts days from Thursday 1970-01-01, so (date + 3) % 7 is 0 on Monday.
' extvar0 = occupied setpoint, extvar1 = swing, extvar2 = setback.
do
  let c = temp1
  let d = date + 3
  let d = d % 7
  let a = extvar2
  if d < 5 then
    if time >= 08:00:00 then
      if time < 18:00:00 then
        let a = extvar0
      end if
    end if
  end if
  let b = a - extvar1
  if relay1 = 0 then
    if c < b then
      let relay1 = 1
    end if
  else
    if c > a then
      let relay1 = 0
    end if
  end if
loop
end

Run it in the playground →

The day of the week from date

date counts days. Day 0 was Thursday, 1 January 1970, so the count moves through the week in step: every 7 days it's Thursday again. The remainder operator % gives you where you are in the week:

(date + 3) % 7 0 1 2 3 4 5 6
day Mon Tue Wed Thu Fri Sat Sun

Adding 3 first just shifts the numbering so that Monday is 0, which makes "Monday to Friday" the same as "less than 5".

Because X-300 scripts do one operation per line, the script does it in two steps:

let d = date + 3
let d = d % 7

About %. The X-300 manual only shows + and - in its examples. % (remainder) is documented for ControlByWeb's newer 400 series, and the scripts in the case study use it on real X-300 units, which accept and run it. The about page lists everything that's observed rather than documented.

Three conditions, nested

"Weekday, after 08:00, before 18:00" is three IFs, one inside the next. Nesting is limited to 5 levels on the X-300, so it's worth noticing how deep you are. Here the deepest point is 3 IFs inside the DO, 4 levels in total.

Try it

  1. The example starts on a Friday at 07:30. Run at 10 min/s and watch the heat come on at 08:00 and switch to setback at 18:00.
  2. Keep it running into Saturday: no occupied period at all.
  3. Change the date to a Monday and watch the week start again.