X-300 Script Simulator unofficial

6. Data from outside

The X-300 can't fetch the weather, but anything on the network can send it a value. A Raspberry Pi, an ESP32 or a home-automation server can write the outside temperature into an external variable every few minutes. This script keeps the heat off while it's mild outside, and stops trusting the value if the sender goes quiet.

' A Raspberry Pi or ESP32 writes the outside temperature into extvar4 every
' 10 minutes over HTTP. Keep the heat off while it is warmer than extvar3
' outside, but only while the feed is fresh: if no new value arrives for an
' hour, fall back to a plain thermostat. The sender alternates the last digit
' (e.g. 58.00 / 57.95) so even a steady temperature looks like a new value.
' extvar0 = setpoint, extvar1 = swing, extvar3 = outside cut-off, extvar4 = outside.
do
  let c = temp1
  if extvar4 <> f then
    let f = extvar4
    let t1 = 36000
  end if
  let e = 1
  if t1 > 0 then
    if extvar4 > extvar3 then
      let e = 0
    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

Run it in the playground →

Sending a value in

External variables can be set with a plain web request to the unit, as described in the manual's section on its state.xml page. Something like this, sent every 10 minutes from a small script or an automation, is enough:

http://<unit address>/state.xml?extvar4=57.95

If the unit has a control password set, the request has to log in like a browser would. Don't expose the unit to the internet to do this; send from a device on the same network.

Is the value fresh?

A feed can stop: the Pi crashes, the Wi-Fi drops, the weather service changes. If the script keeps believing the last number it got, a mild reading from yesterday afternoon could keep the heat off through a freezing night. So the script tracks when the value last changed:

if extvar4 <> f then     ' a different value than last time?
  let f = extvar4        ' remember it
  let t1 = 36000         ' and restart a one-hour timer
end if

While t1 is still counting, the reading is fresh and the outside rule applies. Once it reaches 0 with no new value, the script behaves like a plain thermostat again.

A flag: is heat allowed?

The script uses e as a flag, a variable that just means yes or no. Each pass starts with let e = 1 ("heat allowed"). The outside-temperature rule can set it to 0 ("force off"). At the bottom, if e = 0 then switches the heat off, and otherwise the usual thermostat runs. Rules set the flag; the bottom obeys it. This is how X-300 scripts get around having no AND or OR: several IFs can each set the same flag, and one IF tests it.

The alternating last digit

There's one catch: if it's 58° outside for three hours, every push is the same number, so extvar4 <> f never sees a change and the timer runs out even though the feed is fine. The fix is on the sending side: alternate the last digit, sending 58.00, then 57.95, then 58.00. The 0.05° makes no practical difference, but every push now looks new. The playground's sender does this.

Try it

  1. The example starts at 58° outside with the cut-off at 55°. The heat stays off even though the room is below setpoint.
  2. Drag Outside below 55 and wait for the next push (up to 10 simulated minutes): the thermostat takes over.
  3. Untick the sender, run at 10 min/s, and watch the heat come back an hour after the last value arrived.