DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowFall ResetAmazon USFall reset deals: check better picks before checkoutAmazon US: today's deals, useful picks and quick comparisons.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
Blog

Control Humidity With a Raspberry Pi and IoT Devices

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

A Raspberry Pi can monitor humidity and switch a humidifier, dehumidifier, or fan—but it does not change humidity by itself. A dependable setup pairs a sensor with a local controller such as Home Assistant, then operates the appliance through a suitably rated smart plug or an enclosed, correctly installed relay. For most DIY projects, a BME280 sensor, MQTT, Home Assistant, and a locally controllable smart plug make a flexible starting point.

The key to making it reliable is not just choosing parts: use separate on/off thresholds, confirm the appliance restarts after power loss, and decide what the system should do when a sensor or network goes offline.

Choose the right control setup

“Humidity control” can mean several different things. A dehumidifier or exhaust fan removes moisture; a humidifier adds it. Ventilation may help with moisture or condensation, while a monitoring-only system may simply alert you to conditions that need attention. The Raspberry Pi is the measuring and decision-making part—not the moisture-control equipment.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There are four practical architectures:

  • Home Assistant on a Raspberry Pi: Best when you want dashboards, history, notifications, several rooms, manual controls, and visual automations. A sensor node can send measurements over MQTT, and Home Assistant can control a smart plug.
  • Pico W sensor node: A compact Wi-Fi microcontroller for a remote sensor or simple actuator node. It is not a full Raspberry Pi computer and does not replace a Home Assistant server; it needs firmware and usually a separate controller.
  • Direct Raspberry Pi control: A full Pi reads a sensor and runs a Python program that controls a plug or relay. This can work well in one room, but you must provide your own logging, recovery, alerts, and safe behavior on faults.
  • Commercial humidity controller: Worth considering in a rental, greenhouse, server room, or other setting where a DIY controller failure could cause significant damage. A Raspberry Pi build is not automatically the right choice for unattended or safety-critical control.

A common networked design is:

BME280 sensor → Pico W or Raspberry Pi → Wi-Fi/MQTT → Home Assistant → smart plug → appliance

MQTT separates the sensor, automation software, and actuator, which makes it practical to add rooms or replace a device later. Home Assistant documents MQTT integration, discovery, availability, and sensor entities in its MQTT documentation and MQTT sensor documentation.

#1 Best Overall
2pcs DHT11 Temperature Humidity Sensor Module Digital Temperature Humidity Sensor 3.3V-5V with Wires for Arduino Raspberry Pi 2 3 (2pcs DHT11)
  • DHT11 digital temperature and humidity sensor is a digital signal output with a calibrated temperature and humidity combined sensor.It uses a dedicated digital modules and acquisition of temperature and humidity sensor technology to ensure that products with high reliability and excellent long term stability.
  • Sensor consists of a resistive element and a sense of wet NTC temperature measurement devices, and with a high-performance 8-bit microcontroller connected.
  • The single-wire wiring scheme makes it easy to be integrated to other applications.And the simple communication protocol greatly reduces the programming effort required.
  • Humidity Measure Range 20%-95%,humidity measurement error: +-5%; Temperature Measure Range 0-50°C,temperature measurement error: +-2 degrees.
  • Working voltage: DC 3.3V-5V.Output form: digital output.

Pick a sensor and place it well

For a new general-purpose build, a BME280 breakout is a stronger default than the commonly used DHT11 or DHT22. It communicates over I²C or SPI, measures temperature as well as humidity, and Bosch specifies approximately ±3% RH humidity tolerance and a typical one-second response time. Those are component specifications, not a guarantee that the assembled device will measure a room to ±3%: board quality, enclosure, placement, and installation can all affect results. See the Bosch BME280 specifications and datasheet.

A DHT22/AM2302 can be adequate for a low-cost educational build, but it is slower, is commonly specified around 2–5% RH accuracy, and should not be sampled more often than roughly every two seconds. The DHT11 is less suitable for serious control because of its narrower useful range and lower accuracy. Adafruit’s DHT guide covers those devices and their limits.

