67 comments

[ 0.23 ms ] story [ 143 ms ] thread
I previously put together something like this, but my only gripe was having the usb cable hanging down to an outlet to power the whole thing. I tried a solution by scrapping the Pi, using a nodemcu with a portable power bank and putting the node in low power mode and only regularly coming on to check for updates and to update the thermostat state, but then it became just another thing to charge, so I scrapped that too, maybe a revisit is in store.
I’ve got several PoE devices in places I don’t otherwise have power. Could work for your case and generally easier to run than power.
You might be able to run your doodad off of the thermostat wiring. I think there is 24v ac power?
Trouble with it is that they often times don’t include a ground wire. All the thermostat does is connect the power wire to the given function wire (like “fan on” or “heat pump 1 on”. I am not an expert but having installed a number of thermostats in a number of homes, all the manuals talk about the ground wire being rare and I have never seen one. If you are lucky you might have an unused wire that you can find a ground for, but I have only seen that once. Somehow when houses are wired it seems the HVAC people are very efficient with using the exact right number of wires in a single cable.
Commercial solutions have a rechargeable battery and cycle one of the circuits occasionally to get power to recharge

This can cause trouble

Ecobee (probably others) provides a Doo-dad that wites into the furnace to help make this work

You can always run a new one. I bought new wire at Home Depot, tied it to the old cable, and pulled it down to the basement.
That only works if they didn't staple it to the wall or bury it in spray-foam insulation. I ended up having to run a new one but was lucky that the floor-board was under the garage. I ran a piece of cat5e as well in case there is ever an option to get a thermostat that can use it.
I have yet to see the wires that aren’t staples to the inside of walls. If it’s an option, great but IME it’s rarely an option.
High voltage wiring has to be secured, by code, but low voltage thermostat wires don’t, so it’s more likely that you can pull them.
Ok but if the roughly 15 thermostats I have replaced in 8 buildings it has always been secured.
I wasn't a fan of messing with the thermostat housing but just now after pulling it off, I think my thermostat isn't anything fancy like that, just two black load and two red line wires. It's also important to note that my thermostat connects to baseboard heaters, not an HVAC system.
Even ones connected to fancy heating and cooling systems aren’t that complex and instructions are usually spot on. A simple heating system like you describe is, well, simple. Connect wires, get heat. I’m sure you can figure it out.
The following is relevant to your comment, since you I think are talking about a standard, conventional setup. In contrast, the article has a weird setup for an apartment.

There are adapters you can use to work around the lack of wires. The existing wires already include power, it's the ground that's missing.

The existing 4 wires to a standard dumb thermostat are:

Power

heat

A/C

fan

The functions are enabled by connecting power to whichever is required. But there is a missing "C" (common) wire. So, as you discovered, smart thermostats have no easy way to also power themselves.

I was lucky when I added my smart thermostat. It turned out that my 20 y/o house already had an 8 wire cable preinstalled.

For people stuck with 4 wires, there are adapters available that will multiplex two control signals onto one existing wire. This lets you free up another of the existing wires to become the needed fifth C wire.

Here's one setup I found with a quick search. There's even a video. This adapter requires access to both ends, viz. the thermostat and the furnace.

https://smartthermostatguide.com/c-wire-venstar-add-a-wire-a...

That Final Thoughts section is... odd. Stealth sponsored advertising?
Unlikely as Pi-hole is free and can't really afford to spend on marketing. it is an excellent piece of software though.
Not at all! I just really liked their project and thought more people should know about it. They made a pretty complex thing really easy to setup and very reliable.
I “upgraded” my HVAC to a super modern heat pump with fully variable compressor for efficiency. But the only thermostat that can drive it is a crappy Trane 1050

The remote thermostats can only be averaged and not switched (eg Measure Bedroom at night, Living Room & Office during day)

There’s only 4 time blocks per day

There’s no adjustment of start time based on outside temp. In fact, no way to say: Be at 72 at 8am when I get up

There’s a ”quiet mode” to reduce speed (and noise) at night, but clearly this is on an internal timer. It will come on at 67% for up to a minute before the timed Quiet Mode Function notices and scales it back to the pre-set maximum. Sadly, I’m already awake by then.

(Also, the default values at install are wrong - they have Day and Night switched)

Since this is the smartest thermostat they do for this, can they at least open up the API so I can have a chance to get back the features I liked about my Ecobee?

For so much money, there is so little “smart”

I think I can use what APIs I have to implement the OP solution without mechanical switches, but I can not control the compressor speed directly for Quiet Mode to work

Are you just supposed to run it more?

Or is it hard to keep things comfortable with the inputs you do have?

Since it’s a heat pump, the ability to heat the inside depends on the outside temperature. Warmer outside, faster to heat inside.

But there’s no way to tell the system - I want 72 at 8am, you work it out. So I need to see if tomorrow morning will be 30 or 50 outside and set the start time accordingly. That’s not smart.

Heat pumps aren’t great at large changes anyway, but even 68 to 70 or 72 would work for me

And I also want that inside temperature to be based on the rooms I expect to use at those times: Night time, bedroom. Daytime, living room. Ecobee has exactly this function, Trane/Nexia does not

How many degrees below your occupied temperature are you setting back?

I have a ground source heat pump and my understanding was to pretty set and forget unless you have multiple zones or are going to be away for a long period of time.

Reason being heat pumps have variable speed compressors and setting them back forces them into less efficient higher stages, and as you mention take a lot longer to recover compared to traditional heaters. If the system is sized right it should be running it should be running below max at a relatively stable power.

That's what I meant by using it more. If you just set everything to 72, then presumably the rooms will be that temp when you use them. Doesn't help if you want to sleep at cooler temps of course.

This would be a pretty reasonable approach in a building with high levels of insulation and efficient heating/cooling.

I have a similar thermostat, and I ended up going the Home Assistant route with the Nexia integration[1]. It still relies on the Nexia cloud, which is unfortunate, but it lets Home Assistant directly control the temperature.

I don't think it'll let you use Quiet mode, but it will let you do all the other thing you're missing, and it'll be much simpler than building out everything yourself for sure.

[1] https://www.home-assistant.io/integrations/nexia/

I do have Home Assistant, and have thought about writing the code for this. But then it’s all On/Off, with no access to the variabe compressor speeds of the system I paid quite a bit for (as it’s more efficient)

Quiet Mode is clearly a checkbox festure they added for the city of Seattle noise ordinances (mentioned in the sales literature)

There are relatively inexpensive Z-Wave thermostats on Amazon, if you'd like to avoid the internet-connected requirement in the future. I have a couple of GoControl's.
My house has a Carrier Infinity system where the compressor and air handler is fully variable. It can retrieve weather data over the net and adjust heating/cooling. The compressor and air handler are "connected" which is HVAC lingo for a proprietary protocol. The brains are in a $700 thermostat with a buggy touch screen that has the resolution of a lite-brite and it cannot work with virtual assistants.

One benefit I did see in the manual, is that if the air handler was gas combined with a heat pump you can enter the price of electricity and the price of gas and it can compute which heating method is best: gas/heat pump/resistive (usually when heat pump cannot provide requested temperature). But I don't have gas.

ROMs are available for these systems distributed as hex files on Carriers website. So its been on my todo list to reverse engineer the software.

Someone with time combined with a Raspberry Pi + Raspberry Pi Display (around $80 USD) could build a much better thermostat than what Carrier has done.

At my house, Trane lost a sale because of that incompatible proprietary protocol. I really wanted to super modern heat pump with fully variable compressor. I refuse to be stuck with one vendor. I'm also not putting my system on the internet, though of course IP protocol within my own home could be nice.

Maybe the answer is to look at systems sold for business use.

This is cool! I've often felt tempted to build something like that. I'm disappointed by how overpriced and terrible commercial thermostats are - try finding one that can actually switch from cool to heat automatically, isn't super-cumbersome to set up, and doesn't cost several hundred bucks.

It's also a bit sad how hard it seems to be to get Google Home to be able to control custom gadgets.

And combining Python scripts with a Spring Boot webapp - why? Seems like a good application for Flask. Why use 2 languages when 1 can do the job?

This one wasn't that cheap tbh. Without the legos and with all the bad sensors I got, it cost around 130ish.

I was surprised at how difficult Google Home integration it was yes.

I see what you're saying. I honestly used Spring Boot just cause I'm really comfortable with it and can get something going quickly. It later on worked well for the Google Home stuff since they have examples and docs in Java/Kotlin. It also doesn't look like they have Python support.

Lego is still so underrated. Love https://ngrok.com too, ends up being so randomly useful, one of my favorite tools.
> “The simple stupid approach for the logic is as follows: keep the apartment temperature as close as possible to the temperature we set. This is not realistic as it would keep turning the system on and off very frequently, thus why the system needs a tolerance window.“

Certainly an accurate observation, and what is typically known as hysteresis for those playing along at home.

I mention this because sometimes when you self-discover something, you struggle to identify the most common word to describe it, which can obscure lots of research and prior art about that thing.

Because applications of control theory are so practical and likely to be empirically observed, it’s probably pretty common to have observations like this.

> you struggle to identify the most common word to describe it

In case of temperature control, the magic word (acronym) was "PID" which I learned from a friend who set up an open-source bbq controller:

https://www.raspberrypi.org/blog/heatermeter-open-source-bar...

https://en.wikipedia.org/wiki/PID_controller

Bang-bang[1] works fine for home heating applications, and is used by every thermostat I’ve ever seen. PID is more useful if your system requires/allows fine adjustments rather than just switching on and off.

[1] https://en.wikipedia.org/wiki/Bang%E2%80%93bang_control

My 18 year old central heating system already supports modulation. Surely these days most support it through some open control standard such as OpenTherm?
Mine also, my heating is often running at ~40° unless it's bringing it up from being off overnight or something. Recently I installed a Nest thermostat and doing reading around it suggested that in the US (I'm in the EU) OpenTherm may not be so common, so perhaps they don't tend to use systems that can do modulation much there.
It seems like the PID can be used to control the bang bang intervals?
Absolutely - I've done this in industrial facilities and it's very common with LED's where it's generally called PWM (Pulse Width Modulation). Somewhat obviously, you'd generally use a "hidden layer" converting the % output of the PID algorithm to % duty cycle.

