X-300 Script Simulator unofficial

Case study: one heating script, four versions

These four scripts ran, one after another, on an X-300 heating the ground floor of a small residential building. Each change was tested in this simulator before it was uploaded. They're shown here as they ran, apart from the building's name. Each version opens in the playground with sensible starting values.

The building's needs were ordinary: a comfortable day temperature, less at night, less during weekday working hours, no heating on mild afternoons, and none in summer.

Version 1: a thermostat with a night setback

let a = 1 
do while a = 1
  let c = temp1
  if c < 150 then
    if c > 20 then 
  if time < 12600 then 
   let b = extvar2
  else
    if time > 79200 then
      let b = extvar2
    else
      let b = extvar0
    end if
  end if
  if relay1 = 0 then 
    if c <= b - extvar1 then
      Let relay1 = 1
    end if
  end if  
  if relay1 = 1 then
    if c > b then
      Let Relay1 = 0
    end if
  end if 
end if
end if 
loop
end

Run it in the playground →

The original. Day setpoint extvar0, night setpoint extvar2 from 22:00 to 03:30, swing extvar1. Times are written as raw seconds since midnight (12600 is 03:30, 79200 is 22:00), which works but is hard to read; 03:30:00 and 22:00:00 mean the same thing.

The do while a = 1 loop is a common way to write a loop that never ends (a is set to 1 and never changed); a plain DO does the same.

Two quirks worth noticing: the sensor sanity check (c > 20, c < 150) is on separate lines at odd indentation, and Let and Relay1 are capitalised on a couple of lines. Both run fine; the unit treats statement words and its own variable names without regard to case.

Version 2: a weekday temperature

let a = 1
do while a = 1
  let c = temp1
  let i = date + 3
  let j = i % 7
  let h = extvar3
  if h < 0.3 then
    let h = 0.3
  end if
  if h > 5 then
    let h = 0.3
  end if
  let b = extvar0
  if j < 5 then
    if time > 28799 then
      if time < 57600 then
        if extvar1 > 49 then
          let b = extvar1
        end if
      end if
    end if
  end if
  if time < 12600 then
    let b = extvar2
  end if
  if time > 79200 then
    let b = extvar2
  end if
  let g = 0
  if c < 150 then
    if c > 20 then
      let g = 1
    end if
  end if
  if g = 1 then
    if relay1 = 0 then
      if c <= b - h then
        let relay1 = 1
      end if
    else
      if c > b then
        let relay1 = 0
      end if
    end if
  end if
loop
end

Run it in the playground →

Two additions:

The night window moved to the end of the "pick the target" section, so night always wins over the weekday rule.

Version 3: no heat on mild afternoons

let a = 1
do while a = 1
  let c = temp1
  let i = date + 3
  let j = i % 7
  let h = extvar3
  if h < 0.3 then
    let h = 0.3
  end if
  if h > 5 then
    let h = 0.3
  end if
  if extvar4 <> f then
    let f = extvar4
    let t1 = 36000
  end if
  let d = 0
  let b = extvar0
  if j < 5 then
    if time > 28799 then
      if time < 57600 then
        if extvar1 > 49 then
          let b = extvar1
        end if
      end if
    end if
  end if
  if time < 12600 then
    let d = 1
  end if
  if time > 79200 then
    let d = 1
  end if
  if d = 1 then
    let b = extvar2
  end if
  let e = 1
  if d = 0 then
    if t1 > 0 then
      if extvar4 > 55 then
        let e = 0
      end if
    end if
  end if
  if e = 0 then
    let relay1 = 0
  end if
  let g = 0
  if c < 150 then
    if c > 20 then
      let g = e
    end if
  end if
  if g = 1 then
    if relay1 = 0 then
      if c <= b - h then
        let relay1 = 1
      end if
    else
      if c > b then
        let relay1 = 0
      end if
    end if
  end if
loop
end

Run it in the playground →

A Raspberry Pi on the same network fetches the outside temperature and writes it into extvar4 every 10 minutes, alternating the last digit so every push is a new value (lesson 6). The script adds:

The simulator's tests run versions 2 and 3 over the same days and check that they behave identically whenever the feed is missing.

Version 4: a heating season and a test button

let a = 1
do while a = 1
  let c = temp1
  let i = date + 3
  let j = i % 7
  let h = extvar3
  if h < 0.3 then
    let h = 0.3
  end if
  if h > 5 then
    let h = 0.3
  end if
  if extvar4 <> f then
    let f = extvar4
    let t1 = 36000
  end if
  let d = 0
  let b = extvar0
  if j < 5 then
    if time > 28799 then
      if time < 57600 then
        if extvar1 > 49 then
          let b = extvar1
        end if
      end if
    end if
  end if
  if time < 12600 then
    let d = 1
  end if
  if time > 79200 then
    let d = 1
  end if
  if d = 1 then
    let b = extvar2
  end if
  let e = 1
  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
  if i > 150 then
    if i < 273 then
      if relay2 = 0 then
        let e = 0
      end if
    end if
  end if
  if d = 0 then
    if t1 > 0 then
      if extvar4 > 55 then
        let e = 0
      end if
    end if
  end if
  if relay3 = 0 then
    let t3 = 0
  else
    if t3 = 0 then
      let t2 = 18000
      let t3 = 36000
    end if
    if t2 = 0 then
      let relay3 = 0
    end if
    if c > 80 then
      let relay3 = 0
    end if
  end if
  if relay3 = 1 then
    let e = 2
  end if
  if e = 0 then
    let relay1 = 0
  end if
  if e = 2 then
    let relay1 = 1
  end if
  let g = 0
  if c < 150 then
    if c > 20 then
      let g = e
    end if
  end if
  if g = 1 then
    if relay1 = 0 then
      if c <= b - h then
        let relay1 = 1
      end if
    else
      if c > b then
        let relay1 = 0
      end if
    end if
  end if
loop
end

Run it in the playground →

Two of the unit's three relays weren't wired to anything, so they became switches on the control page:

e = 2 is a third state, "force on", checked after the season and outside rules so that Test heat beats both.

The whole script is 1,629 bytes on disk and 1,732 as the unit counts them (each line ending counts as two bytes), under the 1,900-byte limit. All four versions touch the nesting limit of 5 in places (the loop plus four IFs), which is one reason v4 uses the flags d, e and g instead of nesting the rules inside each other.

What carried through all four versions