Put the sensor where its reading represents the space: around room height, away from direct sunlight, windows, doors, radiators, vents, the appliance outlet, and heat from the Pi or its voltage regulator. Use a ventilated enclosure. In a bathroom, keep it out of direct steam and water droplets unless it is designed for that exposure. A misplaced sensor can undermine a good sensor’s nominal accuracy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Relative humidity also changes with temperature. If your goal is condensation prevention, a room RH reading alone cannot tell you whether every cold wall, pipe, or window is at risk. Dew point or a surface-temperature measurement may be more informative.

Wire and test a BME280 on a Raspberry Pi

Use a breakout that supports 3.3 V logic. A typical I²C connection is:

Rank #2
Sale
Gowoops 2pcs DHT22/AM2302 Digital Humidity and Temperature Sensor Module for Arduino Raspberry Pi, Temp Humidity Gauge Monitor Electronic Practice DIY Replace SHT11 SHT15
  • The sensor can be operated with both 3.3V and 5V, it is compatible for connection to all standard boards such as Arduino, RN-Control, Raspberry Pi and all other microcontrollers.
  • This sensor can build thermometer electric circuit microcontroller, it can be used for robotics development kit, suit for engineer to make projects.
  • Suit for School Beginners: Perfect intro sensor to programmable based on Arduino electronic and IoT robotics.
  • Used for automatic control, weather stations, home appliances, humidity regulators, medical treatment, dehumidifiers, etc.
  • Temperature range: -40 ℃ ~ 80 ℃, Temperature measurement accuracy: ± 0.5 ℃, Humidity measuring range: 0~100%RH, Humidity measurement accuracy: ±2%RH
BME280 VIN/VCC  → Raspberry Pi 3.3 V
BME280 GND      → Raspberry Pi GND
BME280 SDA      → Raspberry Pi SDA
BME280 SCL      → Raspberry Pi SCL

On a standard Raspberry Pi header, SDA and SCL are commonly GPIO 2 and GPIO 3, but check the pinout for your exact board and the breakout’s labels. The BME280 chip supply range is approximately 1.71–3.6 V; a compatible 3.3 V breakout is suitable for Pi or Pico W logic. Enable I²C using the configuration method for your installed Raspberry Pi OS, then install a scanner and look for the device:

sudo apt update
sudo apt install -y i2c-tools
sudo i2cdetect -y 1

A BME280 commonly appears at I²C address 0x76 or 0x77, depending on the breakout’s address selection. Use the address you actually find. If no device appears, recheck power, ground, SDA/SCL, I²C enablement, and the board pinout. Some inexpensive boards sold as BME280-compatible are actually BMP280 devices; a BMP280 does not measure humidity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before connecting an appliance, run a sensor test that detects the chip, reads temperature and RH, rejects missing or implausible values, and prints them at a conservative interval. Confirm the measurement is plausible against a trusted hygrometer and changes sensibly when moved between rooms. Watch for jumps when the appliance switches on; these can signal poor placement or electrical interference.

Send readings through MQTT

For a Home Assistant setup, use a local MQTT broker—often Mosquitto—and a predictable topic structure. For example:

home/bedroom/climate/state
home/bedroom/climate/availability

A JSON state message might look like this:

{"temperature":22.8,"humidity":57.4}

Publish the latest state with MQTT’s retain flag so a controller restarting can receive the most recent value. Also publish an availability state: send online when the node connects and configure an MQTT last-will message of offline so a dropped connection is visible. Availability matters because a retained measurement by itself may be old. A timestamp or sequence number can provide another way to assess freshness.

Rank #3
BME688 Environmental Sensor with AI Function, Supports Temperature/Humidity/Barometric Pressure/Gas Detection, I2C and SPI, Support Raspberry Pi/Raspberry Pi Pico/Arduino / ESP32,etc.
  • BME688 Environmental Sensor with AI function, measure Barometric pressure, Environmental temperature, Relative humidity, VOC and VSC gas change detection (supports IAQ calculation in combination with the software package, and integrated AI function)
  • Supports I2C communication, I2C address configurable, with I2C bus cascading support
  • Supports SPI communication, enabled via CS pin (I2C bus by default)
  • Onboard voltage translator, compatible with 3.3V/5V level
  • Comes with online development resources and manual (examples for Raspberry Pi / Raspberry Pi Pico / Arduino / ESP32)

Home Assistant supports MQTT discovery so a device can create entities such as a humidity sensor, and supports availability topics and JSON value templates. Follow the current MQTT integration and MQTT sensor documentation for the current discovery schema and interface; these details can change between releases. The example discovery configuration in the documentation shows how to identify the humidity value with a template such as {{ value_json.humidity }}.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a local Home Assistant installation, the official MQTT integration documentation describes setting up the Mosquitto Broker app and configuring the integration. Save any broker credentials you will need before reinstalling it. A basic command-line check can help isolate problems:

mosquitto_sub -h BROKER_IP -t 'home/bedroom/climate/#' -v

Then publish a retained test state using your broker account:

mosquitto_pub 
  -h BROKER_IP 
  -u MQTT_USER 
  -P MQTT_PASSWORD 
  -t 'home/bedroom/climate/state' 
  -m '{"temperature":22.8,"humidity":57.4}' 
  -r

If messages do not arrive, check the broker address, port (often 1883 for unencrypted local MQTT), account, firewall, topic spelling, Wi-Fi network, and whether TLS is required. Do not expose an unauthenticated broker directly to the public internet. Prefer local MQTT and local automations so an internet outage does not stop ordinary control.

Choose an actuator that suits the appliance

For a plug-in humidifier or dehumidifier, a smart plug with local control, reported state, and ideally power monitoring is usually simpler and safer to maintain than a hobby relay board exposed to mains voltage. Check the exact model’s electrical rating, environment limits, and compatibility with Home Assistant or MQTT. For example, the Shelly Plug US documentation lists MQTT, REST, overload protection, and power measurement for that model. Its stated ratings are model- and voltage-specific; do not transfer a US rating to a European version or another generation. The US Gen4 documentation describes a different configuration, including 120 V / 60 Hz and a maximum switching current of 15 A with a maximum 1,800 W resistive load. Check the exact product document for the device you use.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BOJACK DHT11 Temperature Humidity Sensor Module Digital Temperature Humidity Sensor 3.3V-5V with Wires for Arduino Raspberry Pi 2 3 (Pack of 2)
  • DHT11 Sensor consists of a resistive element and a sense of wet NTC temperature measurement devices, is a digital signal output with a calibrated temperature and humidity combined sensor and with a high-performance 8-bit microcontroller connected
  • It uses a dedicated digital modules and acquisition of temperature and humidity sensor technology to ensure that products with high reliability and excellent long term stability
  • The single-wire wiring scheme makes it easy to be integrated to other applications.And the simple communication protocol greatly reduces the programming effort required
  • Humidity Measure Range 20%-95%,humidity measurement error: ±5%; Temperature Measure Range 0-50°C,temperature measurement error: ±2 degrees
  • Working voltage: DC 3.3V-5V.Output form: digital output

Before relying on a plug, test the appliance’s behavior after power is cut and restored. Some humidifiers and dehumidifiers resume their previous operating mode; others require someone to press a button. In the latter case, an “on” smart plug may restore power without starting moisture control. Also consider compressor or motor inrush current, the appliance’s full-tank shutdown, and whether power monitoring is accurate at its standby or running load. Plug state confirms that power was commanded, not that moisture is actually being removed.

A relay may suit a low-voltage fan, pump, or custom circuit if its supply and GPIO compatibility are correct. For mains-voltage switching, a relay module’s current rating alone does not establish that the installation is safe. GPIO pins must never be connected directly to mains. Use a listed, enclosed switching product or have the mains work completed by a qualified electrician in line with local code. Fan and HVAC controls may have neutral-wire, motor-rating, and continuous-use requirements; an existing humidity control or timer may be a better fit.

Set thresholds that avoid rapid cycling

