> Fit the page of a smartphone,
> Swing or hysteresis for cut in cut out
> Last setting recall for power outages
> Safety shut down if sensor fails
> Sensor integrity checks
> User input limited to feasible values
It was a fun project and works great thanks to ESPbasic.
NOTE: This sketch will not run without a sensor connected.
Be sure to invoke with the /run after the appropriate ip.
'ESPbasic v3.69____Thermostat Be sure to invoke with "/run" after your ip.
'pin 0 is to sensor you decide
'pin 4 is to relay you decide
' NOTE................................This script will not run without valid sensor input!!!!!!!!
memclear
cls
io(pi,0) 'pin 0 is to sensor
io(po,4,0) 'pin 4 is to relay
nan = 2147483648
DHT.SETUP(11,0) 'sets type of sensor used, and pin connected to
setp = read.val(tmpset) 'reads and loads last set temperature (great for power failure)
curr = int(dht.temp())
stat = "--------------" ' looks cool on boot
if (curr = nan) then gosub [check] 'if no signal from sensor, goes and checks average value
if (curr < 100 and curr > -40) then curr1 = curr
endif
wprint "<style>"
wprint "p {font-size:24px;}"
wprint "</style>"
wprint "<body bgcolor='black'>"
wprint "<table align='center' width='300' bgcolor='lightgreen' border='1' cellpadding='8'>"
wprint "<th>"
wprint "<p>Actual Room<br>Temperature</p>"
wprint "</th>"
wprint "</center>"
wprint "<th>"
wprint "<center>"
textbox curr1
wprint "</th>"
wprint "</center>"
cssid htmlid(), "background-color:white;text-align:center;display:block;width:54px;height:32px;font-size:20;font-weight:bold"
wprint "</table>"
wprint "<table align='center' width='300' height='100' bgcolor='red' border='1' cellpadding='8'>"
wprint "<center>"
wprint "<th>"
wprint "<p>Thermostat<br>is Set At</p>"
wprint "</th>"
wprint "</center>"
wprint "<th>"
wprint "<center>"
textbox setp
wprint "</th>"
wprint "</center>"
cssid htmlid(), "background-color:white;text-align:center;display:block;width:45px;height:32px;font-size:20;font-weight:bold"
wprint "</table>"
wprint "<center>"
wprint "<p><font color = 'white', font size = '4'>Type Desired Temp. in Above Window<br>or select a Quick Button below</font></p>"
wprint "</center>"
wprint "<table align='center' width='300' bgcolor='red' border='1' cellpadding='5'>"
wprint "<center>"
wprint "<th>"
button "<b><big>Quick set to<br>3 deg.</big><b/>", [Qset3]
wprint "</th>"
wprint "</center>"
cssid htmlid(), "background-color:white;text-align:center;display:block;width:130px;height:50px;font-size:15;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height: 1"
wprint "<center>"
wprint "<th>"
button "<b><big>Quick set to<br>15 deg.</big><b/>", [Qset15]
wprint "</th>"
wprint "</center>"
cssid htmlid(), "background-color:white;text-align:center;display:block;width:130px;height:50px;font-size:15;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height: 1"
wprint "</table>"
wprint "<table align='center' width='300' bgcolor='lightblue' border='1' cellpadding='8'>"
wprint "<td>"
wprint "<center>"
wprint "<b><big>Furnace Status</big></b>"
wprint "</center>"
wprint "<center>"
textbox stat
cssid htmlid(), "background-color:white;text-align:center;display:block;width:160px;height:26px;font-size:15;font-weight:bold"
wprint "</center>"
wprint "</td>"
wprint "</table>"
wprint "<br>"
wprint "<center>"
button "<b><big>Refresh Page if Needed</big><b/>", [freshweb]
wprint "</center>"
wprint "</table>"
timer 3000, [refresh]
wait
[on2]
io(po,4,1)
stat = "Furnace is now ON"
return
Wait
[off2]
io(po,4,0)
stat = "Furnace is now OFF"
return
Wait
[Qset15]
setp = 15
wait
[Qset3]
setp = 3
wait
[refresh]
if (setp <= 0 or setp > 30) then let setp = read.val(tmpset) 'remembers last setting
if (setp <> read.val(tmpset)) and (setp <31 or setp > 0) then write(tmpset,setp) 'remembers last setting
curr = int(dht.temp())
if (curr = nan) then gosub [check] 'if no signal from sensor, goes and checks average value
if (curr < 100 and curr > -40) then curr1 = curr
if curr1 < setp-1 then gosub [on2] 'adds hysteresis (swing in HVAC terms)
if curr1 > setp+1 then gosub [off2] 'adds hysteresis (swing in HVAC terms)
endif
Wait
[freshweb]
returngui
stat = "--------------"
curr1 = "---"
wait
[check] 'checks sensor signal integrity
tval = 0
For i = 1 to 5
delay 1000
curr = int(dht.temp())
tval = tval + curr
if tval > (3 * nan) then curr1 = "err"
if tval > (3 * nan) then goto [exit]
endif
next i
return
wait
[exit] 'quits program if sensor is sh*t
io(po,4,0)
stat = "Sensor Failure"
wprint "Sensor Failure, Program Aborted"
end