When I moved my desk setup into the garden room, the underfloor heating (UFH) quickly proved to be a pain point.

The installed controller on the wall was the worst kind of "smart": an off-brand, proprietary unit whose Wi-Fi chip failed before I ever set it up. It offered no local integration capabilities. Effectively I was left with programming a schedule day by day using the buttons on the wall display, via a terrible UI, which massively increased the inertia required to make any changes.

As a Home Assistant user, my instinct was to replace it with a clean Zigbee wall thermostat. But shopping for Zigbee underfloor heating controllers reveals an immediate snag: I couldn't find any that would work with Zigbee without their own cloud integration. I want local-only.

So, instead of hunting for an off-the-shelf compromise, I pulled the old thermostat off the wall and built an autonomous, fail-safe controller using a Shelly Plus 1PM, a Shelly Plus Add-on, and Home Assistant.

Here is how the hardware fits together, the math required to reuse an existing in-screed probe, the local safety controller logic, and where this setup is heading next.

The Hardware Requirements

Pulling the old thermostat off the wall left me staring at live mains tails for a high-draw heating mat buried in concrete, plus a mystery two-wire thermistor disappearing into the floor. You can't just wire a slab heater to a dumb relay driven by Home Assistant—if the server hangs mid-winter, the floor will just keep cooking itself.

I started thinking of the architecture in terms of brains vs. reflexes: Home Assistant can be the brain (handling schedules, room air comfort, and future predictive models), while the relay in the wall acts as the spinal reflex. That meant a few non-negotiable rules for the hardware:

  1. Independent Safety: If Home Assistant crashes, the server reboots, or the local network disintegrates, the heating mat must never run indefinitely.
  2. Thermal Safeguards: The floor screed must not overheat (hard ceiling at 20.0°C), and the room must never fall below freezing (frost pulse at 6.0°C), both handled on the device itself without external logic.
  3. Power Tracking: Native, accurate power/energy metering to log kilowatt-hour draw directly into Home Assistant’s energy dashboard.
  4. Clean Integration: High-level scheduling and climate control driven by room air temperature via Home Assistant, while the relay autonomously safeguards the floor probe.

To accomplish this, I chose:

  • Shelly Plus 1PM: Handles 16A switching and provides live power/energy telemetry over Wi-Fi, paired with an onboard ESP32 running local JavaScript engines.
  • Shelly Plus Add-on: Snaps onto the back of the 1PM to measure the floor temperature probe. Provides galvanically isolated analog/digital input pins without risking mains voltage bleeding into the probe leads.

Wiring & The 15 kΩ Resistor Hack

Connecting the mains power and heating mat to the Shelly 1PM is straightforward:

MAINS IN:
  Brown (Live Supply)    ───> [ L ] Shelly Plus 1PM
  Blue  (Neutral Supply) ───> [ N ] Shelly Plus 1PM

HEATING MAT:
  Brown (Live to Mat)    ───> [ O ] Shelly Plus 1PM
  Blue  (Neutral to Mat) ───> [ N ] Shelly Plus 1PM (shared neutral block)

The real issue was the probe. Putting a multimeter across the sensor tails at room temperature showed the thermistor buried in the concrete screed was an old 15 kΩ NTC sensor, rather than the modern 10 kΩ standard.

The Shelly Plus Add-on provides a VREF + R1 OUT pin hooked to an internal 10 kΩ pull-up resistor designed specifically for standard 10 kΩ NTC probes. Wire a 15 kΩ probe straight into that circuit, and the resulting voltage curve will be skewed, yielding inaccurate temperature values.

Instead of digging up the floor, we can fix the circuit using basic parallel resistance. By placing a standard 30 kΩ metal film resistor in parallel across the sensor inputs, the equivalent resistance drops right down to 10 kΩ:

1Rtotal  =  1Rprobe  +  1Rresistor  =  115,000  +  130,000  =  110,000  ⇒  Rtotal = 10 kΩ

