Blind Bathroom Fan Control

Post Reply
User avatar
emme
Posts: 956
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Blind Bathroom Fan Control

Post by emme » Thursday 19 July 2018 9:16

Ciao,

while I'm restructuring my bathroom, I played around with Zwave and other devices....

The result is an automatic fan control based on light and humidity

the actors are:
- Light switch (in my case zWave)
- Fan Switch (in my case zWave)

the sensors are:
- Temp/Humidity Device (in my case a rf433 device from Oregon)

The other stuff needed are:
- Numeric Variables with the Humidity Trigger (min/max)

How it works:
When you switch on the light the fan start, when the light is OFF or have been switched off the script evaluate the humidity value and act the fan accordingly
If over the MAX value it switch it on
if below the min value it switch off

the triggers are:
- light device
- Temp/Hum change


SCRIPT:

Code: Select all

-- ======= SETUP =======
-- Place the correct names for devices and variables

local devFan     = 'Ventola_Bagnetto'   -- Fan Switche Device Name
local devLuce    = 'Luce_Bagnetto'      -- Light Switch Device Name
local varHMax    = 'bagnettoHumMax'     -- Variable Name for Max Humidity
local varHMin    = 'bagnettoHumMin'     -- Variable Name for Min Humidity
local devTempHum = 'TEM_Bagnetto'       -- Device Name for Temperature Device 

-- Do Not Change Nothing beyond this point

function evalFan(dz, humMax, humMin)
    if dz.devices(devTempHum).humidity > humMax then
        dz.log('Umidità sopra il valore impostato.... accensione')
        dz.devices(devFan).switchOn().checkFirst()
    elseif dz.devices(devTempHum).humidity <= humMin then
        dz.log('Umidità sotto il valore impostato.... spegnimento')
        dz.devices(devFan).switchOff().checkFirst()
    end
end

return {
	on = {
		devices = {	devTempHum, devFan, devLuce }
	},

    logging = {
        level = domoticz.LOG_INFO,
        marker = "[BAGNETTO Ventola]"
    },

	execute = function(dz, devName)
		local humMax = dz.variables(varHMax).value 
		local humMin = dz.variables(varHMin).value 
		
		if devName.name == devLuce and devName.state == 'On' then
		    dz.devices(devFan).switchOn().checkFirst()
		    dz.log('Accensione Luce Bagno ==> Ventola ON')
		elseif devName.name == devLuce and devName.state == 'Off' then
		    dz.log('Spegnimento Luce Bagno ==> Valutazione')
		    evalFan(dz,humMax,humMin)
		elseif devName.name == devTempHum and dz.devices(devLuce).state == 'Off' then
		    dz.log('Variazione T e H ==> Valutazione')
		    evalFan(dz,humMax,humMin)
		end
		
	end
}
I've installed it 2 days ago and seems to work fine

hope you will find it useful!
caio
M
The most dangerous phrase in any language is:
"We always done this way"

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests