I recently renewed my bathroom in which I have no window... just an exaust vent
So I decided to build a script that could handle the ventilation system based on light (on/off and humidity)
script uses 2 variable that set up the min and max humidity
vents goes ON when:
- lights is switched ON
- Humididty rise over the max value
vents goes OFF when:
- Lights goes off and humidity is lower than MIN value
- humidity is lower than MIN value
here is it
Code: Select all
local devTempHum = 'TEM_Bagnetto'
local devLuce = 'Luce_Bagnetto'
local varHMax = 'bagnettoHumMax'
local varHMin = 'bagnettoHumMin'
local devFan = 'Ventola_Bagnetto'
return {
on = {
devices = { devTempHum, devFan, devLuce }
},
logging = {
level = domoticz.LOG_INFO,
marker = "[BAGNETTO Ventola]"
},
execute = function(dz, devName)
local humMax = tonumber(dz.variables(varHMax).value )
local humMin = tonumber(dz.variables(varHMin).value )
dz.log('T: '..dz.devices(devTempHum).temperature..'°C - H: '..dz.devices(devTempHum).humidity..'%')
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')
if tonumber(dz.devices(devTempHum).humidity) > humMax then
dz.log('Umidità ['..dz.devices(devTempHum).humidity..'%] sopra il valore impostato.... accensione')
dz.devices(devFan).switchOn().checkFirst()
elseif tonumber(dz.devices(devTempHum).humidity) <= humMin then
dz.log('Umidità ['..dz.devices(devTempHum).humidity..'%] sotto il valore impostato.... spegnimento')
dz.devices(devFan).switchOff().checkFirst()
end
--evalFan(dz,humMax,humMin)
elseif devName.name == devTempHum and dz.devices(devLuce).state == 'Off' then
dz.log('Variazione T e H ==> Valutazione')
if tonumber(dz.devices(devTempHum).humidity) > humMax then
dz.log('Umidità ['..dz.devices(devTempHum).humidity..'%] sopra il valore impostato.... accensione')
dz.devices(devFan).switchOn().checkFirst()
elseif tonumber(dz.devices(devTempHum).humidity) <= humMin then
dz.log('Umidità ['..dz.devices(devTempHum).humidity..'%] sotto il valore impostato.... spegnimento')
dz.devices(devFan).switchOff().checkFirst()
end
-- evalFan(dz,humMax,humMin)
end
end
}