This works if your device can have a short enough cycle time for the PID algorithm to receive reasonable response feedback to its output. Ideally for PID to duty cycle conversions, your system should be low frequency (large "inertia") and the physical actuator/device you're controlling should have a high frequency (able to turn on/off rapidly, as LED's can with PWM).

The difficulty for home HVAC is that you'd like to start/stop it as rarely as possible to extend the life of the motors. The cycle frequency ends up being in the same order of magnitude relative to the frequency that the house heats and cools.

Obviously you can tune these things until the cows come home, and eventually you'll probably find some good settings. In reality, most people/installers/technicians will improperly tune a PID loop, especially if it converts to % duty cycle.

Hysteresis will almost always work better for home HVAC.

Alternatively, you can install (somewhat expensive) variable speed AC units and then happily use PID. You'll probably save a bit of energy and be more comfortable overall with more precise management of not only temperature, but also humidity.

(comment deleted)
TIL, thank you:-)
Do you perhaps have recommendations on how to control:

1x central heater with:

.. state: on or off

.. actions on or off

Nx Temperature regulator valves

.. state: current temp, target temp, percentage open

.. actions: set target temp only

What control loop do I use to control the central heater on|off based on the state of the TRVs? To maintain distinct temperatures in different zones’ TRVs

If your regulator valves close completely when target temp is reached, this should work:

- Set target temp for each room.

- Implement 2-step control using min(current_temps[]) and max(current_temps[])

So basically:

- if any room is below set_temp - X degrees, turn on

- if any room is above set_temp + Y degrees, turn off

Log and plot the temperatures, you should see some kind of sawtooth wave that flattens at the peaks due to the valves closing. Adjust the X/Y values to start/stop heating earlier or later to reduce the temperature variance.

Thanks a ton! I'll try it out, maybe even do a write up if I succeed
and now I have two more magic words :)

(btw I wasn't saying PID is what this situation needs, I meant that knowing that term unlocked a whole lot of interesting history and applications and more)

You are still talking about different systems dispute them both having to do with temperature. An AC unit can only be on or off, so you need a window, hysteresis, to keep from toggling on and off constantly. If you can input an analog signal, like control how much power goes into the heating coil in a BBQ, the PID is applicable. PID, if tuned properly, will find the right amount of power to feed the heating element to keep the oven at the desired temperature. This is not possible if you can only turn the AC on/off with significant lag, so you need hystereiys.
PID can be used with an on/off control, you do something like PWM: on X minutes out of every hour, and vary the X as the analog parameter.

Don't know how easy that is on the AC/heating, but as far as the control system, it works, and it's PID.

PID can’t be used for control of any device that uses a relay. PWM will have the effect of just changing the coil voltage. Even if you could switch a relay on/off quickly you’d just prematurely burn out the contacts.

PID is only effective with solid state switching devices, which are not really common for residential heating/cooling.

Did you even need the D, wouldn't a PI controller be sufficient?
The point is that once you know the word PID you can read about the concept and reach conclusions such as yours.
The article project is already using a Pi controller.
PID is very simple control loop that will show over/undershoot every time there is external change (for example somebody opens a window) and will take a long time to settle when disturbed.

I would use a simple model of the room (as a thermal mass with three components -- heater, air and walls -- that heat up / cool down / exchange energy at different rates).

Then I would run moving horizon estimator to predict future effect of turning on/off the heating system (for example, if I turn it off now, what will be the final temperature before it starts to drop again?)

Then you include Kalman filters to discover basic parameters of the model and then update them as system change (for example external temperature changes) so that predictions of the model are accurate.

You can even monitor the parameters of the model and response of the system and recognize different situations like open doors, windows, etc.

For example, I have made similar for my dumb espresso machine and by monitoring parameters of the model I can detect boiler scale buildup and then I can detect whether I have cleaned all scale from the boiler or there is still some of it left. It is all very simple because there are two parameters of the system: thermal mass and delay from when the heater is engaged to when the water has reached its temperature. By detecting that thermal mass has decreased and that the delay has increased it can automatically tell there is scale buildup.

What do they mean by "The temperature dial doesn’t work"?

It seems like they might mean it doesn't control the air temperature of the HVAC, but that isn't what it is supposed to do, it's the thermostat.

If they mean it's broken, well there you go.

I am far from an HVAC expert, but I think these lines from the article help clarify the issue:

> The temperature dial doesn’t work, the building controls whether its heating or cooling time.

> The fluid temperature is out of our control since the building adjusts it based on the outside temperature.

It doesn't sound like the device they have available is actually a proper thermostat- rather, it's just a control device for a water heater + radiator + fan. The switch adjusts how fast air is blowing over the radiator, and the dial is supposed to adjust the temperature of the fluid in the radiator.

But if I understand correctly, the building sets their radiator fluid temperature for the whole building, and it sounds like the fan speed is apparently useless, so the only control the author has over their unit's temperature is whether or not the fan is on or off.

So, what they built is the actual thermostat, which mechanically actuates the on/off switch based on a temperature measurement.

What I would expect under the circumstances you describe is that the knob controls the temperature at which the fan turns on and off. It sounds like the building installed the wrong device for the job, or didn’t hook it up properly, or it’s otherwise broken; hard to tell from the article which of those options it is.
Not hooked cause the valve it's supposed to turn to control the fluid in the pipes is stuck.
Right, what I'm saying is that no heating system would work like that, the fluid temperature is set at the furnace (the controller might vary it based on the outdoor temperature or other factors, but it's not a directly adjustable user input).

