Page 1 of 5

DIY WiFi Programmable Thermostat

Posted: Sun Apr 10, 2016 7:24 pm
by basicchip
**************************************************************************************************************************************
For those of you just coming to the forum, this is a work in progress.

The goal of this design is to use an ~$10 module to add a WiFi served control webpage to a thermostat that is user programmable in BASIC or C and that programming is relatively simple.

While I expect the finished design to be done in a few weeks, it is still a work in progress. But the web server side has been built on an EMW3165 module and that is nearing completion.
*****************************************************************************************************************************************


This is something I want for my own use. I want to replace at least one of the thermostats in my house with a programmable design, that can be controlled over WiFi. Here is one of those thermostats.
thermo1.jpg
thermo1.jpg (18.37 KiB) Viewed 29539 times
Some more details on my use. My system is a heater only, and as a radiant system, all the thermostat does is say its cold or hot.

To get started I did not want to develop the project on the existing heater controller, which could be an expensive proposition if I did something bone-headed. So I picked up a 24VAC/16VAC transformer at the local Ace Hardware.
xformer.jpg
xformer.jpg (44.82 KiB) Viewed 29539 times
I've had lots of experience working with high voltage, and also being shocked a lot, so first I decided to build an enclosure for that transformer. I had a few boxes lying around, but seems to me like an old PC power supply, gets me halfway there, AC power plug, switch, box to get started. I guess I'm voiding the waranty :)
pc_supply.jpg
pc_supply.jpg (83.31 KiB) Viewed 29539 times

Re: WiFi Programmable Thermostat

Posted: Mon Apr 11, 2016 12:00 am
by basicchip
OK getting the power supply setup. A handful of junk box components makes a 24VAC supply, that I don't have to worry about exposed 120VAC or at least it is a lot more stable on my desk
pwr.jpg
pwr.jpg (55.1 KiB) Viewed 29536 times
As for the thermostat, while this is the one in my house, it is no longer generally used. Partly it is pretty old tech nowadays, lots of through hole parts.
thermo2.jpg
thermo2.jpg (86.82 KiB) Viewed 29536 times
So I picked up a newer one at Home Depot (less than $20), which will be a better example for others, this is a Honeywell RTH221B
thermo3.jpg
thermo3.jpg (22.4 KiB) Viewed 29536 times
And the more modern all SMT design.
thermo4.jpg
thermo4.jpg (54.1 KiB) Viewed 29536 times
I plan on using the housing, power supply, relay, maybe temp sensor and interfacing those to the WiFi module. It should save a lot of time.

Re: WiFi Programmable Thermostat

Posted: Tue Apr 12, 2016 3:45 am
by basicchip
Not a lot of useful progress today, but you learn by experience. The original thermostats were mercury switches on bimetal strip springs that rotated with temperature change. When it wanted heat or cool, the mercury switch would close and present a dead short to the 24VAC coming to it on 2 wires. Not much has changed, the digital thermostats read temp from a sensor and trip either a big transistor through an opto-isolator, or use a small relay to do the same thing. Not much in the way of progress, but that makes the heating system compatible even with those old mercury switch thermostats.

So what happened, I was checking out voltage levels when the thermostat was requesting heat. I guess I didn't believe/know that it would be a dead short at the thermostat end. That blew an internal fuse on the transformer I picked up at Ace. I guess I could fix it, but as it turns out both thermostats seem to have a full wave rectifiers, so that I can just use my better DC power supplies that have current limits and meters and are generally more experimenter friendly.

But this also presents a problem for when the thermostat is requesting heat, there is really no voltage coming up those wires from the heater controller. I was counting on at least some voltage there to provide power for WiFi module. And it also informs me that the batteries in both thermostats are providing power for the digital side when heat is requested. All in all pretty energy wasteful, but again the price of compatibility.

If you have both heat and cool lines, at least one would be providing 24VAC at all times, but in my case I have to come up with something else. My system has 2 "controllers" down at the boiler. One is a controller that monitors the gas heat, then the primary loop, and then the secondary loops through the house. The other handles the multi-zones and makes the request for heat from the boiler controller and controls loop solenoids for water/anti-freeze flow in the floor.

As it turns out my zone controller provides the 24VAC, and senses the thermostat closures. It has current limiting resistors (not sure the value), but when a thermostat is closed there is only 2 VAC on the wires. That is too little to power my module, but I am thinking of experimenting to see what it would see as a closure, and if it is > 5V, then I can probably get by without a battery, otherwise I might have to charge a LiPo cell in the WiFi thermostat.

Re: WiFi Programmable Thermostat

Posted: Tue Apr 12, 2016 10:49 pm
by basicchip
Today had to think more about power and did some looking at the Honeywell thermostat and the older Erie one. The Honeywell one seems to run the digital side completely off batteries, which to me is not a desirable design, after all until the furnace controller goes WiFi, it is hardwired to the thermostats. My older Erie design does run off the 24VAC, but has a small hearing aid style battery to run when heat is being requested (ie. the 24VAC is down to < 2VAC).

I did some experimenting on the multizone controller to see what it would see as a HEAT request. Also got out my reading glasses and flash light and a bag of power resistors from my junkbox (yes my wife says my whole office is a junk box, and I don't necessarily disagree).

The MZ controller has 470 ohm limiting resistors in the thermostat sense circuit, and somewhere on its panel it says it is compatible with .1 A thermostats. Before the flashight and reading glasses I didn't see the "." . That seems much more reasonable to me, as 1 A is a lot of power to be running around on bell wire.

I found that the MZ controller would send heat with as big as a 200 ohm across the thermostat. That is good, as I can work with simple linear regulators depending on the power required by the EMW3165 module. More on that next.

Re: WiFi Programmable Thermostat

Posted: Tue Apr 12, 2016 11:09 pm
by basicchip
As this is a work in progress, some reading here may be a bit disappointed that it is not a solution yet. And while it seems like I am just poking around, in reality I have been thinking about this for a while, and this journal is mostly about the integration process I am doing now.

The goal of this is to do the thermostat control program in BASIC and for it to also serve a webpage as the interface to the end user. That programming is nearly complete, as that work started a few months back. As I know, hardware without software is pretty useless. Here is a snapshot of the webpage you would see on your phone, tablet, PC, Mac, Linux machine or whatever.
webpage1.jpg
webpage1.jpg (63.32 KiB) Viewed 29460 times
Originally I was thinking of doing some cross platform app. But by going with a webpage, that is about as cross platform as it gets and doesn't require much programming on our side beyond some HTML.

On the thermostat side, I still intend to hack an existing design to provide the case and hopefully temp display. Seems like the power supply may become a design issue, as I don't want to use batteries or external supply. Poking around at some of the store bought solutions, Nest is pretty good, as it learns from you, but being the inveterate tinker, I can't tinker with it. The touch screen ones seem like a silly idea, as if you do WiFi and can control it from your phone, what do you need the touchscreen for.

Re: WiFi Programmable Thermostat

Posted: Wed Apr 13, 2016 1:39 am
by olzeke51
Hi Bruce, looks like a good idea. and a challenge
'
what is the temp sensor ??
'
are you making a circuit board to mount the
module and prototype area for other components ??
'
BTW - ?DIRTYPCBS seems to have a breakout board ONLY for it
the comments section of the Seeedstudio product page has a link.--
http://dirtypcbs.com/view.php?share=932 ... 4ba8fb2f6f
'
- here are some UI thots!!!
'
so is the wifi thermostat housing going to have::
1) a visual display ? - two digits - 7 segment?
2) will it flash between setpoint and current temp,
' when not in the hysteresis band
3) what will be the hysteresis
4) buttons to program it manually, up & down
5) the manual/button input will only last until the next
' programmed time slot?
' OR maybe have a 'time button'
' for duration of manual mode - in hours
' but now the web page would need modified/updated
'
Hey, you stirred up the creative juices !!!
Best to you, Olzeke51

