# HearthNodes recipe 11 - bathroom fan on humidity gradient
alias: "Climate - bath fan runs until the gradient flattens"
id: hn_climate_bath_humidity_fan
description: "Absolute humidity driven runtime, clamped 8-45 minutes"
mode: restart
max_exceeded: silent
trigger:
- platform: numeric_state
entity_id: sensor.bath_absolute_humidity
above: "{{ states('sensor.hall_absolute_humidity') | float(0) + 4 }}"
for: "00:00:30"
variables:
fan: fan.bath_extract
gradient_window_s: 120
stop_threshold_pct: 1.0
min_runtime_s: 480
max_runtime_s: 2700
condition:
- condition: template
value_template: >-
{{ (now() - states.sensor.hall_absolute_humidity.last_updated).total_seconds() < 600 }}
- condition: state
entity_id: binary_sensor.bath_window_contact
state: "off"
- condition: state
entity_id: input_boolean.bath_fan_latched
state: "off"
action:
- service: fan.turn_on
target:
entity_id: "{{ fan }}"
data:
percentage: 100
- service: script.humidity_gradient_watch
data:
fan: "{{ fan }}"
window_s: "{{ gradient_window_s }}"
stop_pct: "{{ stop_threshold_pct }}"
min_s: "{{ min_runtime_s }}"
max_s: "{{ max_runtime_s }}"
# Relative humidity is never used: it tracks temperature as much as moisture and
# fires on a cold morning with no shower. Hallway reference sensor unavailable ->
# conservative fixed 20 minute runtime. The 45 minute maximum is a separate timer
# that cuts the relay directly.
触发器 · numeric_state
sensor.bath_absolute_humidity
浴室绝对湿度在 3 分钟内比走廊参考值高出 4 g/m³ 以上。
分步说明
- fan.bath_extract立即以高速启动排风扇;此刻延迟比噪声更重要。
turn_on · speed high - script.humidity_gradient_watch当相对湿度在连续两个 2 分钟窗口内下降幅度都小于 1 % 时关闭风扇。
run · sample every 60s · stop when ΔRH < 1 % over 4 min - fan.bath_extract把运行时长限制在 8 到 45 分钟之间,避免湿度传感器卡死导致风扇整天运行。
turn_off · min runtime 8 min · max runtime 45 min - sensor.bath_fan_energy记录每次循环的运行时长,让季节性规律(冬天淋浴时间更长)变得可见。
log per cycle
用绝对湿度,绝不用相对湿度
相对湿度更多是在告诉你温度,而不是水汽含量。用传感器的温度和相对湿度换算成绝对湿度,或者直接用上报绝对湿度的传感器。用相对湿度触发,会在没有洗澡的寒冷早晨误触发,而在空气本就温暖的夏天漏掉一次长时间淋浴。
关闭判断看斜率,不看绝对水平
以固定相对湿度水平作为停止条件,意味着在潮湿的日子即使空气已停止改善,风扇仍会继续运行。连续两个 2 分钟窗口变化小于 1 %,就是风扇已无事可做的时刻。淋浴约 11 分钟,泡澡约 26 分钟。
同时保留硬性上限和硬性下限
8 分钟下限用于覆盖湿度峰值之后仍在从地面蒸发的水分。45 分钟上限则约束传感器异常上报带来的损失。这两个数字应当写进脚本,而不是记在脑子里。
硬件
| 型号 | 协议 | 连接 | 在本链路中的作用 |
|---|---|---|---|
| Zigbee humidity sensor with 0.1 % RH resolution | zigbee |
无线 | 上报间隔必须不超过 60 秒;5 分钟上报间隔无法解析湿度斜率。 |
| Sonoff ZBMINI-L2 in the fan isolator switch | zigbee |
有线 | 控制风扇的常电供电;门上方的隔离开关对站在凳子上的人仍然可用。 |
| Second humidity sensor in the hallway (reference) | zigbee |
无线 | 绝对湿度只有作为差值才有意义;走廊传感器正是让「天气变化」不再触发的原因。 |
失效时怎么办
如果走廊参考传感器不可用,配方切换到保守的固定 20 分钟运行。如果风扇继电器 5 秒内未确认开启,会立即报警,因为淋浴时风扇不转会很快损坏墙面。两个传感器在 15 % 与 5 % 电量时各做一次检查。