adds code

Bathroom Automation: Home Assistant, Node-RED & Sonoff

Originally published: 2020-08-07

Bathrooms are one of the most satisfying rooms to automate: steam builds up, humidity spikes, and a well-tuned flow can run the extractor fan exactly as long as it needs to run — then stop. This guide walks through the sensor-and-relay pattern behind the video tour below, the humidity-to-fan logic including one timing trick that fixes a common bug, and the safety line you should not cross on your own.

Quick answer: The core pattern is a humidity sensor feeding Node-RED, which switches the extractor fan through a Sonoff relay flashed with Tasmota. Home Assistant or a Node-RED Dashboard can display state, but the logic — humidity threshold, hold time, wait-until — lives in the flow. Mains wiring near water is the one part to take seriously: keep DIY to low-voltage and plug-level work, and use a qualified installer for anything fixed.

Watch: a bathroom automation tour

The video tours a full setup: a PIR sensor at the bedroom door triggers Hue light scenes by time of day, and the bathroom light and fan run on Sonoff Basic R2 relays flashed with Tasmota, with a D1 mini wired to push buttons so the switches still work by hand. Watch the fan button logic — a short hold starts the fan, and it stays on until humidity returns to normal.

How does the humidity-to-fan flow work?

The pieces are simple: a humidity sensor (a BME280 or DHT22 works) publishes readings to MQTT, and a Sonoff relay running Tasmota subscribes to a command topic that switches the fan. The flow logic is where bathrooms get interesting:

  1. A trigger starts the cycle — humidity crossing a threshold, or the video’s trick: a 0.4-second hold on the push button as you step into the shower.
  2. The flow waits a fixed period (the video uses 10 minutes) before checking anything. This is the fix for the classic bug: steam takes minutes to travel and build up, so a “wait until humidity drops” node evaluated immediately sees dry air and ends the cycle before the shower has even started.
  3. After the delay, a wait-until node watches for humidity to fall back below the threshold, then switches the fan off.

The result: the fan runs exactly as long as the steam does — no more leaving it on for an hour, no more foggy mirror because it cut out early.

How do you time a heated towel rail?

A heated towel rail is the second classic bathroom automation: run it on a schedule (morning and evening windows), cap the total runtime, and interlock it with humidity so it does not fight the extractor fan for warmth. A Tasmota-flashed relay or a monitoring plug gives you the draw feedback to confirm it is actually heating. Check the rail’s rating plate first — sizes and wattages vary a lot, and the switching hardware must be rated for the load.

What should you not DIY in a bathroom?

Safety note: bathrooms are the most regulated room in home electrics for a reason. Wiring codes divide the room into zones around baths and showers, require equipment with appropriate moisture ratings in those zones, and expect circuits to be protected by an RCD (GFCI). Relay boards in open enclosures do not belong near water. Keep your DIY to low-voltage sensors and plug-level switching, and bring in a qualified electrician for anything that involves fixed mains wiring in the bathroom itself.

Which loads suit a smart plug instead of a relay?

For lower-power bathroom loads — a heated towel rail, a nightlight, a dehumidifier — a smart plug with energy monitoring can replace a DIY relay entirely, with a proper enclosure and certification included. Before buying, check the maximum load rating against the appliance’s draw (a towel rail’s heating cycle is the number that matters) and whether the plug supports local control so the switching does not depend on a cloud. Our smart plugs compared on load and safety specs page lists measured ratings instead of marketing claims.

If you buy through links on the sites we recommend, we may earn a small commission.

Frequently Asked Questions

Do I need Home Assistant if I am using Node-RED?

No. Node-RED with an MQTT broker runs this whole pattern standalone. Home Assistant adds device dashboards and voice integrations, and many setups run both on the same host.

Why did my “wait until humidity drops” node fire immediately?

Because steam had not reached the sensor yet — the air was still dry when the node first evaluated. Add a fixed delay (the video uses 10 minutes) before the wait-until so the humidity spike can build up.

Is a PIR sensor a good trigger for a bathroom fan?

It works for occupancy, but steam and temperature changes can cause false triggers. Humidity is the more reliable trigger for fans; PIR is better suited to lighting.

Further reading

Sources

Previous Post Next Post