ESP8266 Thermostat updated

Place your projects here
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

ESP8266 Thermostat updated

Post by Zim »

2021-02-10 17_43_06-Window.jpg
Be sure to uncomment line 15 for the first run, then recomment it...

Code: [Local Link Removed for Guests]

'Zim's Annex Thermostat Celcius v.7
onHtmlReload create_page 
onhtmlchange update
gosub create_page
timer0 2000, update
wait

create_page:
cls
autorefresh 1000
D1 = 5    ' output to relay
D2 = 4    ' sensor
PIN.MODE D1, OUTPUT 'relay for furnace D2
PIN(D1)= 1
'file.save "/tmpset.txt", str$(5)   'XXXXXXXXXXXXXXXXXXXX   uncheck this for the first run so it creates a txt file  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
setp = val(file.read$("/tmpset.txt"))
DHT.SETUP 4, 11
curr = DHT.TEMP
curr1 = 99                'displayed sensor reading if sensor issue  
stat$ = "Furnace is now OFF"
otw = 0  'On Time Warning variable
ltmp = 0   'low temp warning variable
htmp = 0   'high temp warning variable
qsbutt$ = "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"
txtbstat$ = "background-color:white;text-align:center;display:block;width:160px;height:26px;font-size:15;font-weight:bold"
txtbsetp$ = "background-color:white;text-align:center;display:block;width:54px;height:42px;font-size:30;font-weight:bold"
txtbcurr1$ = "background-color:white;text-align:center;display:block;width:54px;height:42px;font-size:30;font-weight:bold"

A$ = ""
A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:24px;}|
A$ = A$ + |</style>|
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>|
A$ = A$ + |<th>|
A$ = A$ + |<p>Room<br>Temperature</p></th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(curr1, "txt1")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt1", txtbcurr1$)
A$ = A$ + |</table>|
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='red' border='1' cellpadding='8'>"|
A$ = A$ + |<center><th>|
A$ = A$ + |<p>Thermostat<br>is Set At</p>|
A$ = A$ + |</th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(setp, "txt2") 
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt2", txtbsetp$)
A$ = A$ + |</table>|
A$ = A$ + |<center>|
A$ = A$ + |<p><font color = 'white', font size = '4'>Type Desired Temp. in Above Window<br>or select a Quick Button below</font></p>|
A$ = A$ + |</center>|
A$ = A$ + |<table align='center' width='300' bgcolor='red' border='1' cellpadding='5'>|
A$ = A$ + |<center><th>|
A$ = A$ + button$("<b><big>Quick set to&#10;5 deg.</big><b/>", Qset5, "but1")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("but1", qsbutt$)
A$ = A$ + |<center><th>|
A$ = A$ + button$("<b><big>Quick set to&#10;15 deg.</big><b/>", Qset15, "but2")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("but2", qsbutt$)
A$ = A$ + |</table>|
A$ = A$ + |<table align='center' width='300' bgcolor='lightblue' border='1' cellpadding='8'>|
A$ = A$ + |<td><center>|
A$ = A$ + |<b><big>Furnace Status</big></b>|
A$ = A$ + |</center><center>|
A$ = A$ + textbox$(stat$, "txt3")
A$ = A$ + cssid$("txt3", txtbstat$)
A$ = A$ + |</center></td></table>|
A$ = A$ + |<br><center>|
A$ = A$ + button$("<b><big>Refresh Page if Needed</big><b/>", freshweb)
A$ = A$ + button$("<b><big>Turn OFF</big><b/>", offf)
A$ = A$ + |</center></table></body></html>|
HTML A$
return

on2:
otw = otw + 1
if otw > 900 gosub alert_time  'if furnace on over 30 min. sends alert
'if otw > 30 gosub alert_time  'test
PIN(D1)= 0
stat$ = "Furnace is now ON"
return

off2:
otw = 0  'resets alarm timer
PIN(D1)= 1
stat$ = "Furnace is now OFF"
return

Qset15:
setp = 15
return

Qset5:
setp = 5
return

update:
curr = DHT.TEMP
if setp <= -1 or setp > 30 then let setp = val(file.read$("/tmpset.txt"))              'if temp has been set out of normal range, it defaults to last setting
if (setp <> val(file.read$("/tmpset.txt"))) and (setp < 30) and (setp > -1) then file.save "/tmpset.txt", str$(setp)             'writes last acceptable setting to memory
if curr < 40 and curr > -40 then curr1 = int(curr)  'int gives no decimal xxxxxxxxxxxxxxxx use this line to calibrate eq. int(curr) - 5
if curr1 < (setp - 1) then gosub on2 'swing adjustment
if curr1 > (setp + 1) then gosub off2 'swing adjustment
if curr > 32 gosub alert_high ' if temp high go to alert
if curr < 0 gosub alert_low  'if temp low go to alert
'wlog " On time alert  "; otw     'shows the count up to alert after 30 minutes of on time
'wlog " Low temp alert  "; ltmp   'shows the count up to alert after 15 minutes of low temp
'wlog " High temp alert  "; htmp  'shows the count up to alert after 15 minutes of high temp
return

freshweb:
gosub create_page
return

alert_time:
otw = 0  'resets alarm timer
EMAIL.SETUP "smtp.gmail.com", 465, "Zim@gmail.com", "passw" 'replace with your login / password
print EMAIL ("Zim@gmail.com", "780xxxxxxx@msg.telus.com", "Title : Thermostat", "Furnace running for over 30 minutes")
pause 100
'wlog "on-time alert sent"
return

alert_low:
ltmp = ltmp + 1
if ltmp < 450 return
ltmp = 0  
EMAIL.SETUP "smtp.gmail.com", 465, "Zim@gmail.com", "passw" 'replace with your login / password
print EMAIL ("Zim@gmail.com", "780xxxxxxx@msg.telus.com", "Title : Thermostat", "Garage temperature is low")
pause 100
'wlog "low temp message sent"
return

alert_high:
htmp = htmp + 1
if htmp < 450 return
htmp = 0
EMAIL.SETUP "smtp.gmail.com", 465, "Zim@gmail.com", "passw" 'replace with your login / password
print EMAIL ("Zim@gmail.com", "780xxxxxxx@msg.telus.com", "Title : Thermostat", "Garage temperature is high")
pause 100
'wlog "high temp message sent"
return

offf:
PIN(D1)= 1
timer0 0 
cls
A$ = ""
A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:36px;}|
A$ = A$ + |</style>|
A$ = A$ + |<br><center>|
A$ = A$ + button$("<b><big>Turn on Thermostat</big><b/>", gogo)
A$ = A$ + |</center></table></body></html>|
HTML A$
PIN(D1)= 1
'wlog " pin D1 is  "; PIN(D1)
onHtmlReload offf
return

gogo:
cls
reboot
You do not have the required permissions to view the files attached to this post.
Post Reply