Do not switch an appliance on and off at one threshold. Humidity fluctuates, so a single setpoint can cause rapid cycling and unnecessary wear. Use hysteresis: one threshold to start and another to stop. For example, a dehumidifier might turn on above 65% RH and turn off below 58% RH. A humidifier might turn on below 40% RH and stop above 45% RH. These are example control settings, not universal comfort, health, or building-code limits. Measure your space for several days and choose values appropriate to climate, building condition, plants, stored materials, and equipment.

Consider requiring a threshold to persist for several minutes, setting a minimum run and off time, and limiting maximum continuous operation. A 30–120 second moving average can soften noise, but excessive averaging delays response. A practical example policy for a dehumidifier could be: start above 65% RH after five minutes; stop below 58% RH after five minutes; enforce a minimum run time of 10 minutes and a minimum wait of five minutes between starts; and alert if RH stays above 70% for 30 minutes. These are design examples, not a recommended indoor-humidity target.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Home Assistant, separate on and off automations make the deadband explicit. For example, this YAML-style automation starts a plug after sustained high humidity and checks that the sensor node is available:

Best Value
DIYables DHT11 Module Temperature and Humidity Sensor for Arduino, ESP32, ESP8266, Raspberry Pi, 5 Pieces
  • DHT11 Temperature and Humidity Sensor Module: 5 pieces
  • Easy to connect: With a built-in resistor, No need to solder or breadboard
  • Working voltage: DC 3.3V-5V
  • Secure screw hole for stable attachment to components or housing
  • Tutorials for Arduino, ESP32, ESP8266, Raspberry Pi are provided (Search for: DIYables DHT11 module)
alias: Dehumidifier - humidity high
triggers:
  - trigger: numeric_state
    entity_id: sensor.bedroom_humidity
    above: 65
    for: "00:05:00"
conditions:
  - condition: state
    entity_id: binary_sensor.bedroom_climate_node
    state: "on"
actions:
  - action: switch.turn_on
    target:
      entity_id: switch.dehumidifier_plug
mode: single

A separate stop automation can use the lower threshold:

alias: Dehumidifier - humidity controlled
triggers:
  - trigger: numeric_state
    entity_id: sensor.bedroom_humidity
    below: 58
    for: "00:05:00"
actions:
  - action: switch.turn_off
    target:
      entity_id: switch.dehumidifier_plug
mode: single

Entity IDs, availability entities, and YAML syntax depend on your configuration and Home Assistant version. Add minimum on/off timing, a maximum-run safeguard, manual override, and notifications as appropriate; the simple examples do not implement all of those protections. Test the automation in monitoring mode first, then verify its behavior before leaving it unattended.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Plan for failures, stale data, and water

Decide the system’s safe state before enabling automatic control. For an ordinary room dehumidifier or humidifier, a reasonable default is to stop automatic operation if the sensor is unavailable, mark the reading unavailable, and notify the user. Do not let a stale retained value masquerade as a live measurement. An application with a separate, independently engineered ventilation safety requirement may need different fallback behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • After Wi-Fi or broker loss: Use MQTT availability and check that the controller stops acting on stale sensor state. A Pico W needs firmware that reconnects and republishes state.
  • After a Raspberry Pi reboot: Confirm the sensor republishes current state, the automation loads, and the actuator enters a known state. A startup grace period can prevent switching on stale or transient readings.
  • If the plug says on but the appliance is not working: Check power draw, the appliance’s mode, its tank or filter, and whether it needs a physical restart. Power monitoring can help distinguish a commanded plug state from a load drawing power, but cannot prove the appliance is dehumidifying.
  • If humidity does not fall: Check for a full tank, blocked filter, open window, leaking moisture source, inadequate appliance capacity, or poor sensor placement.
  • For dehumidifiers: Secure any drain hose, retain the appliance’s tank-full shutdown, consider a separate leak sensor, and keep controller electronics away from water and overflow.

Compare a low-cost sensor with a trusted reference hygrometer and record any consistent offset. Do not treat a single displayed RH number as exact. Likewise, no single room sensor can guarantee mold prevention: hidden leaks, cold surfaces, insulation defects, and other moisture sources need separate investigation.