The likely function of the dial is to set a temperature where the fan turns on and off.

It's not hooked up. The valve it's supposed to control in the pipes is stuck.
I’ve been in the middle of making a similar system for my own apartment, mainly out of frustration that I keep forgetting to turn the heat down at night. It’s less relevant since I’m working from home right now, but I also have plans to add geofencing to turn the heat down when I’m not there and back up again when I head home.

I had the parts I need 3D printed, partly because it looks a bit nicer and partly because I need to replace the knob with one that’s easier to attach a servo to, and so needed something with a D-shaft. Designing those parts made me learn more about gear measurements than I ever thought there was to know. Like the author I went with the DS18B20 1-Wire temperature sensor, mostly because it was the first thing that came up on Sparkfun, so I’m glad to hear it was a good choice.

I’m using an Arduino to drive the circuitry, sending the temperature and receiving control commands via serial over USB to my home server. This works pretty well (and allows for fancier logic than doing it all on the Arduino), but has the interesting result that when I’m compiling software the control program can get swapped out and my heat switches off (or rather, gets turned down to 55°F) until the thermostat daemon gets paged back in!

The last part about the thermostat daemon is pretty cool. I set the system to always switch off when it turns on.

How fancy do you plan to go with the control logic?

For the first version I’m just doing a hard-coded daily schedule, plus a button to bump the setpoint up briefly if I get a chill. The server is still useful even for this simple setup because I can just use the NTP-synced system clock instead of having to mess around with an RTC on the Arduino, and also so I can log things for later analysis.

In the long run, I have a bunch of ideas bouncing around in the back of my head that I might get around to eventually: the aforementioned geofencing, interfacing with an automatic alarm clock (also not built yet) to turn the heat on right before I get up, detecting when I go to bed rather than having a set schedule, determining my preferred temperature based on the weather (I think I mind the cold less when it’s raining), running the ceiling fan (in the summer, and maybe also to pull heat down from the loft in the winter), and so on. No idea if I’ll actually do any of them, but the option is there.

I think my biggest takeaway from this (very cool) writeup is that I'm an idiot for buying cases for all of my pi zero projects instead of digging into my kids' box-o-legos.
I don't quite understand why he could not detach the cover of the thermostat and connect the wires of the switch directly into the raspberry pi. Would it not be possible to do this in a non destructive way?
Yes, I thought about it and touched on it in the article. I just didn't want to mess with the control unit given how old the building is, I'm renting, and I have no prior experience in wiring electrical stuff. Also by doing like that, I run the risk of ruining something in the control unit and living without temp control until my landlord feels like fixing it.
> The pursuit of minimizing my commute to work led me to move into an apartment with no temperature control. Given how common this is for downtown Chicago apartments with reasonable rent

What kind of third world shenanigans is this?

If you live in Europe, your heater highly likely has OpenTherm (which is not as open as the name suggests). So instead of playing with lego you can buy/build an otgw[0] which will MITM your heater and thermostat communication, allowing you to add your own smart solution on top. You can still use the outdoor temperature sensor (if installed), thermostat control logic, etc. But you can intercept and rewrite commands so you can set temperature, date/time and other heater/thermostat settings. And snoop on messages like internal temperatures from the heater and things like water pressure.

[0] http://otgw.tclcode.com/