Re: WiFi Programmable Thermostat

Posted: Wed Apr 13, 2016 2:12 pm
by basicchip
The temp sensor will be a digital type, I have a few lying around, and when I find one and hook it up I will let you know which one it is. There are quite a few out there, all pretty cheap and easy to use with either one-wire, i2c or SPI interfaces. Originally I was thinking of using the one in the thermostat that I am hacking.

As for the display I intend to leave that alone as it fits the package, and would normally show temp. Replacing the display would add time, and not a lot of functionality.

For the buttons I was thinking of using those for AWAY/HOME settings, which is easy to do, by disconnecting them from the existing micro and running wires over to the EMW3165. Most likely I will build a custom board for the module, right now I am using the ones available on eBay for $12 or so, which have 0.1" headers soldered on.

As for actual operation of the thermostat control, that will be in BASIC and we will publish the source here. Same goes for the HTML

For time, this things lives on the in house network and it can pick up the time from many different sources, no need for the user to set that.

Re: WiFi Programmable Thermostat

Posted: Thu Apr 14, 2016 10:43 pm
by basicchip
Had a chance to make some power measurements today. Did them on both an ESP8266/LPC824 combination and on the EMW3165. The ESP8266 has some very high bursts on startup (>250 mA) and runs toggling between 20 and 80 mA (without measuring a guess would be an average of 35 mA). The EMW3165 runs at about 50 mA.

Well 50 mA * 470 ohms is 23.5V. Which means I guess I will have to bite the bullet for now and supply power to the module, rather than trying to power it from the 24 VAC.

Both digital thermostats seem to be drawing less than 1 mA, and as all they do is take a temperature reading every once in a while and control a relay that is not surprising. There may be way to get the power lower on the WiFi side, but that may take more research than time to just get something working.

Luckily 5V USB regulated power supplies are everywhere due to smart phones and tablets, so that is a cheap solution, just have to hide it somewhere.

Re: DIY WiFi Programmable Thermostat

Posted: Thu Apr 14, 2016 11:11 pm
by basicchip
Also looked at the Nest installation guides and some other tech info on it. These guys understand human engineering, quite a nifty product.

As for power they have a rechargeable battery inside, so they can be compatible with a 2 wire 24VAC system. I may end up doing the same, but they also talk about limiting resistors in the heating controller, and that they may be too big (like I think mine are). I can easily change one of those, or I also have a spare zone, that I may just connect up as if it were a cooling circuit, so I can steal power that way.

Re: DIY WiFi Programmable Thermostat

Posted: Wed Apr 20, 2016 5:25 pm
by basicchip
OK, tax filing done, ski season winding down. But I have been poking around for power supply ideas on this. And have started on the schematic diagrams for that. I am going to design this for 24VAC available all the time, meaning heating and cooling wires. In my case I will just snake in a spare 24VAC line. In addition I will also design and check out an MCP73871 which controls charging of a Li battery while simultaneously supplying the load. So the incoming 24VAC can be shorted to signal a heat request.

For building the PCBs, I am going to try ExpressPCB which does 3 fixed size PCBs for $61. That is pretty cheap, for volume PCBs I have been using either Sunstone or PCB-Pool.

On the programming side, to show the communication between webpage and user BASIC program, these are preliminary sources for BASIC and the HTML. The firmware on the device services the webpage and handles the CGI requests that can set or read values in the BASIC program.

Web source (phpBB does not allow HTM uploads)
Thermostat.zip
(1.26 KiB) Downloaded 897 times
And the BASIC program
Thermostat.bas
(12.78 KiB) Downloaded 941 times
Hardware definitions for STM32F411.bas
STM32F411.bas
(55 Bytes) Downloaded 932 times
The include for parsed.bas is a placeholder file that we are using until the BASICtools gets caught up to compile the HTML page and add it to the downloaded hex.