Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Smartify a "dumb" Humidifier #565

Unanswered
skilau asked this question in Show and tell
Discussion options

Up here in Minnesota, we are in the heart of winter right now, our houses are very dry, and our sleeping has gotten annoying with sore throats, etc.
We have a couple existing "dumb" Humidifiers, but they are annoying, in that they run continuously, until they run out of water.
So even though you started the night at a low of 15-20% Humidity, you wake up at 60%, with potential mold issues, and other things.

I already have some BLE temp/humidity sensors in our rooms to keep an eye on the temp, and had a spare Kasa Smart Plug lying around.

So, what the heck, I thought it would be interesting to try to "smartify" our Humidifiers, so that it only runs at night, and that it only turns on when the humidity is too low, and turns off when we hit an optimal level of humidity.

The script below is the result. It works extremely well, and keeps our bedrooms at our perfect level of humidity that we like.

PS: You can have just 1 temp/humidity sensor, in which it should probably be placed near your head/headboard in your room, so you get an optimal level of humidity that you like for breathing while sleeping.
Or, if you happen to have a couple spares like I have, you can place them evenly around the room, so you can have a optimal level for the whole room.

# Humidifier script
#
# This script will "smartify" a dumb Humidifier when used with
# Temp/Humidity sensor(s) and a smart plug.
#
# Sensors we want to watch
# Can be anywhere from just 1 to as many as you happen to have in the room
humidity_sensors = [
 'sensor.h5075_515e_humidity',
 'sensor.h5075_002d_humidity',
 'sensor.h5177_72aa_humidity',
]
# The Smart Plug that can turn on/off the Humidifier
plug = 'switch.office_humidifier'
# The low humidity value in which when below, the Humidifier should be on
LOW_HUMIDITY_THRESHOLD = 37.0
# The high humidity value in which when above, the Humidifier should be off
HIGH_HUMIDITY_THRESHOLD = 42.0
# Default state for Smart Plug, when outside of Humidifier hours
SMART_PLUG_DEFAULT_STATE = "off"
# Hours for when the Humidifier should be running.
HUMIDIFIER_HOURS = "range(sunset - 20min, sunrise + 15min)"
# Humidifier Active Sensor Triggers will be allocated on this array.
_humidifier_active_triggers = []
# Humidifier Nonactive Sensor Triggers will be allocated on this array.
_humidifier_nonactive_triggers = []
def humidifier_active():
 """
 When the Humidifier is Active (during the active hours), determine:
 If the humidity is too low, turn the Humidifier on.
 If the humidity is too high, turn the Humidifier off.
 """
 # Calculate the average humidity over the number of sensors
 avg = 0.0
 for sensor in humidity_sensors:
 avg += float(state.get(sensor))
 avg /= float(len(humidity_sensors))
 log.info(f"Average humidity: {avg}")
 if avg < LOW_HUMIDITY_THRESHOLD:
 if state.get(plug) == "off":
 log.info(f"Office Humidity is too low, turning on Humidifier: {avg}")
 switch.turn_on(entity_id=plug)
 elif avg > HIGH_HUMIDITY_THRESHOLD:
 if state.get(plug) == "on":
 log.info(f"Office Humidity is too high, turning off Humidifier: {avg}")
 switch.turn_off(entity_id=plug)
def humidifier_nonactive():
 """
 When the Humidifier is Nonactive, (outside of the active hours),
 set the Smart plug to whatever value the user wanted defaulted.
 """
 if SMART_PLUG_DEFAULT_STATE == "on":
 if state.get(plug) == "off":
 log.info(f"Humidifier off hours, turning plug on")
 switch.turn_on(entity_id=plug)
 elif SMART_PLUG_DEFAULT_STATE == "off":
 if state.get(plug) == "on":
 log.info(f"Humidifier off hours, turning plug off")
 switch.turn_off(entity_id=plug)
def humidifier_active_factory(sensor_name):
 """
 A factory to set up a given Humidity Sensor while the Humidifier is in
 its active hours
 """
 @time_active(f"{HUMIDIFIER_HOURS}")
 @state_trigger(f"{sensor_name}")
 def humidity_trigger(trigger_type=None, var_name=None, value=None):
 if trigger_type == "state":
 log.info(f"{sensor_name}: {value}")
 humidifier_active()
 # Append the trigger to our global array of them
 _humidifier_active_triggers.append(humidity_trigger)
def humidifier_nonactive_factory(sensor_name):
 """
 A factory to set up a given Humidity Sensor while the Humidifier is in
 its nonactive hours
 """
 @time_active(f"not {HUMIDIFIER_HOURS}")
 @state_trigger(f"{sensor_name}")
 def humidity_trigger(trigger_type=None, var_name=None, value=None):
 if trigger_type == "state":
 log.info(f"{sensor_name}: {value}")
 humidifier_nonactive()
 # Append the trigger to our global array of them
 _humidifier_nonactive_triggers.append(humidity_trigger)
@time_trigger('startup')
def startup_function():
 """
 Set up each Humidity Sensor at startup.
 """
 for sensor in humidity_sensors:
 humidifier_active_factory(sensor)
 humidifier_nonactive_factory(sensor)
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /