Thermostat
- Authors
- Name
- Matt Nodurfth
In our home in ever-winter San Francisco, we experienced consistently chilly mornings and evenings. (Thanks Karl.) Waking up in a cold dark house is absolutely no fun, so I set out to fix it! We had an outdated, non-digital thermostat, which I could’ve easily replaced with a modern Wi-Fi-enabled one. However, I was eager to dive into the world of 3D modeling and additive manufacturing, so I chose a different path. To build a reversable/non-destructive module I can mount directly on the existing thermostat.
I started by turning on my 3D printer and gathering various spare components from my workshop, such as thermocouples, a spare servo, and an old Raspberry Pi. The first piece I created was a friction-fit backplate for the thermostat for mounting all the components. I measured the existing thermostat housing and used Blender to design a simple backplate. Then, I modeled some arms with adjustable holes to attach the thermostat's control arm to the servo motor.
Following the modeling, I wrote some code to act as wrappers for the thermocouple and servo libraries, allowing initial command-line control. The interesting thing here was to map a servo position to an approximate temperature value. After the system was functional, I mounted the components onto the backplate, connected them to the Raspberry Pi's GPIO pins, and proceeded to the fun task of coding. The goal was to operate the thermostat from our phones using a web server hosted on the Raspberry Pi. But mostly to never have to use the app as the system would manage temperature automatically.
For the server, I decided to explore Go to build the API, and it excelled in terms of speed and ease of development for such a simple project. Especially nice as it bundles into a binary. In terms of the UI, I chose the now mostly deprecated template, Create React App, as its an easy way to start React project scaffolding. Then I added some Tailwind CSS for styling.
For state management, I just wrote basic configs to a database file on the OS; this way, temperature and system continuity survived any crashes or power outages.
For the routing to the webserver, I set the project up behind a simple nginx proxy.
The main functions for the GO API server are to act as a chron job scheduler to turn the thermostat on in the mornings and off at night and allow for changing the temperature during the day.
This was quite a fun project that really helped with comfort and efficiency - keeping the thermostat on when we want it and off when we don't.
The entirety of the code for this custom thermostat project—the hardware management, API, and UI—is available on my GitHub (https://github.com/nodu/thermostat).