Hardware suggestions for D1 mini controlled thermostat

I've been trying to replace my existing thermostat with a custom one and am running into a issue with powering the device. I've been using a sunfounder 5V relay board to connect the R (power) wire to the G/W/Y wires to turn on my fan/heating/cooling based on logic from the D1 mini (ESP8266) and a DHT20 temperature sensor. The relay requires quite a bit of power & my 4AA batteries in series only lasted ~1 week. I know a solid state relay board would theoretically require less power, but I don't think its sufficient to make the batters last months/a year time frame rather than lasting weeks.

I'm assuming my existing thermostat is somehow siphoning power off of the R wire, probably while the fan/heating/cooling is connected by a relay (unfortunately no C/Common wire so its not just powered actively from the wall unless there is trickle shenanigans?). Does anyone have suggestions for what kind of hardware I could use? I'm guessing there is some hardware out there that shifts the power draw to the connected AC wires rather than from the DC power I'm supplying from my battery pack to maintain the relays, but I'm not familiar enough to know what I should be looking for. Thanks!

I am not familiar with that part I will assume it is a typo and you actually have a ESP_8266 D1 Mini.

There is not even enough information to make a decent SWAG. For starters, what is that thing you are controlling? From your description it appears to be a central heating control, possibly for a furnace. In my experience, most of those were 24V AC, not DC.

As for your running time, that sounds OK as there are no details such as an annotated schematic or your code. Here is what I would expect.

Wi-Fi transmitting: 70-200+ mA peaks
Normal running with Wi-Fi connected: 60-80 mA
CPU active, Wi-Fi off/sleep: 15-25 mA
Light sleep: about 0.5-3 mA
Deep sleep (bare ESP8266 chip): very low current

Doing the math:

2000 mAh / 70 mA = about 28 hours

Either you have some amazing batteries or the ESP is sleeping most of the time.

The relay board requires about 20 mA. A small SSR module requires about 3-10 mA, or roughly 50% of what the relay uses.

At this point I suggest you put your parts in a box. It appears you purchased them before working out the problem and are now simply looking for a project for the parts.

The best thing you can do is start from scratch and write down your specifications, including defining the load and the power available from the device you are controlling.

You are correct on the typo, its an 8266. And yes, the ESP does in fact sleep for a significant portion of the time. The relay board I have is powered by DC, not AC, and so is the D1 Mini, hence my usage of a DC power source for both of them. A home thermostat usually enables/disables 24V AC control signals to furnaces/AC's/fans (W/Y/G wires) from a 24V AC source (R wire), and that's exactly what I'm doing here. Some HVAC systems have addition wires, like a common wire, present, but mine does not.

This is the first micro controller project that I've done, and it's doing exactly what I wanted it do as a good prototype. I purchased these parts for this project and not sure why you have the tone that you have.

A relay board drawing 20 mA is two order of magnitudes too high to be reasonably sustained by a battery pack and it seems to be common for modern thermostats to utilize the 24V AC for power. I believed I was going to have to go down this route, so I made the post specifically because the hardware I thought I would need is not readily apparent. Latching relays seem to be an adequate solution for this project, or at least good enough that I don't think the complexity of drawing from the AC system is worth it for me.

I'm not going to thank you for your time, and I hope others are not as unfortunate to be greeted by your condescending "suggestions". I'm only even bothering to respond to provide more information and how I decided to approach this in case others have a similar project.

Not enough info to be sure, but many older thermostats use a 24VAC setup. If you post enough pictures of the right parts and angles, maybe we can tell.

What do you expect to gain from adding an MCU?

I highly recommend you also check into what happens if the processor failes? How hot will the facility become?

In the U.S. and many other countries, household HVAC systems have 24VAC hot and common leads (R and RC) and it is not difficult to make a 5VDC converter to power your project. So the first task is to figure out if that is possible with your system. Where do you live?