Low-Voltage Wiring:

  • Bridge VREF+R1 OUT to ANALOG IN using a short jumper wire.
  • Connect one leg of the floor probe to ANALOG IN and the other leg to GND.
  • Insert the 30 kΩ resistor across the exact same terminals: one leg in ANALOG IN, the other in GND.

Now the Shelly sees a standard 10 kΩ load right around room temperature (25°C), which originally let me test the probe using the Add-on's stock analog profile before moving to custom edge logic.

Local Edge Logic: JavaScript & Steinhart-Hart Math

Rather than converting raw analog voltages in Home Assistant, the Shelly handles the entire calculation locally. Every 10 seconds, an onboard script polls the voltmeter component, converts the raw millivolts to actual resistance, solves the Steinhart-Hart equation, logs the reading, and checks local safety thresholds:

// Configuration & Thresholds
let CONFIG = {
  scanInterval: 10, // Poll every 10 seconds
  voltmeterID: 100, 

  MAX_SAFE: 20.0,   // Local hard overheat ceiling (°C)
  FROST_ON: 6.0,    // Trigger frost protection pulse (°C)
  FROST_OFF: 7.0,   // End frost protection pulse (°C)

  MQTT_TOPIC: "shelly-ufh-office/floor/temperature",
  isFrostMode: false,

  calcTemp: function (voltage) {
    const constVoltage = 10;
    const R1 = 10000;
    const A = 0.0011252791214670555;
    const B = 0.00023471763897744966;
    const C = 8.563489971304025e-8;

    const R2 = R1 * (voltage / (constVoltage - voltage));
    const logR2 = Math.log(R2);
    let T = 1.0 / (A + (B + C * logR2 * logR2) * logR2);
    return T - 273.15; // Return Celsius
  },

  onTempReading: function (floorTemp) {
    let switchStatus = Shelly.getComponentStatus("switch:0");
    if (switchStatus === null || typeof switchStatus.output !== "boolean") return;
    let relayOn = switchStatus.output;

    // 1. HARD OVERHEAT SAFETY (Always top priority)
    if (floorTemp >= CONFIG.MAX_SAFE) {
      if (relayOn) Shelly.call("Switch.Set", { id: 0, on: false });
      CONFIG.isFrostMode = false;
      print("SAFETY: Overheat limit reached. Relay forced OFF.");
      return;
    }

    // 2. AUTONOMOUS FROST PROTECTION
    if (!relayOn) {
      CONFIG.isFrostMode = false;
      if (floorTemp <= CONFIG.FROST_ON) {
        CONFIG.isFrostMode = true;
        Shelly.call("Switch.Set", { id: 0, on: true });
        print("FROST: Temperature below threshold. Starting pulse.");
      }
    } else {
      if (CONFIG.isFrostMode && floorTemp >= CONFIG.FROST_OFF) {
        CONFIG.isFrostMode = false;
        Shelly.call("Switch.Set", { id: 0, on: false });
        print("FROST: Pulse target reached. Turning OFF.");
      }
      // If relayOn is true and isFrostMode is false, HA has initiated heating.
    }
  }
};

function fetchVoltage() {
  const voltmeter = Shelly.getComponentStatus("voltmeter:" + JSON.stringify(CONFIG.voltmeterID));
  if (!voltmeter || typeof voltmeter["voltage"] !== "number") return;

  const temp = CONFIG.calcTemp(voltmeter["voltage"]);

  if (MQTT.isConnected()) {
    MQTT.publish(CONFIG.MQTT_TOPIC, temp.toFixed(1), 0, true);
  }

  CONFIG.onTempReading(temp);
}

function init() {
  Timer.set(CONFIG.scanInterval * 1000, true, fetchVoltage);
  fetchVoltage();
}

init();

The script publishes temperature directly to MQTT with retain flags so Home Assistant picks up state immediately after reboots. If floor temperature exceeds 20.0°C, the script kills the relay instantly. If the floor drops below 6.0°C, it pulses the relay until it hits 7.0°C, preventing cold damage safely and energy efficiently.

