Blog: Bathroom dehumidifying using two sensors and a floating humidity threshold.
Link to the original blog post with a nice text/pictures layout.
The problem:
The bathroom fan is running too long if it’s raining outside.
A year ago I automated the dehumidifying of the bathroom using an extraction fan, Sonoff mini switch, Xiaomi Mi BLE thermometer/humidity sensor and HomeAssistant.
It works great, except in humid and rainy weather. In such cases, the fan runs too long, because it can not reach the manually set humidity threshold.
The solution:
A moving humidity threshold using a second humidity sensor.
HW parts:
- ESP32 board (BLE proxy)
- 2 Xiaomi Mijia BLE humidity sensors
- Sonoff mini zigbee switch
- extraction fan
- a bathroom
SW:
- #HomeAssistant (server)
- #ESP32Home add-on
The process:
1. I resolved how to connect Sonoff ZBMINI to the fan. The fan has 4 connectors: 1. ground, 2. neutral, 3. Phase 1 (power), 4. Phase 2 (a signal to turn it on). Until I connected the Sonoff switch, I used a physical switch to turn the fan on.
I connected the Sonoff switch in parallel to the physical switch. This way I can still use the physical switch to turn the fan on (in case Home Assistant is not working).
The schematics/doodles:
![zbmini switch and the wiring schematics for extractor fan](https://blog.rozman.info/wp-content/uploads/2024/05/20230213_172002-1024x576.jpg)
The fan enclosure (without Sonoff):
![the extractor fan, cover removed](https://blog.rozman.info/wp-content/uploads/2024/05/20220207_185820-576x1024.jpg)
The Sonoff switch is so small it nicely fits the fan enclosure:
![the extractor fan without cover, sonoff zbmini connected](https://blog.rozman.info/wp-content/uploads/2024/05/20230213_171815-576x1024.jpg)
3. I connected Sonoff to my Zigbee network. I had some issues with the range because the bathroom is 10m away from the Zigbee router. Then I added some zigbee smart plugs (routers) nearby to strengthen the mesh.
4. Then I set up Xiaomi Mi BLE sensors (one in the bathroom, one in the hallway) and ESP32 BLE proxy. Will skip the steps here, maybe this will be another blog post. Nevertheless, any humidity sensor connected to Home Assistant would work.
Home Assistant
5. I’ve set up a generic hygrostat entity:
![home assistant generic hygrostat screenshot](https://blog.rozman.info/wp-content/uploads/2024/05/image-14.png)
The code for it (it should be defined manually in configuration.yaml):
generic_hygrostat:
- name: Kopalnica
unique_id: kopalnica_dehumidifier01
humidifier: switch.kopalnica_stikalo_vent
target_sensor: sensor.atc_kopalnica1_humidity
min_humidity: 30
max_humidity: 80
target_humidity: 65
dry_tolerance: 2
wet_tolerance: 2
device_class: "dehumidifier"
min_cycle_duration:
seconds: 5
keep_alive:
minutes: 3
initial_state: true
away_humidity: 65
away_fixed: True
sensor_stale_duration: 00:15:00
6. I’ve added the automation for setting a floating humidity threshold:
The automation works like this: It has 2 triggers. The 1st trigger fires if the state of the humidity sensor located in the hallway changes. The 2nd trigger (which is probably not needed) fires every 30 minutes (just to be sure).
Then the target humidity in generic hygrostat (HA) is set to: hallway humidity + 8%.
Why 8% difference? Don’t know, I set it using trial-and-error and it works ok.
![home assistant screenshot, automation of the floating humidity threshold](https://blog.rozman.info/wp-content/uploads/2024/05/image-13-1024x738.png)
The code for target humidity needs to be added manually to the automation yaml:
"{{ float(states('sensor.atc_hodnik1_humidity')) + float(8) }}"
Traces
Here’s the example of automation in action. The left trigger (humidity sensor state change) fired:
![home assistant log of the automation execution](https://blog.rozman.info/wp-content/uploads/2024/05/image-12-1024x595.png)
The result:
The result: a comparison of the fixed vs. floating humidity threshold can be observed on the chart below.
If the generic hygrostat entity in HA is set to a fixed value (e. g. 60%), the fan runs unnecessarily long and it can’t reach the target humidity, see red (1) on the chart below.
If the target humidity adjusts according to the general humidity in the house, it runs less time (2).
The chart below shows the switch from the fixed humidity threshold to floating threshold (21 May around 18:00). See the blue horizontal line (threshold) and purple line (current bathroom humidity). Light blue vertical bars represent when the fan is running:
![home assistant chart of bathroom humidity, calculated humidity threshold and indication when the fan is running](https://blog.rozman.info/wp-content/uploads/2024/05/image-11-1024x389.png)
Conclusions/Key takeaways
- it took me more than a year to fix this annoying issue of the fan running at night,
- at the end it was easier to set up the automation than I thought.
Disclaimer
The links to the products are not affiliate links and I don’t receive any compensation for linking.
The code and the ideas are mostly from HomeAssistant and ESPHome community forums.
Hashtags: #esphome #esp32 #homeassistant #diy #humidity #bathroom
Leave a Reply