Night-tariff water heater scheduler

Heats the water heater only in the cheap night tariff zone or from surplus solar power, with a temperature limit.

Smart home Board: ESP32 DevKit V1 (WROOM-32) Level: ●●● ⏱ 3–5 h

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Cheap electricity is a schedule, not a feeling

Where your tariff has a cheaper night zone, the best time to heat water is then. Check your operator’s current zones, since they differ and change. The ESP32 knows the time from NTP, reads the tank temperature, and switches the heater through a solid-state relay only inside the cheap window.

Details that make it safe and pleasant

  • Keep the heater’s own thermostat and thermal fuse in the circuit. The controller sets when it may run, not how hot it may get.
  • Strap the probe to the tank surface with insulation; it lags the water, so set the target a bit conservatively.
  • Once a week heat to about 60 °C to limit bacteria such as Legionella in the tank.
  • With a solar array you can allow heating on surplus power: read the grid exchange with a meter and open the window when the surplus exceeds the heater power.
  • If the ESP32 stops, the heater must be off, not on.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • DS18B20 waterproof probe
  • Solid-state relay SSR-25DA + heatsink (for heaters)
  • Relay module 1-channel 5V (opto-isolated)
  • Inline fuse holder + fuses
  • Plastic project enclosure
  • Lever connectors (WAGO type) 2/3-pin

Wiring

Module Module pin ESP32 pin Note
DS18B20 DATA 1-Wire GPIO4 4.7 kΩ pull-up to 3V3; clamp on the tank outlet
SSR input +/- signal GPIO26 / GND SSR sized for the heater with margin, on a heatsink
Heater circuit power through the SSR keep the original thermostat and safety cut-out in series

Libraries

  • OneWire
  • DallasTemperature

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <WebServer.h>

WebServer server(80);
String buildJson();   // implemented in the project below

String num(float v, int d = 1) { return isnan(v) ? String("null") : String(v, d); }

const char PAGE_HTML[] PROGMEM = R"rawliteral(
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>ESP32</title>
<style>body{font-family:system-ui;background:#0b0f14;color:#e6edf3;margin:20px}table{border-collapse:collapse}td{padding:6px 14px;border-bottom:1px solid #223}button,input{font-size:16px;padding:8px 14px;margin:4px;border-radius:6px;border:1px solid #345;background:#16202b;color:#e6edf3}</style>
</head><body><h2>ESP32</h2><table id="t"></table>
<script>
function load(){fetch('/json').then(r=>r.json()).then(d=>{let h='';for(const k in d){h+='<tr><td>'+k+'</td><td>'+d[k]+'</td></tr>';}document.getElementById('t').innerHTML=h;});}
load();setInterval(load,2000);
</script></body></html>
)rawliteral";

void startWeb() {
  server.on("/", []() { server.send_P(200, "text/html", PAGE_HTML); });
  server.on("/json", []() { server.send(200, "application/json", buildJson()); });
  server.begin();
}
#include <time.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire ow(4); DallasTemperature ds(&ow);
const int PIN_SSR = 26;
const int NIGHT_FROM = 23, NIGHT_TO = 7;     // Ukrainian night zone 23:00-07:00; edit for your tariff
float TEMP_MAX = 65.0, TEMP_MIN_DAY = 35.0;  // never heat above TEMP_MAX; top up in the day only below TEMP_MIN_DAY
bool heat = false, forceOn = false; float tank = NAN; int hourNow = -1;

bool isNight(int h) { return NIGHT_FROM > NIGHT_TO ? (h >= NIGHT_FROM || h < NIGHT_TO) : (h >= NIGHT_FROM && h < NIGHT_TO); }
String buildJson() { return String("{"tank":") + num(tank) + ","heating":" + (heat ? 1 : 0) + ","hour":" + hourNow + ","force":" + (forceOn ? 1 : 0) + "}"; }

void setup() {
  Serial.begin(115200); pinMode(PIN_SSR, OUTPUT); ds.begin();
  connectWiFi(); startWeb();
  configTzTime("EET-2EEST,M3.5.0/3,M10.5.0/4", "pool.ntp.org");     // Europe/Kyiv; change for other zones
  server.on("/force", []() { forceOn = server.arg("on") == "1"; server.send(200, "text/plain", forceOn ? "forced ON" : "auto"); });
}
void loop() {
  server.handleClient();
  static uint32_t t = 0;
  if (millis() - t > 5000) {
    t = millis();
    struct tm ti; bool timeOk = getLocalTime(&ti, 10); hourNow = timeOk ? ti.tm_hour : -1;
    ds.requestTemperatures(); tank = ds.getTempCByIndex(0);
    bool sensorOk = tank > -100;
    bool want = false;
    if (sensorOk && tank < TEMP_MAX) {
      if (forceOn) want = true;
      else if (timeOk && isNight(hourNow)) want = true;
      else if (tank < TEMP_MIN_DAY) want = true;       // comfort top-up
    }
    heat = want; digitalWrite(PIN_SSR, heat ? HIGH : LOW);   // sensor fault or NTP loss: no heating at night, only the day top-up logic
  }
}

Build tips

  • Keep the original thermostat in series; the ESP32 only decides when to allow heating.
  • Verify the time zone string and the tariff window of your supplier.

What you need

Buy the parts kit · Estimated total: $20.00

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
DS18B20 waterproof probe × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Solid-state relay SSR-25DA + heatsink (for heaters) × 1
$6.00
Buy at AliExpress Buy at Amazon.com
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Inline fuse holder + fuses × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Plastic project enclosure × 1
$3.00
Buy at AliExpress Buy at Amazon.com
Lever connectors (WAGO type) 2/3-pin × 1
$2.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Ukraine: we buy and sell these parts ourselves, order them on this site.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Aquarium heater and light controller

Holds the water temperature within a fraction of a degree with a cross-checking second probe, runs the lamp on a schedule and reports a cold tank.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Floor heating controller

Controls an electric floor or heater with a solid-state relay, floor and room probes and a schedule.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 3–5 h
Pick parts / kit
⛔ High risk

Never replace the boiler's own safety thermostat or overheat protection. The ESP32 is only an extra controller; use a certified relay and a fuse.

Solid-fuel boiler controller

Controls the draft fan and circulation pump by flue-gas and water temperature, with overheat and CO warnings.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 4–6 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.