A note on curve accuracy at the extremes: While compiling this write-up, an AI review of the circuit math flagged an interesting catch. While a 30 kΩ parallel resistor makes a 15 kΩ probe match a 10 kΩ probe right at 25°C (and stays reasonably close near our 20.0°C ceiling, which I keep low for gentle background slab warmth), a fixed parallel resistor flattens the thermistor curve at the cold end. Because the combined resistance can never exceed 30 kΩ, feeding R2 straight into 10 kΩ Steinhart-Hart coefficients will over-report the temperature near freezing—meaning the 6.0°C frost threshold wouldn't actually trigger until the slab was well below zero. The production script above is what's running on the wall today, but some experimentation (or backing out the parallel resistor in the JS math before solving Steinhart-Hart) is warranted before relying on the cold-end reading in a deep freeze.

The Network Watchdog (The 30-Minute Kill Switch)

One thing I didn't want is an uncontrolled runaway controller if the network goes down, or Home Assistant fails. Should Home Assistant turn the relay ON, and then the Home Assistant host reboots or crashes. Left unattended, the heater would churn until it either hits the floor limit or damages your electricity bill.

To solve this, we rely on the Shelly's bare-metal hardware timers alongside Home Assistant's generic_thermostat keep-alive:

  1. Inside the Shelly UI: Under Switch:0 -> Settings -> Automations -> Timers, enable Auto OFF and set it to 1800 seconds (30 minutes).
  2. Inside Home Assistant: In configuration.yaml, the generic_thermostat climate entity is set with a 5-minute keep-alive:
climate:
  - platform: generic_thermostat
    name: Office Heating
    heater: switch.office_underfloor_heating
    target_sensor: sensor.office_room_temperature  # Ambient air thermometer
    min_temp: 10
    max_temp: 23
    ac_mode: false
    cold_tolerance: 0.5
    hot_tolerance: 0.5
    initial_hvac_mode: "off"
    precision: 0.1
    keep_alive:
      minutes: 5 # HA resends 'ON' state every 5 minutes while active

Because Home Assistant reasserts the ON command every 5 minutes, the Shelly's 1800-second timer resets continuously during normal operation. But if Home Assistant goes silent, the Shelly hits the 30-minute ceiling, cuts the circuit, and safely defaults to idle.

What’s Next: Time-Series Predictions & Local AI Dispatch

Now that the underfloor heating is fully instrumented, deterministic, and safe, it’s generating rich time-series data: ambient room temperature, slab temperature, outdoor conditions, solar irradiance, and minute-by-minute energy usage.

Underfloor heating in concrete is fundamentally an exercise in managing thermal inertia: it takes an hour or two for heat to radiate up through the slab, and hours more to dissipate. Relying purely on reactive threshold thermostats often means you overshoot or turn heat on right before solar gain warms the room naturally through the windows.

The next phase of this project is moving past basic reactive thermostats. I’m currently looking at training a local predictive model running on historical Home Assistant time-series data to forecast room temperatures several hours into the future.

Instead of just responding to a drop in room temp, the automation can decide the optimal intervention ahead of time:

  • Should it crack open the motorized blinds to capture passive solar gain?
  • Should it pulse the high-inertia underfloor heating early because a cold snap is incoming?
  • Or should it run a brief burst from a convective room space heater to bring the air up to temperature quickly without heat-soaking the floor?

Having robust local safety constraints baked into the Shelly firmware makes this kind of experimentation safe: an external agent or predictive model can test different optimization schedules without any risk of freezing the building or melting the floor.

More on the predictive model and data pipeline once the first iteration is trained and running. Stay tuned!


AI Assistance

The honest truth is that this is an article I've wanted to write for years. But I never got around to double-checking all my old hardware notes, confirming the resistance equations, pulling the live configurations, and taking the time to turn it into a polished write-up that others can learn from. And that's a shame.

So I pulled the live scripts and YAML off the production hardware, dug out my old wiring notes, and used AI to help structure everything into a clean write-up—which even caught the cold-end resistor curve quirk noted above. Here it is now so others can build their own safe, local-first smart heating.