Help wanted with ventilation script

Easy to use, 100% Lua-based event scripting framework.
Post Reply
basjes
Posts: 3
Joined: Tuesday 30 October 2018 23:01
Target OS: Raspberry Pi
Domoticz version:
Location: NL
Contact:

Help wanted with ventilation script

Post by basjes » Tuesday 30 October 2018 23:18

Hi,

I'm new to dzVent scripting and thought to setup a ventilation script.

Unfortunately it is not as easy as I thought ;)
I have a ventilation box with multiple levels which I can control wit a selector switch in domoticz.
The actual state of the box is sent to domoticz using ESPEasy.

What I'm trying to achieve is the following:
between 07:00 and 22:00 (daytime) the ventilation box may run at a higher speed (switch level 10) and if the humidity rises above 60 % it is supposed to run at switch level 30.
Between 22:00 and 07:00 (nighttime) the ventilation box must run at a lower speed (switch level 00) and if the hunidity rises above 60% it is supposed to run at switch level 10.

I've searched the wiki and tried to use examples. So far I created the following script, but is does not work as expected.
It only seems to run the daytime part. I'm probably overthinking this and missing something (for me not so) obvious.

Can you guys give me som pointers ?
Thanks.

Code: Select all

return {
	on = {
		timer = {'every minute'}
			 },
   execute = function(domoticz, timer)
   		
if (domoticz.time.hour >=7 and domoticz.time.hour <22) then
	domoticz.log('het is overdag')
         			
	if domoticz.devices('Thermo Badkamer').humidity >= 60 then
	domoticz.log('Het is vochtig op de badkamer!', domoticz.LOG_INFO)
	
		if domoticz.devices('Ventilatie').switchSelector < 40 then
		domoticz.log('Er is geen timer ingesteld', domoticz.LOG_INFO)
		domoticz.devices('Ventilatie').switchSelector(20)  			
		end
  	    	        
    if domoticz.devices('Thermo Badkamer').humidity <= 60 then
  	domoticz.log('Het is niet (meer)vochtig op de badkamer!', domoticz.LOG_INFO)
	domoticz.devices('Ventilatie').switchSelector(10)
	end

elseif (domoticz.time.hour >=22 and domoticz.time.hour <7) then
	domoticz.log('het is avond/nacht')
	
    if domoticz.devices('Thermo Badkamer').humidity >= 60 then
  	domoticz.log('Het is vochtig op de badkamer!', domoticz.LOG_INFO)
  	
    	if domoticz.devices('Ventilatie').switchSelector < 40 then
		domoticz.log('Er is geen timer ingesteld', domoticz.LOG_INFO)
		domoticz.devices('Ventilatie').switchSelector(10)  			
		end

    if domoticz.devices('Thermo Badkamer').humidity <= 60 then	
	domoticz.log('Het is niet (meer) vochtig op de badkamer!', domoticz.LOG_INFO)
	domoticz.devices('Ventilatie').switchSelector(00)
    end
end
end
end
end
}

User avatar
waaren
Posts: 1348
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Help wanted with ventilation script

Post by waaren » Wednesday 31 October 2018 0:52

basjes wrote:
Tuesday 30 October 2018 23:18
I'm new to dzVent scripting and thought to setup a ventilation script.
Do you see anything in the log ? That would be useful for debugging.

I use a script similar to the one below and adjusted some parts to enable it for your situation. Please check if it fits your purpose. Any questions feel free to ask.

Code: Select all

