The idea here is for a fan to turn on off based on comparing a humidity sensor’s value to a reference humidity.
For example, this could be the humidity in the house at the thermostat. It could be based on the local weather. You can use this automation to have the humidity in your bathroom trend with the humidity outside of the bathroom (which may change with the weather).
Get started
Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)
blueprint:
name: Humidity Management
description: Turn a fan on and off based on the difference between a humidity sensor and a baseline
domain: automation
input:
humidity_sensor:
name: Humidity Sensor
description: A sensor that measures the humidity of the area
selector:
entity:
domain: sensor
reference_humidity:
name: Reference Humidity
description: A percentage point value that indicates the baseline humidity if there is no reference sensor available
default: 60
reference_humidity_sensor:
name: Reference Humidity Sensor
description: A sensor that indicates the baseline humidity of the location
selector:
entity:
domain: sensor
default: []
fan_switch:
name: Fan Switch
description: A switch that turns the fan on and off
selector:
entity:
domain: switch
rising_threshold:
name: Rising Threshold
description: How many percentage points above the reference humidity the sensor can rise before the fan is turned on
selector:
number:
min: 0
max: 100
default: 8
falling_threshold:
name: Falling Threshold
description: How many percentage points above the reference humidity the sensor must fall to before the fan is turned off
selector:
number:
min: 0
max: 100
default: 3
trigger:
- entity_id: !input humidity_sensor
platform: state
- entity_id: !input reference_humidity_sensor
platform: state
condition:
- condition: template
value_template: '{{ mode != switch_state }}'
action:
- service: switch.turn_{{mode}}
entity_id: !input fan_switch
variables:
reference_humidity: !input reference_humidity
humidity_sensor: !input humidity_sensor
reference_humidity_sensor: !input reference_humidity_sensor
fan_switch: !input fan_switch
switch_state: '{{ states(fan_switch) }}'
rising_threshold: !input rising_threshold
falling_threshold: !input falling_threshold
difference: '{{ states(humidity_sensor)|float - (states(reference_humidity_sensor)|float
or reference_humidity|float) }}'
mode: '{% if switch_state == ''off'' and difference|float > rising_threshold|float %}on{%
elif switch_state == ''on'' and difference|float > falling_threshold|float %}on{% else %}off{%
endif %}'
mode: single
Logger: homeassistant.components.automation.salle_de_bain_humidity_management
Source: components/automation/init.py:373
Integration: Automation (documentation, issues)
First occurred: 11:05:32 AM (1 occurrences)
Last logged: 11:05:32 AM
Error rendering variables: AttributeError: ‘list’ object has no attribute ‘lower’
The threshold binary sensor platform observes the state of another sensor. If the value is below ( lower ) or higher ( upper ) than the given threshold then state of the threshold sensor is changed. It support also a range if lower and upper are given.
Good day, Thank you for sharing this blueprint. Great work, however I get the following error:
Logger: homeassistant.components.automation.humidity_management
Source: components/automation/__init__.py:373
Integration: Automation (documentation, issues)
First occurred: 3:39:43 AM (122 occurrences)
Last logged: 11:23:48 AM
Error rendering variables: TypeError: '>' not supported between instances of 'float' and 'str'
This is the yaml created:
alias: Main Bathroom Humidity Management
description: Manage the bathroom humidity with the extractor fan.
use_blueprint:
path: >-
dondochaka/turn-a-fan-on-and-off-based-on-the-difference-between-a-humidity-sensor-and-a-baseline.yaml
input:
falling_threshold: '3'
humidity_sensor: sensor.sonoff_1000bec77f_humidity
reference_humidity: '80'
reference_humidity_sensor: sensor.ble_temperature_a4c138349488
fan_switch: switch.sonoff_1000bec77f
rising_threshold: '8'
True, that one isn’t a Number selector but its default value is also an integer (60). If you look at Tibuski’s post, the default integer value is, yet again, converted to string.
It seems to ignore the value’s type and always stores it as string. Maybe it’s assuming automatic type conversion will take care of it later, when the value is consumed at runtime.
Hey all, thanks for the heads up. I just fixed the bug by editing the blueprint in the original post.
Although the thresholds are selected as numbers, they become strings in the variable definitions. They must be cast to numbers for the comparisons to work properly.
That part was understood (evident from the error message). What KTibow and I were discussing was a blueprint’s preference to store numeric values as strings (as seen in the automation generated by the blueprint). Seems like a curious design decision.
Good work. I noticed that it does not take into account if its started the fan or not and that I think would make it more versatile. For example I tried to turn my electrical floorheating on when the humidity was raised but that will not work since it will for the moment also turn off the heating during hours when I want it on all the time.
It would also be nice if the reference sensor could be the same sensor but with an averaged value over time (when NOT triggered), then most of us wouldnt need an extra sensor.
Change the word switch in the action to fan.
That is also a service, fan.turn_off / fan.turn_on under action
Then use your fan entity. It will use the default fan speed. If you want to change fan speeds, you will have to get into a little more coding.
Also change the domain in the top from switch to fan.
Is it possible to make the Humidity sensor a multi device selector. I have two bathrooms that use the one fan. So I want to turn the fan on if one of the Humidity Sensor matches the criteria.
Can you make this turn on a Fan when the outside temperature is above a certain degree?
Like if its 25c outside, turn on a loft fan?
Turn back off once outside temp comes down to like 22c or something?