>>> 2022-06-22 thermostats
Let's discuss the humble thermostat. You probably have one in your house, and it probably connects to a set of wires. If you've ever replaced your thermostat, you've probably found those wires a little irritating due to the lack of well standardized nomenclature for identifying them. This is particularly clear in the new generation of smart thermostats which attempt to be "consumer-friendly" to install, and thus must have sort of complex install wizards (InstallShield (R) for Thermostats) just to generate your hookup instructions. So what's up with that?
Well, let's take a step back.
Your house is full of a bunch of 120VAC wiring. Well, that's assuming you live in the United States, and to be fair US residential wiring is typically 240v split phase, so you have both 240v and 120v wiring, depending on how you count. The idea of this split phase thing, if you're not familiar, is that the utility delivers to your house 240VRMS AC with a neutral wire that is at a potential halfway between the other two pairs. We could label this -120V, 0V, and +120V, which while "0V" is always arbitrary makes some sense since neutral is bonded to ground. These are all of course VRMS, which in this context is Volts Root Mean Square, not Virtual Richard M. Stallman (which is a piece of software that chastises you for being complicit in your own subjugation). Since AC implies a voltage that changes constantly, there are a few ways to measure, and VRMS is conventional. 120VRMS is about 170V peak to zero, or 340V peak to peak. We call it 120V because, well, that 170V only exists briefly at the two peaks of the waveform. 120V is a more useful number for actual power calculations, although AC power calculations can always become a bit complicated because the phase relationship of potential and current can vary (this is called power factor). This is all basically an irrelevant tangent, the point I want to make is that we all understand that residential electrical wiring is 120VAC or 240VAC depending on how you look at it . But after all that, what if I told you that it is also conventional for residential electrical systems to have a low-voltage AC supply?
Well, it's true, but in sort of a limited sense and with a lot of variations. Almost all homes have at least one small transformer mounted on the side of a junction box in a basement or closet that produces 12-24VAC. There are two standard residential applications of low-voltage AC: the first is the doorbell, which typically uses 16VAC although 12VAC and 24VAC doorbells also exist. The second is the HVAC control circuit, which is nearly always 24VAC. Most of the time these have two separate transformers but you can use one for both purposes, although I'm not sure that it's wise or code compliant.
The reason for the low-voltage supply is that, in most cases, the thermostat switches low-voltage, current-limited (by the transformer) circuits that energize relays in the actual furnace/AC/etc. This allows thermostat wiring to be significantly smaller, and thus cheaper and easier to install. Code requirements for thermostat wiring are particularly lenient due to current limiting in the transformer, so they're commonly only 18 AWG. 18 AWG is small enough that the NEC ampacity tables don't even go that small; it's just not permissible for non-current-limited circuits. The size savings are particularly important since thermostats are most often hooked up using a five-wire cable.
The wires connected to a thermostat are conventionally identified by letters (but usage of these letters is not entirely consistent) that primarily refer to the conventional colors of the wires (while obviously a terrible practice, I have encountered thermostats where the colors were not used according to convention). In other words, if you are wondering what the "R" wire is, it's the Red wire. That's what R means. Similarly G for Green, Y for Yellow, and C for Blue (not to be confused with B for Blue). That's a joke, C is for Common, but the wire is conventionally blue, but a lighter blue than the B wire. Sometimes it's not blue. C is probably the one that varies the most.
Conventional (four|five)-wire systems
What do all these wires do? Well, the R or Red wire is the 24VAC power supply. Less commonly, there can be separate R wires for heating and cooling, usually labeled RH and RC. This usually happens when the heating and cooling equipment are in different locations and installed at different times, so they each have their own transformer without a connection between them. This actually comes up a lot in New Mexico because of people replacing swamp coolers with refrigerated air, which is often easier to do by putting a package unit (condenser and evaporator in one unit) on the roof on the original swamp cooler plenum. In this case the entire cooling system, from compressor to indoor air blower, is all on the roof and usually has its own thermostat wiring run .
The basic concept of the thermostat is that it takes the 24VAC supply and connects it to other wires, which go the coils of relays in the heating or cooling equipment to actually turn things on and off. The most common of these wires are W (White) which activates the heat, Y (Yellow) which activates the cooling, and G (Green) which activates the fan. A typical simple thermostat installation only provides these four wires: R, W, G, and Y. G is provided as a separate wire for the fan to enable the fan auto/on switch that most thermostats have.
But there's sort of a problem with this standard setup: 24VAC is available, but it cannot be used as a general purpose power supply! The reason is that there's no neutral wire to connect the 24VAC to that doesn't cause something in the HVAC equipment to turn on. This is why many digital thermostats are battery powered. Historically, the thermostat wiring was strictly a control circuit and could not be used as a power supply.
Modern smart thermostats, though, involve typical computing industry horrors like running a complete Linux environment, and therefore cannot run off of AAs with any reasonable lifespan . They require a constant external power supply. This means they need a common, or C wire, which functions as a general purpose neutral. The C wire is a relatively new innovation in thermostat wiring and so a lot of homes don't have one, and on those that do the color can vary. Both blue and black are fairly typical. The C wire is only used if you have a thermostat that expects an external power supply; mechanical thermostats and older digital thermostats typically did not. Many newer digital thermostats can function off of either a C wire or batteries, but the combination of both is ideal since it avoids regular battery changing but also allows the thermostat to keep its clock during a power outage.
So now we have five wires, which as I said is the most common in a modern residential installation: R and C (24VAC and common), G (fan), and W and Y (heat and cooling).
There are more.
Some houses have more interesting HVAC equipment that involves extra wires to control extra features, or that for historic reasons just uses a little different control scheme.
Some homes are equipped with two-stage heat, two-stage cooling, or potentially both. Two-stage cooling seems more common but that might just be because I live in a climate that rarely stays below freezing all day, but does require all-day cooling more often than I'd like to admit. In most cases thermostats exercise only "bang-bang" control, a term that means that all they can do is turn a fixed heat or cooling output on or off. But in a two-stage system, there is a "low" setting and a "high" setting. In AC this is often implemented by having two compressors.
For two-stage systems, there will be two wires, one for each stage. These are usually called W1 and W2 for heat, and Y1 and Y2 for cooling. W2 is usually, but not always, brown, and Y2 is usually, but not always, light blue.
Heat pumps usually add one difference and potentially a second. First, heat pumps typically have some outdoor temperature at which they are no longer more efficient than resistive heating (or in other words they become 100% or less efficient, when heat pumps are typically more than 100% efficient. For newer heat pumps this temperature is usually low enough to be pretty uncommon, but older heat pumps in colder climates may get into this situation regularly.
Heat pumps are almost always installed with resistive electric heating for this situation. Switching to resistive heating in excessively cold weather basically makes 100% the minimum efficiency. Older heat pumps usually called this feature "emergency heat," but "emergency" sounds sort of dramatic and may have been a factor in people avoiding heat pumps ("do heat pumps run into a lot of emergencies?"). As a result, newer heat pumps and thermostats tend to call this "auxiliary heat." Either term works but auxiliary is probably better since it clarifies that the resistive heating is not just for situations where the heat pump has failed (although it is a cool bonus that heat pumps usually provide redundant heating, unlike gas or conventional electric heaters).
As you'd imagine, there's a wire for that. It's labeled "X" or maybe "Aux.", and it can be basically any color. There's no agreed upon norm.
I'm actually oversimplifying somewhat as "emergency heat" and "auxiliary heat" are technically different things, but it is still largely true that auxiliary heat has replaced emergency heat. What happened is that older heat pumps usually only used the resistive heat if the user turned on a switch on the thermostat, usually in response to loss of heat---an apparent emergency. Newer heat pumps usually turn on the resistive heat automatically, either when the outdoor temperature is too cold or when the thermostat is trying to close a large temperature difference quickly in which case the auxiliary heat just provides a boost. This is sort of a two-stage heat system. These newer systems still usually have an "emergency heat" switch on the thermostat which just forces it to use the auxiliary heat only, should the heat pump have failed.
As an additional complication, some heat pumps use a fundamentally different control scheme. I have never personally seen one of these, but I have read that some brands still work this way. To understand it we need to consider how a heat pump actually works: fundamentally, a heat pump does the same thing to heat and cool, but the direction of the loop is changed. This is accomplished by a "reversing valve." While many heat pumps have a heat and cool input (W and Y) and set the reversing valve and run the compressor based on those two inputs, some heat pumps use the W wire to run the compressor and then have an additional wire which sets the reversing valve as a separate function. The reversing valve wire may be powered for cooling (called B), or powered for heating (called O) depending on the manufacturer. Trane heat pumps seem to use a particularly eccentric scheme where B and O are both present but B energized is the same as the un-powered state, B is used a a common wire (it doesn't do anything, just like C on most thermostats) except when O is energized.
These wires are usually blue and orange, and called B and O as a result. The functional equivalency of these wires in certain combinations with W and Y wires results in a lot of thermostats having terminals that are labeled for both functions, which leads to further confusion.
Everything I have said so far relates to conventional control voltage thermostats, which are most common because of their low install cost and universal support in forced-air furnaces. But line-voltage thermostats, which directly switch power to the device, also exist. Line-voltage thermostats are very common in my region on swamp coolers, which have relatively low current consumption and are traditionally controlled manually by a rotary switch or set of light switches. Most swamp cooler upgrades to thermostatic control are just done by putting a line-voltage thermostat in place of the old manual switches. These thermostats are somewhat specialized since there are operational factors specific to swamp coolers, for example the desire to pre-wet the media before starting the blower and the popularity of two-speed blower motors.
Line-voltage thermostats are also common with radiant electric heating systems like baseboard heaters and underfloor heating, where they're installed very near the heater more or less in line with the electrical wiring already going to it. They're also common for hydronic (water) heating systems, but this is a bit of an odd case as hydronic thermostats are still usually just actuating a control circuit... it's just that typical hydronic zone valves operate at line voltage, not low voltage, and actually have a fairly substantial current draw.
Of course all of this nonsense with wires can be a huge pain, especially on a retrofit installation of central heat or when relocating a thermostat for better performance. To ease these kinds of situations and create a fun new set of failure modes, there are plenty of options for wireless thermostats that communicate with a box that "emulates" a traditional thermostat. The receiver/controller can then be connected directly to the HVAC equipment and the thermostat can go wherever you want. I had one of these once and the thermostat required 8 AA batteries that died constantly. There have probably been advancements in recent years.
This simple scheme of the thermostat energizing relay coils is not very practical in commercial buildings. In fact, it's not that practical in residential buildings today either, and in modern heaters and air conditioners the thermostat wires are not necessarily connected to relays but instead may just be logical inputs to a control board. Still, the necessity of five or more pair wiring to each thermostat is a cost issue in commercial buildings where it is typical to have one thermostat in each room.
On top of that, commercial buildings tend to have a more complicated system design in which variable air volume (VAV) equipment is used, which means that thermostats control the amount of air delivered to a room instead of whether or not heating or cooling is active.
Historically, variable air volume commercial HVAC systems were often pneumatic. Rather than pressure based, they were vacuum based. Somewhere centrally in the building, a vacuum pump pulled a decent volume of air through a system of tubes running throughout the building. Vacuum lines were run to variable air volume dampers (VAVs) and then to thermostats. In response to out of range temperatures, thermostats would close or open the tube to the room air. In response to the change in vacuum pressure on the line (which would increase, or rather go more negative, when the thermostat closed its valve) a pneumatic servo actuator in the VAV would adjust the damper. If you've heard a thermostat making a constant faint whooshing noise, that's why... it's a pneumatic thermostat admitting air into the vacuum line.
Of course this pneumatic scheme had its downsides, and as technology advanced it became more attractive to use an electronic scheme. I am not very knowledgeable in this area, having had only very limited interactions with commercial HVAC equipment that mostly mounted to some collegiate security research on manipulating the temperature of unpopular faculty member's offices. Most modern commercial HVAC systems do seem to have consolidated on BACnet, which is a general purpose communications protocol for building automation equipment that originated in the HVAC industry (with a trade group called ASHRAE).
BACnet is a fairly simple protocol (intended for easy implementation on embedded devices) which has a lot in common with other protocols for similar use cases. It's primarily what I call a "high level remote memory access" protocol, meaning that it fundamentally consists of commands to read and write addresses (called "properties" in BACnet, unlike say modbus which more clearly shows its RDMA basis by calling them registers). BACnet enhances this model a bit by adding a simple discovery scheme that makes setup of BACnet networks easier. BACnet also specifies a set of standardized properties or addresses that facilitate compatibility between vendors.
BACnet is agnostic to the physical layer, which can be Ethernet but is often RS-485 or proprietary protocol LonWorks. An interesting property of BACnet is that it seems to be fairly common for access to the BACnet physical medium to be fairly easy to obtain, for installer convenience. In other words, a lot of commercial thermostats just have a Euroblock-type connector on the bottom that can be used to connect to the BACnet bus. You can imagine the potential.
 Unless you're on three phase delta power, which is a weird thing that is common in apartment complexes. Then you have 120V and 208V for reasons that require trigonometry.
 I live in a house with what I would call the New Mexico Transitional configuration, meaning that I have a normal AC evaporator mounted on my central furnace, but the condenser is nonetheless sitting on a platform on the roof on top of the old swamp cooler plenum. I think when there's already a roof frame for the swamp cooler this is just easier than putting the condenser on the ground, especially since the refrigerant lines can be run straight down through the old plenum or heater combustion air duct. It has the downside that the central furnace and AC continue to use the old swamp cooler plenum which is poorly sealed where the swamp cooler was removed and loses a lot of conditioned air into the attic. Nothing that eighteen cans of Great Stuff can't fix.
 This is not strictly a limitation of smart thermostats, I've used an Emerson Sensi thermostat which is WiFi-connected but still manages a reasonable life off of battery power. Of course it has a basic LCD display and physical buttons, not the full color touchscreen that everyone demands these days.