return {
    on      =   {   timer   = { "every minute"  }},
   
   logging  =   {   level   = domoticz.LOG_DEBUG, 
                    marker  = "ventilation"      },   
   
   execute = function(dz)
    
        local humidity          = dz.devices("Thermo Badkamer").humidity
        local ventilator        = dz.devices("Ventilatie")
        local ventLevel         = ventilator.level
        
        local humidityFence     = 60
        local noTimerLevel      = 40
        
        local lowVentDaytime    = 10
        local highVentDaytime   = 20
        local lowVentNighttime  = 0
        local highVentNighttime = 10
        
        local function logWrite(str,level)
            if not level then level = LOG_DEBUG end
            dz.log(str,level)
        end
        
        local function manageVentilator(low,high) 
            if humidity >= humidityFence then
                logWrite("Het is vochtig op de badkamer! (" .. humidity .. "%)")
                if ventLevel < noTimerLevel then
                    logWrite("Er is geen timer ingesteld")
                    if ventLevel ~= high then 
                        logWrite("Er wordt geschakeld")
                        ventilator.switchSelector(high) 
                    else
                        logWrite("Ventilator draait al op juiste nivo; dus geen actie vereist")
                    end              
                else
                    logWrite("Er is een timer ingesteld")
                end
            else              
                logWrite("Het is niet (meer) vochtig op de badkamer! (" .. humidity .. "%)")
                if ventLevel ~= low then 
                    logWrite("Er wordt geschakeld")
                    ventilator.switchSelector(low) 
                else
                    logWrite("Ventilator draait al op juiste nivo; dus actie vereist")
                end
            end
        end
        
        
        -- Main 
        if dz.time.matchesRule("at 07:00-22:00") then
            logWrite("het is overdag")
            manageVentilator(lowVentDaytime,highVentDaytime)
        else
            logWrite("het is avond/nacht")
            manageVentilator(lowVentNighttime,highVentNighttime)
        end
    end
} 
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

basjes
Posts: 3
Joined: Tuesday 30 October 2018 23:01
Target OS: Raspberry Pi
Domoticz version:
Location: NL
Contact:

Re: Help wanted with ventilation script

Post by basjes » Wednesday 31 October 2018 9:38

Thanks for the script. I will look at it tonight

basjes
Posts: 3
Joined: Tuesday 30 October 2018 23:01
Target OS: Raspberry Pi
Domoticz version:
Location: NL
Contact:

Re: Help wanted with ventilation script

Post by basjes » Wednesday 31 October 2018 22:05

waaren wrote:
Wednesday 31 October 2018 0:52
basjes wrote:
Tuesday 30 October 2018 23:18
I'm new to dzVent scripting and thought to setup a ventilation script.
Do you see anything in the log ? That would be useful for debugging.

I use a script similar to the one below and adjusted some parts to enable it for your situation. Please check if it fits your purpose. Any questions feel free to ask.

Code: Select all

return {
    on      =   {   timer   = { "every minute"  }},
   
   logging  =   {   level   = domoticz.LOG_DEBUG, 
                    marker  = "ventilation"      },   
   
   execute = function(dz)
    
        local humidity          = dz.devices("Thermo Badkamer").humidity
        local ventilator        = dz.devices("Ventilatie")
        local ventLevel         = ventilator.level
        
        local humidityFence     = 60
        local noTimerLevel      = 40
        
        local lowVentDaytime    = 10
        local highVentDaytime   = 20
        local lowVentNighttime  = 0
        local highVentNighttime = 10
        
        local function logWrite(str,level)
            if not level then level = LOG_DEBUG end
            dz.log(str,level)
        end
        
        local function manageVentilator(low,high) 
            if humidity >= humidityFence then
                logWrite("Het is vochtig op de badkamer! (" .. humidity .. "%)")
                if ventLevel < noTimerLevel then
                    logWrite("Er is geen timer ingesteld")
                    if ventLevel ~= high then 
                        logWrite("Er wordt geschakeld")
                        ventilator.switchSelector(high) 
                    else
                        logWrite("Ventilator draait al op juiste nivo; dus geen actie vereist")
                    end              
                else
                    logWrite("Er is een timer ingesteld")
                end
            else              
                logWrite("Het is niet (meer) vochtig op de badkamer! (" .. humidity .. "%)")
                if ventLevel ~= low then 
                    logWrite("Er wordt geschakeld")
                    ventilator.switchSelector(low) 
                else
                    logWrite("Ventilator draait al op juiste nivo; dus actie vereist")
                end
            end
        end
        
        
        -- Main 
        if dz.time.matchesRule("at 07:00-22:00") then
            logWrite("het is overdag")
            manageVentilator(lowVentDaytime,highVentDaytime)
        else
            logWrite("het is avond/nacht")
            manageVentilator(lowVentNighttime,highVentNighttime)
        end
    end
} 
Your script works like a charm.

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests