Smart Bathroom Ventilation Fan

Hi everyone, and thanks for the great contributions in this awesome community.
I thought I’d share my simple project in case anyone find it useful, and maybe get some constructive critique where I can learn from it for my future projects.

The idea is simple. Smart Ventilation Fan for a bathroom.
The concept of a ventilation fan is to reduce the humidity and/or temperature by dumping the hot and humid air out, and displacing it by fresh or better air mass. Using a conventional switch, this process is manual requiring human intervention.

Using a Sonoff Basic with a Temperature and Humidity sensor (in my case AM2302B) attached to GPIO,
we can get the sensor readings.

The Sonoff Basic tucks nicely into the frame of the vent fan, and the sensor can be attached to the outer frame using double sided mounting tape.

The end result looks like this:

The logic that I used is as follows:
Activation:
When either the temperature or humidity exceeds the preset thresholds, the vent fan will turn on.

de-Activation:
When both the temperature and humidity are below the preset thresholds, or the vent fan has been running continuously for 20 minutes, the vent fan will be turned off.

I used a Node-RED flow to make this logic work.
The flow code can be found below:

[{"id":"f7dbde19.40ede","type":"comment","z":"a4193cb.0d41ac","name":"Vent Fan","info":"# Exhaust Fan Automation Logic\nThis logic flow monitors the Master Bathroom Temperature and Humidity, and activates the bathroom's Ventilation Fan accordingly.\n\n*Activation:*\nWhen either the temperature or humidity exceeds the preset thresholds, the exhaust fan will be switched on.\n\n*de-Activation:*\nWhen both the temperature and humidity are below the preset thresholds, or the exhaust fan has been running continuously for 20 minutes, the switch will be turned off.","x":80,"y":460,"wires":[]},{"id":"cc71008.5a4d6","type":"mqtt in","z":"a4193cb.0d41ac","name":"Sensor","topic":"home/master/tele/msb_vent-fan/SENSOR","qos":"2","broker":"6643124f.d04004","x":90,"y":520,"wires":[["ed2fe668.683d48"]]},{"id":"ed2fe668.683d48","type":"json","z":"a4193cb.0d41ac","name":"","property":"payload","action":"","pretty":false,"x":230,"y":520,"wires":[["1ee5004c.f2c75","9a99aed3.0bc87","cb116a79.5a56c8","f90d2460.be6618"]]},{"id":"1ee5004c.f2c75","type":"switch","z":"a4193cb.0d41ac","name":"Temperature","property":"payload.AM2301.Temperature","propertyType":"msg","rules":[{"t":"gte","v":"39","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":500,"wires":[["79cb9ffb.f51b5"]]},{"id":"9a99aed3.0bc87","type":"switch","z":"a4193cb.0d41ac","name":"Humidity","property":"payload.AM2301.Humidity","propertyType":"msg","rules":[{"t":"gte","v":"65","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":540,"wires":[["79cb9ffb.f51b5"]]},{"id":"79cb9ffb.f51b5","type":"api-current-state","z":"a4193cb.0d41ac","name":"Master Bathroom Vent Fan","server":"83a4b7e1.07ae58","outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.master_exhaust_fan","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":700,"y":520,"wires":[["b46296ae.ad49c8"],[]]},{"id":"b46296ae.ad49c8","type":"api-call-service","z":"a4193cb.0d41ac","name":"Turn On","server":"83a4b7e1.07ae58","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\"switch.master_exhaust_fan\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1060,"y":560,"wires":[["482b4823.712688"]]},{"id":"cb116a79.5a56c8","type":"switch","z":"a4193cb.0d41ac","name":"Temperature","property":"payload.AM2301.Temperature","propertyType":"msg","rules":[{"t":"lt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":640,"wires":[["2479316.6cd4dce"]]},{"id":"2479316.6cd4dce","type":"switch","z":"a4193cb.0d41ac","name":"Humidity","property":"payload.AM2301.Humidity","propertyType":"msg","rules":[{"t":"lte","v":"55","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":580,"y":640,"wires":[["dcb2bbfd.c7a6f8"]]},{"id":"f90d2460.be6618","type":"switch","z":"a4193cb.0d41ac","name":"Humidity","property":"payload.AM2301.Humidity","propertyType":"msg","rules":[{"t":"lte","v":"55","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":680,"wires":[["db6da240.7363b"]]},{"id":"db6da240.7363b","type":"switch","z":"a4193cb.0d41ac","name":"Temperature","property":"payload.AM2301.Temperature","propertyType":"msg","rules":[{"t":"lt","v":"35","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":590,"y":680,"wires":[["dcb2bbfd.c7a6f8"]]},{"id":"dcb2bbfd.c7a6f8","type":"api-current-state","z":"a4193cb.0d41ac","name":"Master Bathroom Vent Fan","server":"83a4b7e1.07ae58","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.master_exhaust_fan","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":810,"y":660,"wires":[["197c903e.2d982"],[]]},{"id":"197c903e.2d982","type":"api-call-service","z":"a4193cb.0d41ac","name":"Turn Off","server":"83a4b7e1.07ae58","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\"switch.master_exhaust_fan\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1080,"y":700,"wires":[[]]},{"id":"5f45b921.ff1fd8","type":"inject","z":"a4193cb.0d41ac","name":"","topic":"home/master/tele/msb_vent-fan/SENSOR","payload":"{\"Time\":\"2019-03-02T07:42:02\",\"AM2301\":{\"Temperature\":22.6,\"Humidity\":66.1},\"TempUnit\":\"C\"}","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":110,"y":620,"wires":[["ed2fe668.683d48"]]},{"id":"482b4823.712688","type":"trigger","z":"a4193cb.0d41ac","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"20","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":890,"y":620,"wires":[["197c903e.2d982"]]},{"id":"6643124f.d04004","type":"mqtt-broker","z":"","name":"MOSQUITTO MQTT","broker":"192.168.1.192","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"83a4b7e1.07ae58","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]

I hope you will find this useful, and I appreciate any feedback that will help making this logic smarter.

3 Likes

This looks pretty cool. I’m looking to try something similar, but I’ve never modified a Sonoff before. What pins did you connect the sensor to? What does your Tasmota configuration look like?

Nice tidy installation!

Feedback. You are probably better to measure increase in humidity, rather than just an absolute level. That way you take into account the background humidity. eg if humidity goes up by 15 in a period of x then turn on.