This web page may help as it includes workarounds for systems that don't seem to have RC. If not, look for others relevant to your particular system and locale.

  • Highly recommend you avoid hacking a thermostat with an Arduino.

  • A friend did this, went on holidays, the DIY thermostat failed for some reason, furnace ran for the whole holiday period, drywall boards dried out, $20,000+ damage, no insurance.

I also don't understand why you are using battery power when you have a permanent power source available. A diode bridge, a few caps and a voltage regulator should get you the DC power needed for the D1 mini & relay.

The D1 mini isn't ideal for battery circuits, I have found. It's USB-serial chip consumes more power than the ESP chip itself when the ESP chip is in sleep mode. My D1 mini circuits last around 3 months from 1,800mAh li-po batteries.

I didn't know they could be damaged by getting too dry. Too wet, yes. Aren't they supposed to be dry? The clue is in the name! I think drywall is what we call plasterboard in the UK?

Seems like nobody has bothered to read your entire post

  • This was the first I ever heard of drywall can be damaged by excessive heat after installation.

  • The house was 37°C for the holiday period.
    Screw pops, shrinkage, some wall board replacements, re-taped, re-painted.
    No insurance coverage because of the non-approved unit was installed.
    Not sure about the high temperature furnace cutout ?

  • Could have been much worse if the DIY unit failed to call for heat during a winter holiday.

I would second this recommendation!

I have experimented with microcontrollers controlling devices in the house but when experiments were complete removed them and used commercially available (often lower cost) units

I have had microcontrollers monitoring three phase power consumption, river level, heat pump room temperatures, etc for extended periods - even then one has to be careful in the selection of sensors - I would certainly remove such monitors if the property was sold

when developing commercial devices once initial testing is complete and ready for production devices would be submitted to the appropriate authority for approval, e.g. CE marking in the EU
using CE approved components (power supplies, modems, contactors, etc) simplifies the process

That would depend, older thermostats used a bi-metallic strip that expands/contracts with temperature to control switch contacts (often mercury switches). Those require no power. It's possible a more modern electronic thermostat could siphon enough power off the control wires by drawing substantially less current than is needed to activate the relays inside the HVAC equipment, but that would likely preclude using a relay in the thermostat itself.

This is a project that needs at least a watchdog timer, and preferably a way to insure that it fails to a safe state. A backup cutoff device that disables the thermostat if the temperature exceeds some unsafe amount would be a possibility.

Esp draws a lot of power, did you choose that because you need wifi? If not, pick some low power mcu.
Latching relay draws power only when swithing, power saving is enormous compared to your "sunfounder".

ran the following code Simple Deep INT0 Wakeup on a ESP32S3 Zero Min

// from https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/

/*
  ESP32 Deep Sleep with External Wake Up
  =====================================
  This code displays how to use deep sleep with
  an external trigger as a wake up source and how
  to store data in RTC memory to use it over reboots

  This code is under Public Domain License.

  Hardware Connections
  ======================
  Push Button to GPIO 33 pulled down with a 10K Ohm
  resistor

  NOTE:
  ======
  Only RTC IO can be used as a source for external wake
  source. They are pins: 0,2,4,12-15,25-27,32-39.

  Author:
  Pranav Cherukupalli <cherukupallip@gmail.com>
*/
#include "driver/rtc_io.h"

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)  // 2 ^ GPIO_NUMBER in hex
#define USE_EXT0_WAKEUP          1               // 1 = EXT0 wakeup, 0 = EXT1 wakeup
#define WAKEUP_GPIO              GPIO_NUM_4     // Only RTC IO are allowed - ESP32 Pin example
RTC_DATA_ATTR int bootCount = 0;

/*
  Method to print the reason by which ESP32
  has been awaken from sleep
*/
void print_wakeup_reason() {
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT0:     Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1:     Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER:    Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP:      Serial.println("Wakeup caused by ULP program"); break;
    default:                        Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
  }
}

void setup() {
  Serial.begin(115200);
  delay(1000);  //Take some time to open up the Serial Monitor

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32
  print_wakeup_reason();

  /*
    First we configure the wake up source
    We set our ESP32 to wake up for an external trigger.
    There are two types for ESP32, ext0 and ext1 .
    ext0 uses RTC_IO to wakeup thus requires RTC peripherals
    to be on while ext1 uses RTC Controller so does not need
    peripherals to be powered on.
    Note that using internal pullups/pulldowns also requires
    RTC peripherals to be turned on.
  */
#if USE_EXT0_WAKEUP
  esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);  //1 = High, 0 = Low
  // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  // No need to keep that power domain explicitly, unlike EXT1.
  rtc_gpio_pullup_dis(WAKEUP_GPIO);
  rtc_gpio_pulldown_en(WAKEUP_GPIO);

#else  // EXT1 WAKEUP
  //If you were to use ext1, you would use it like
  esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
  /*
    If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO
         during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will
         increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH
         domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.
  */
  rtc_gpio_pulldown_en(WAKEUP_GPIO);  // GPIO33 is tie to GND in order to wake up in HIGH
  rtc_gpio_pullup_dis(WAKEUP_GPIO);   // Disable PULL_UP in order to allow it to wakeup on HIGH
#endif
  //Go to sleep now
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
  //This is not going to be called
}


normal operation 40mAmp
deep sleep 300uAmp

I supplied power to the GND and 3.3V pins - there is probably other onboard circuitry taking current even when the microcontroller is in deep sleep

then tested with a custom ESP32 board with all other devices removed (only a LED on board)

normal operation 40mA
deep sleep LED ON 4mA
deep sleep LED removed 20uA
Light sleep LED removed 1.3mA

once you have built the prototype and it is operational try measuring the current when in sleep mode

note: cheap digital multi-meters will not work reliably at low current - you need a good meter probably costing £200+

I used a Avo 9 MkII analogue multi-meter which works OK with DC lowest range 0-50uAmp

UPDATE: Heltec WiFi LoRa V3 sleep test
LoRaWAN joining etc 100mA
LoRaWAN.sleep() called 25uA

Here's the answer to the question I initially asked (and a summary since most people who responded can't read):

I replaced my thermostat using a D1 mini (ESP8266), that uses wifi in order to query the temperature band to control to. Using an actively powered relay board to control the HVAC system is not feasible since I am constrained to using a battery pack - my HVAC system did not have a C wire that could be used for power. If a C wire is present, that should be used for power alongside an actively powered relay board.

4AA batteries is MORE than sufficient to run an ESP8266 thermostat that manages a HVAC system - I'm expecting several months, if not more, of lifetime. While the power usage is not negligible, the ESP8266 can be in light or deep sleep 99.9999% of the time. I went with the TQ2-L2-3V to act as my latching relay. A latching relay requires 2 GPIO pins to operate. Heating and Cooling requires 4 total. That didn't leave me with enough GPIO pins to control a fan separately. Since the TQ2-L2-3V is a 2 coil relay, I used the other side for fan control, which means each latching relay is heat & fan on or heat & fan off (same for cooling). Realistically, I don't see the need to have the fan on when not actively heating/cooling so this was an acceptable compromise. The average power draw of the latching relay is essentially 0, its only drawing during a small, <100ms pulse.

To latch the relay from one state to another, there is a concern of a voltage spike rebounding back and frying your board pins. To prevent this, I used a diode (1N4148). This is what connects pins 1&5 and 10&6, only allowing current from 1 to 5 and 10 to 6. Another thing about this relay is that the amperage from the GPIO pin probably isn't sufficient. So I used a transistor (BC550CBU) to allow full current from the 3.3V pin to drive the latching.

Here is an example wiring diagram:

In the diagram above, "3" is the base/control pin, "2" is the collector pin, and "3" is the emitter pin for the transistor. The power source there should be the 3.3V output from the D1 mini.

Something to consider doing is adding a physical temperature switch as a fail safe. Something like an AC, NC Snap Disc Thermostat Switch that opens if the temperature exceeds its safety bounds. (e.g., if temp > 85, the switch opens and doesn't allow for current to flow to the heating circuit). They are kind of expensive and, since I will know if the board isn't operating or connecting to the server, I chose to forgo these for now.