Open-Source Thermostat Won’t Anger Your Landlord

[Nathan Petersen] built a Hackable Open-Source Thermostat to smooth out temperature fluctuations caused by the large hysteresis of the bimetallic strip thermostat in his apartment. While it may be tempting to adjust the “anticipator” to take care of the problem or even replace the bimetallic thermostat with an electronic version, building your own thermostat from scratch is a good way to add to your project portfolio while making your way through college. Plus, he got to hone his hardware and software design chops.

The hardware is designed around the STM32, using a cheap, minimal variant since the device just needs to sense temperature and control the furnace in on-off mode. The TMP117 high-accuracy, low-power, temperature sensor was selected for temperature measurement since accuracy was an essential feature of the project. Dry-contact output for the furnace is via a normally-open solid state relay (opto-isolator). For the user interface, instead of going the easy-route and using an I2C/SPI OLED or LCD display, [Nathan] used three 7-segment LED displays, each driven by an 8-channel constant current driver. The advantage is that the display can be viewed from across the room, and it’s brightness adjusted via PWM. Temperature set-point adjustment is via a simple slide potentiometer, whose analog voltage is read by the micro-controller ADC. To remind about battery replacement, a second ADC channel on the micro-controller monitors the battery voltage via a voltage divider. The PCB components are mostly surface mount, but the packages selected are easy enough to hand solder.

[Nathan]’s Github repo provides the hardware and firmware source files. The board is designed in Altium, but folks using KiCad can use either the awesome Altium2KiCad converter or the online service for conversion. (The results, with some minor errors that can be easily fixed, are quite usable.) Serendipitously, his PCB layout worked like a charm the first time around, without requiring any rework or bodge wires.

The firmware is a few hundred lines of custom bare-metal C code, consisting of drivers to interface with the hardware peripherals, a UI section to handle the user interface, and the control section with the algorithm for running the furnace. [Nathan] walks us through his code, digging into some control theory and filtering basics. After making a few code tweaks and running the thermostat for some time, [Nathan] concludes that it is able to achieve +0.1°F / -0.5°F temperature regulation with furnace cycles lasting about 10-15 minutes (i.e. 4-6 cycles per hour). Obviously, his well insulated apartment and a decent furnace are also major contributing factors. Moving on, for the next version, [Nathan] wants to add data collection capabilities by adding some memory and SD card storage, and use an RTC to allow seasonal adjustments or time-based set-points.

This is his first attempt at a “functional’ useful project, but he does love to build the occasional toy, such as this POV Top.

51 thoughts on “Open-Source Thermostat Won’t Anger Your Landlord

  1. Kudos to the developer on the interesting project but I wonder who really needs temperature regulation to +0.1/-0.5 F. I would also think cycling the heater (or A/C) often enough to achive that narrow range would cost extra. I’ve recently gone down the HA rabbit hole (though I’m old enough to have had a house full of X10 devices decades ago) and briefly looked at adding a smart thermostat and finally concluded I don’t touch my thermostat enough (it’s programmable) to make that a wise investment.

    1. +1 Most bimetallic strip tstats can be adjusted easily within a 2 degree differential or better by adjusting the anticipator to match the current draw of the controls, and while he says “furnace”, an old AC or heat Pump system may not have an “anti-short cycle” delay (ASC) built in to the equipment so it could try to restart a compressor before refrigerant pressures have equalized after shutting down, which is BAD. On the other hand there is plenty of room for improvement even on the newest control systems for HVAC equipment, especially for residential monitoring….. so keep it up, but remember the price of a new geothermal heat pump unit can be $8-12K USD, so “do no harm” is the rule.

    2. Agree — tight regulation just isn’t practical for a typical home’s temperature control, and along those lines hopefully designer has baked a “cool down” period in during which the device will wait (not call for heat) at least a minimum amount of time before calling again. Modern control furnaces may have this built in, but older electromechanical versions likely rely on the thermostat not rapid cycling.

      Another consideration: My furnace is two-stage but is only “on-off” from a thermostat wiring control point of view (designed for easy retrofit where control wiring is limited) … internally it will operate in 1st stage for 12 minutes followed by 2nd stage. Instituting a (short) maximum duty cycle for the furnace could create a situation where you only allow limited run time in the higher-output stage.

      I’d think a max-min duty cycle makes sense… perhaps 1 minute on time minimum and max on time of 120 minutes with a minimum of 5 minutes between on times.

      1. Some years back, a contractor told me that they’re going with five and even seven stage units. They have an outside temperature sensor too. They too can up a level as required. But over time, the system learns how long at what stage is required, and adjusts a request for heat to go directly to the optimum level for house temperature vs outside temperature. Typically the system turns on more frequently, for a more stable home temperature, but it learns how to not keep having to turn on too frequently at too-low a level. Each level of burner output is somehow able to operate at high efficiency and low emissions.

    1. Yeah, the 7 segments are going to be a big draw if they’re on all the time…

      There’s also a power-applied LED, and several stronger than necessary pull-ups.

      Haven’t looked at the code yet, but hopefully there is a bit of protection in there like rapid flashing the display in a really annoying way to get attention when the batteries are going low.

      Dead batteries in an electronic thermostat are a disaster if you’re not home to notice the problem.

      When I bought my house it was vacant in a New England January. We did our walk through on Sunday, all was well, ~65F inside, but when we returned the next day after closing and it was freezing inside (probably ~45F) — apparently the thermostat batteries had JUST died that night…

      An old LL trick where the tenant pays for heat is to install a mechanical thermostat, usually in the basement near the furnace, wired in parallel with the tenant controlled one, it guarantees a minimum temperature in case the tenants have turned their thermostat completely off (yes it happens, especially with younger/inexperienced folks that head home at Christmas, they may not realize why doing that is so bad)

  2. Typical hackaday comment.

    I’m sure it could have been done with a 555 timer.

    Why not just give praise and support for job well done instead of always trying to cut people down?

    This is a student who says it was “his first electonics project that solved a real problem”. Not only did he make a nice project, he made a great write it up and published the code and schematics for others to learn from. (A far cry from what many hackaday commenter do for the community)

    Job well done Nathan and hope to see more from you in the future!

    1. Ahhh, you’re in the “everybody gets a trophy crowd”. I haven’t seen anything critical just some reasonable inquiries. As a student, what better place to learn than from the comments of others in the peer group.

  3. I don’t get why landlords would care about what you set your thermostat to. In all the rental properties I have lived in (or looked at/seen), electricity (and gas if its fitted) are paid for by the tenant. With the exception of cases like share housing, student accommodation, AirBnB or other special cases I have never once heard of an instance where using more energy for heating/cooling increases the costs for the landlord…

    1. A lot of places include utilities as a perk and are often even not setup to meter per apartment. Having shared walls, your heating needs are often a function of your neighbor’s thermostat setting as well as the weather.

      1. Our newlywed apartment initially had unbilled gas, then they added meters. But someone figured out the meter didn’t cover the gas fireplace in the living room, and quietly spread the word. The other thing that helped our gas bill was our elderly downstairs neighbors. They kept their thermostat in the 90’s, so we effectively had slightly heated floors.

      2. A friend was in a 22-floor apartment building where electricity, heating and A/C were included. As his rent was paid by his employer, we had to figure out the portion of rent that was electricity. Landlord let us see the bills. Huge surprise. As Hydro only had to admin one bill, the three phase delivery to the building was balanced between floors/units, for very efficient usage of to-building power. His share of electricity was 1/5 of an individual unit bill in a similar building with per-unit metering. With per-unit metering, hydro gets to reap $ from the balanced load the building represents…

        He still didn’t want to ‘spend’ his free heat unnecessarily, so as his unit was ‘warm enough’ with a sweater in winter with the heat coming through the floor and walls, he turned it off. He was frequently getting instructions to turn it back on from LL due to upstairs neighbours complaining about cold floors.

    2. It’s not using more energy they’re concerned with, it’s not using enough to keep the pipes in the basement from bursting when they freeze! It’s been my experience that renters have the least clue about thermodynamics and how to wisely use their environmental controls. Before they left the nest, they generally weren’t allowed to touch the thermostat, and weren’t responsible for doing things like changing filters, operating seasonal dampers or hot water valves, and no one really gives new tenant or homeowners a course in how to run their HVAC system. Wisdom is generally gained through expensive repairs, like coming home from holiday to find the new indoor swimming pool that you haven’t paid for yet!

    3. Beyond your experience there are many large apartment buildings with centralized heat systems where there is no way to determine individual usage. The landlord will most assuredly throw you out if you mess with the heating system that serves potentially hundreds of tenants.

      1. The last place I lived with included heat the thermostat hadn’t been updated since the early 70s (I pulled it off the wall one day to check and it had a model and date code I could look up). I spent a couple weeks in early winter trying to adjust in in such a way that it wouldn’t fluctuate more than 5 or so degrees. At the time I had a newborn in the hos6e and he would wake up if the temps in the house dropped bellows 65 and the thermostat had a range of about 17 degrees between shut off and turn on.

        I could have asked my landlord to fix it but he was one of those curmudgeonly old dudes who complained about anything and claimed the problem on his renters and as the rent was cheap comparatively i didn’t want to anger him. Instead I bought a basic digital one and slapped it in place. I left the old one on the counter under it. When we moved out and we did the walk through for the deposit he tried to complain loudly about the “modification to the unit”. I shouted him down pointing out I paid for it out of pocket and it was probably saving him a several houndred dollars by upgrading his his equipment for free. I then told him if it bothered him so much I could put the old one back on now and he could go buy his own. He groumbled a bit but ultimately gave me my full deposit. As I was leaving I saw him throw the old one away and starting pulling the new one off, presumably to reading the model#.

    4. My landlord is terrified of frozen pipes, and the minimum setpoint, dictated in the lease, is 65F. He’d probably have an infarction if I modified the thermostat in ANY way. I had to explain why I have a fan in my window in the dead of winter. I like it a bit on the chilly side ~70F, but my mid-floor apartment absorbs so much heat from my neighbors I regularly come home (window shut when I’m away) to a 75-80F room! My registers only ever come on after running the window fan for a few hours.
      I keep thinking about some kind of window-operating thermostat project, because the outside temperature has a big impact on whether the heat can keep up while I sleep. Unfortunately, my projects are only ever “thought experiments.”

      1. Look at DIY Coroplast based heat recovery air exchange. Has an air in path and an air exhaust path, with a HX (heat exchanger) between them. Many of the HX are cross-flow, but it’s easy to Coroplast a counter-flow unit by having narrow sheets of Coroplast spaced apart by pieces of the same material. The corrugated channels handle air flow in one direction, and the space between them handles air flow in the other direction. Edges and spacing handled by very thin strips of Coroplast, but use little bits in the spaces to create turbulent airflow there to maximize heat exchange. The material of Coroplast isn’t very heat conductive, but it’s so thin, and cheap to make the HX larger, it’s not really material. You want to use two fans, one for intake and one for exhaust, running at equal speeds, so you don’t end up with a negative pressure inside that will such dirty air out of the walls, service spaces, etc.. Don’t use just any fan, but VDC and that will develop some static pressure. Left installed in the window all the time, when running it gives you fresh temperature-conditioned air. Insulate the outside of the unit, and ensure that the outer layers are exhaust layers.

        You can build it to fit in the window, or sit on the floor and use two hoses going to a window fitting like the two-hose floor-standing a/c units use. Insulate the hoses too.

        A good idea to put a furnace filter on the incoming air at intake to the unit, to keep that out of the incoming path and your home. And another on the air intake for the exhaust air, to keep dirt/dust out of the exhaust path.

        Now for your cooling. Have a temperature sensor that opens a shortcut so a portion of cool outside incoming air enters without going through the HX.

  4. I don’t see enough hobbyists using thermocouples in their projects. Once you have a system for creating thermocouples at home from bare wire, it is pretty cheap and much more precise than these modules that often use an RTD. Getting the temperature sensing bit away from your electronics is key, and don’t forget to calibrate!

    1. A thermocouple makes no sense, because it requires measuring the cold junction. But if you can measure the cold junction temperature, you can just take that as the temperature.

      For this application, I would use a simple NTC.

  5. Here in Canada , a digital , UL listed thermostat can be bought for about 40 $ canadian and already has more functions than this (being 5 – 2 day programmable) , is fire-hazard free , doesn’t require batteries and looks a 1000x better. Unless your landlord periodically enters your house to check if you changed his precious mechanical thermostats to digital ones and in the event that he cannot be convinced that digital thermostats will be better in the long run so that he pays for them, which ever money was invested on building this thermostat should have been used on already manufactured hardware. Since this isn’t even a full thermostat, but rather a controller for another thermostat, the only places it will ever be used , is on top of another thermostat. So if he moves ,chances are his hardware because totally useless.

    It is a nice build , but I wouldn’t trust a homebuilt device to manage temperature at my house while I’m away or sleeping. I mean even approved , commercial thermostats have had issues in the past..

  6. If you’re in the USA be aware that if you have a pipe freezing incident it is very likely the insurance company will deny coverage if you have a DIY thermostat.

    Sure you can take it to court and force the insurance company to prove the problem was caused by your DIY thermostat. However if your making a DIY thermostat it’s unlikely you have the financial capability to sustain a court battle with an insurance company. Even if you do win in court it’s very likely your legal expenses will cancel out any insurance payout you win for the damage due to the frozen pipes.

    1. The reality in many big city rentals in these times, is that either you and your landlord don’t speak the same language, or it’s managed by 3rd party property management co that either says no to everything or requires that they hire someone to install it for a $500 extra fee.

    2. Decades ago a buddy taped a small night light bulb (about 5W) just below his thermostat, and plugged it into a mechanical timer. When the light was on it gave off just a bit of heat biasing the thermostat’s temperature by a few degrees, giving him a dirt cheap setback thermostat. No changes to the building or thermostat, no violations of any lease.

      1. This is exactly how the 70’s vintage HeathKit thermostats worked – current flow in one direction lit the bulb built into the thermostat and the other direction controlled the furnace if I recall correctly (only used 2 wires) – all driven from a control box down near the furnace. The control box regulated the bulb current which gave you setback control – more current, more heat in the thermostat, more setback.

        Built it in 8th grade for my parents – you knew setback started when the bulb lit each night.

        Worked great for decades.

      2. This is exactly how the X-10 thermostat setback module worked (TH2807). It was just a heater (adjustable) in a box that you put below the regular thermostat and connected to an appliance module.

  7. Not sure where Nathan is from, here in The Netherlands, on-off thermostats are disappearing altogether. Modern (and even not so modern) boilers are of the condensing type, replacing the on-off thermostat for a modulating one saves substantial amounts of gas as the boiler runs colder, enhancing the condensation energy gains.

    1. You are completely confusing modulated boilers with thermostats. The thermostat has nothing to do with the modulation. With a condensing burner what is modulated is the amount of flame or the amount of gas that is allowed to go to make that flame. Modulation takes place in the boiler. It cares nothing about the thermostat other than the thermostat is either on or off. The thermostat on your wall has absolutely nothing to do with modulation in modulating boilers.

  8. I regularly find my room temp off from what my thermostat says.

    I always found it strange that American central heat has a single temperature controller for an entire house, and why they couldn’t put multiple boxes in synchronized to each other to get more accurate results.

    I would love to have thermal stability of less than a degree in my home, that would make it so much more comfortable right now in winter. It would also make adding a temperature controlled room for my small machine shop at home possible. Seems sometimes a room is 5 degrees colder than my thermostat thinks it is. Now that I see these things use a simple bimetalic strip, I’m not suprised at the inaccuracy.

    Temperature compensation done in watches with just a bimetalic strip was sometimes done as a trimetallic strip, with another metal besides brass and steel, for a slightly higher sensitivity. I wonder why they don’t use something more advanced in modern times than that.

    1. Is there anywhere in the world with “single zone” heating is not the norm? In the Netherlands and Spain (where I lived long time) the norm is ONE thermostat in the living room, and then perhaps a thermostatic valve in some or two of the radiators in the house. Electronic valves fitted in the radiators can provide multi-zone heating but it’s quite new and expensive to set up.

      1. In the alpine regions the usual method for central heating systems is to have a thermostatic valve on every radiator and an outside sensor to control the water temperature, often combined with a time switch to decrease water temperature during night hours.

  9. Excellent project, this is great to see!

    Several years ago I had a need for an internet controlled/programmable thermostat that didn’t cost an arm and a leg. I was very surprised at that there were really no open source projects that tackled this problem at that time. There were a couple ad-hoc projects people had semi-documented for internet points but no actual open source projects available to completely replace your thermostat with something you could easily hack yourself. I started working on something as I had decided this was one mole-hill that needed a mountain under it. But as lots of projects like this go, lack of time and shifting priorities ended up pushing this project to the ever-growing back-burner. I don’t have a huge need for this now, but I still keep my eyes open for a serious contender to arrive in the barren open source thermostat space.

    One silly but big problem I noticed in general was a lack of good enclosures which make an open source thermostat easily deployable. This doesn’t seem like such a big deal until you consider that this is actually a requirement for 99% of users of such a product. There is a standard format that is needed: a wall-mount holder and a detachable enclosure. It’s fairly niche to thermostats, but other devices can use this too. At one point I found an off-the-shelf enclosure that would fit the requirements, but it was a little odd looking if memory serves. Anyway, that ended up being the killer feature that scuttled the project for me; by the time I had located a suitable enclosure the energy I had for the project had moved elsewhere. Of course you can design your own now and 3D print it, that wasn’t an option at that time though.

    1. Re: enclosures. I’m guilty of having built many projects over the years and then losing interest/energy when it came time for the enclosure. A thermostat is going to be unique in most households depending upon the status of the builder. The above definitely would not pass most girlfriend/wife approvals. But for a single man/woman in a solo dwelling, anything goes.

      Regarding some comment way above here, in the USA it’s common for most houses to have a single thermostat, and as stated it’s usually in the living room. Higher end (more expensive/luxurious) homes may have zone thermostats and of course the most expensive homes may even have individual room thermostats all governing a central HVAC with controllable venting.

  10. The large hysteresis of the bimetal switch along with proper anticipator setting turns what would seem to be a bang bang control into a proportional controller. The anticipator action also provides a cycler action with minimum on and off times. A cycle rate curve across the load range than varies the cycle rate. This provides near constant temperature independent of load. A side effect of this is that the thermostat will act as a proportional controller. The industry usually designs this to be something like 3 degrees F at 100% load. There are mechanical means to add integral control but this is not normally done.

    In addition the relatively long time constant of the bimetal sensor provides immunity to transient temperature changes.

    Investigate the the math behind the cycler in this publication:

    Another thing to consider is the sensor temperature coupling to the wall, the ambient air and the radiation to other walls and windows in the control space.

    You also need to consider the local self heating of the thermistor by the thermostats electronics.

    Given the time constants of a normal house a digital thermostat can get by with measuring the temperature once a minute and deciding to turn on or off 4 times a minute. The rest of the time it can spend sleeping.

  11. For more info on digital HVAC control check out Honeywell SPYDER PUL-,PVL-,PUB-, PVB- Controllers, (search for 63-2662).

    The SPYDER controllers build up control logic for a building from graphical function blocks. The CYCLER functional block is a digital implementation of a multistage cycler based on anticipation. It takes in an error signal based on P, PI, PID controller and cycles the equipment based on the configuration of the block.

  12. How about a non-invasive non-contact approach of building a stand-alone temperature regulator which is hung below the original thermostat with strap around the landlord supplied stat? The idea is to set the original stat a few degrees below the desired set point, then have the user-supplied turn a heater strip on and off to modify the temperature detected by the original stat. Yes, it would need external power to be practical, but ought to be within reach of what a mobile phone charger can supply.

    As a matter of fact I’ve seen economizer gadgets advertised that are just dumb resistors in a plastic box that trick the wall stat as described above. I guess it never occurred to people that buy those that they could just turn down the stat. Anyway, the clever hacker could up the game by including a temperature sensor and microprocessor to manipulate the hysteresis of the original stat by applying the right amount of heat to narrow the regulation band.

    As other writers noted, anticipators, short cycle lock-out and multiple stages can confound a project like this. This project is best suited for a simple system like my GF’s apartment that has hot water heat with a simple mechanical stat to open and close a valve in the water loop for the baseboard radiators. There isn’t much chance of anything really bad happening with a simple system like that. I looked inside the stat in her apartment which is an old mechanical Honeywell that has a magnet and a cam that allows the hysteresis to be set between 0.5 and 2.0 degrees F. The landlord (or installer) has the hysteresis set all the way to 2. That seems unnecessarily wide, but we don’t want to change it and rock the boat with an antsy landlord who worries about small stuff.

  13. I did something very similar last summer! I have a window AC unit that cools my room, but the built-in thermostat doesn’t work, so it’s either on or off… Well, I have multiple ESP32’s, I have a web controlled power switch, and I have lots of temperature sensors, so I built my own controller! AC unit plugged into my web controlled power switch, my ESP32 took temperature reading via an LM35 temp sensor (I was able to get 1 degree F accuracy out of it at room temperature via averaging and custom tables and offset), and the ESP32 checked web power switch socket state via http and sent ON/OFF commands depending on state, temperature, and time of day.

  14. Not only will you want time of day set points (such as no heating or cooling while everyone is away to work) this project now needs to include motion detectors. If there is motion, better start making things comfortable again)

  15. Can you program a one of these that will cycle on dew point temperature?

    Temperature alone feels drastically different when affected by humidity. If you look into high performance home and check out hvac 2.0, there is a desire to have a dew point thermostat and nobody is making that.
    If you add in IAQ and data logging that would be a win!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.