When dew point is more useful than relative humidity

Relative humidity is a percentage of how much water vapor the air holds compared with the amount it could hold at its current temperature. Warm air can hold more moisture than cooler air, so RH can change as a room heats or cools even when the actual water vapor changes little. Dew point is the temperature at which condensation begins; absolute humidity describes water vapor per unit volume.

For general room control, RH is usually the simplest threshold to understand. For condensation risk, compare dew point with the temperature of the vulnerable surface, or add a surface-temperature sensor. A single RH sensor cannot reliably detect condensation on every window, cold wall, pipe, or duct. Address persistent condensation by investigating ventilation, insulation, air circulation, leaks, and thermal bridges—not by assuming that a plug-in dehumidifier alone will solve it.

Troubleshooting

Symptom Likely cause What to check
No BME280 appears in the I²C scan Incorrect wiring, I²C disabled, wrong bus, or wrong address Verify 3.3 V, ground, SDA/SCL, the board pinout, I²C configuration, and the breakout’s address selection.
Temperature works but humidity is missing or implausible Wrong sensor or driver; the board may be a BMP280 rather than a BME280 Confirm the chip marking and use a driver for the actual device.
Automation cycles rapidly One threshold, narrow deadband, noisy reading, or sensor near the appliance Use distinct thresholds, add duration and minimum-run/off timers, and relocate the sensor.
Plug turns on but appliance stays off Appliance needs a button press after power restoration Test power recovery manually; use an appliance with suitable auto-restart behavior or choose a different control method.
Sensor remains available after Wi-Fi loss No MQTT last-will/availability handling, or stale retained data is being treated as current Configure availability and ensure automations require current availability.
Humidity remains high while the plug is on Full tank, blocked filter, open window, moisture source, or undersized appliance Inspect the appliance and room; verify actual power draw and placement.
Control stops after a Pi restart Service, broker, sensor publishing, or automation did not recover Check startup configuration and logs; verify a fresh sensor state and known actuator state before resuming.

A sensible commissioning sequence

  1. Choose the equipment and desired outcome: add moisture, remove it, ventilate, or monitor and alert.
  2. Install the sensor and collect readings without controlling anything for 24–72 hours. Compare against a reference and adjust placement if needed.
  3. Set a deadband and choose delays, minimum run/off times, unavailable-sensor behavior, and manual override.
  4. Test the smart plug or relay separately, including appliance restart after power loss and reported state.
  5. Run the automation while present. Test sensor disconnect, broker loss, controller reboot, and appliance faults before relying on it unattended.

A full Raspberry Pi is the better choice when you want Home Assistant, a broker, history, and multiple automations. A Pico W is useful as a low-cost remote sensor node, but requires firmware and another controller for dashboards and orchestration. For either approach, local control, reliable availability reporting, safe switching hardware, and a tested recovery plan matter more than adding complexity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 3
BME688 Environmental Sensor with AI Function, Supports Temperature/Humidity/Barometric Pressure/Gas Detection, I2C and SPI, Support Raspberry Pi/Raspberry Pi Pico/Arduino / ESP32,etc.
BME688 Environmental Sensor with AI Function, Supports Temperature/Humidity/Barometric Pressure/Gas Detection, I2C and SPI, Support Raspberry Pi/Raspberry Pi Pico/Arduino / ESP32,etc.
Supports I2C communication, I2C address configurable, with I2C bus cascading support; Supports SPI communication, enabled via CS pin (I2C bus by default)
$28.79
Bestseller No. 5
DIYables DHT11 Module Temperature and Humidity Sensor for Arduino, ESP32, ESP8266, Raspberry Pi, 5 Pieces
DIYables DHT11 Module Temperature and Humidity Sensor for Arduino, ESP32, ESP8266, Raspberry Pi, 5 Pieces
DHT11 Temperature and Humidity Sensor Module: 5 pieces; Easy to connect: With a built-in resistor, No need to solder or breadboard
$7.49

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.