LET d = 0
LET rmt_relay1 = 0
LET t3 = 100 ' 10 sec
DO
' Control heater
IF relay3 = 0 THEN
' We are in remote control mode
' Sets thresholds for house temp
IF relay2 = 0 THEN
LET b = 5.0
LET c = 5.5
ELSE
LET b = 17.2
LET c = 17.7
END IF
IF relay1 = 0 THEN
'Heater is off
LET a = 0
IF temp1 < b THEN
LET a = 1
END IF
IF temp2 > 60 THEN
LET a = 1
END IF
IF temp4 < 2.8 THEN
LET a = 1
END IF
IF t0 > 0 THEN
LET a = 0
END IF
' Switch on
IF a = 1 THEN
LET t1 = 1200 ' Min on = 2 min
LET t2 = 12000 ' Max on = 20 min
LET relay1 = 1
END IF
ELSE
'Heater is on
LET a = 0
IF temp1 < c THEN
LET a = 1
END IF
IF temp2 > 55 THEN
LET a = 1
END IF
IF temp4 < 3.5 THEN
LET a = 1
END IF
IF t1 > 0 THEN
LET a = 1
END IF
IF t2 = 0 THEN
LET a = 0
END IF
' Switch off
IF a = 0 THEN
LET t0 = 2400 ' Min off = 4 min
LET relay1 = 0
END IF
END IF
ELSE
LET t0 = 0
LET t1 = 0
LET t2 = 0
LET relay1 = 0
END IF
' Control pipes
IF t3 = 0 THEN
IF temp3 < 4 THEN
LET rmt_relay1 = 1
LET d = 1
LET t3 = 3000 ' 5 min
LOG
ELSE
IF d = 1 THEN
LET rmt_relay1 = 0
LET d = 0
LET t3 = 600 ' 1 min
LOG
END IF
END IF
END IF
LOOP
END