Page 1 of 1

Script for ventilator

Posted: Friday 11 January 2019 11:42
by Labtec
Hi,

Can someone help me with a script for turning on my central ventilator.

If light is on (idx 138) for 3 minutes then turn on ventilator (idx 140) for 5 minutes.

Thanks!

Re: Script for ventilator

Posted: Friday 11 January 2019 12:52
by JanJaap
Hi Labtec,

I control my central ventilator based on humidity, which I presume is what you really want in the end (I did not want the blower to start running when just brushing my teeth....). I have a humidity sensor in the bath room, compare that to the humidity in the living room and on a delta between the 2 switch on the blower (when using humidity you really need some comparison value, I started with absolute humidity levels for the bathroom but that drove me crazy because it would start running in the middle of the night which my wife did not appreciate....)

I know this is not an exact answer to your question, but below is what I made, don't know if you can use it......

Setup:
- nest thermo in the living room
- Everspring ST814 in the bathroom (robbshop, dutch webshop
- a Fibaro FGS222 2 realy switch that I mounted in the manual control switch of the blower, which is located in the kitchen (the blower is named WTW here)

I created a LUA for this:

Code: Select all

----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Debug = "NO"                    -- Turn debugging on ("YES") or off ("NO")
RequestWTW = uservariables["WtwStandReq"] -- Requested WTW stand (pre-load with current)

----------------------------------------------------------------------------------------------------------
-- Script functions
----------------------------------------------------------------------------------------------------------

commandArray = {}
time = os.date("*t")
-- determine switch on/off for WTW due humidity sensor
for deviceName,deviceValue in pairs(devicechanged) do
    if (deviceName=='Temp en vocht badkamer_Humidity') then
        sBadTemp, sBadHumidity = otherdevices_svalues['Temp en vocht badkamer']:match("([^;]+);([^;]+)")
        if Debug=="YES" then
            print("event on '"..deviceName.."', value '"..tostring(deviceValue).."'");
        end
        --determine setpoint
        sNestTemp, sNestHumidity = otherdevices_svalues['Nest Temp en Vocht']:match("([^;]+);([^;]+)")
        if Debug=="YES" then
            print("Nest, temp '" ..tostring(sNestTemp).."' humidity '"..tostring(sNestHumidity).."'")
        end
        sLevelOn = math.min(math.max(sNestHumidity + 25, 40), 80)
        commandArray["Variable:WtwAanLevel"] = tostring(sLevelOn)
        sLevelOff = sLevelOn - 10
        commandArray["Variable:WtwUitLevel"] = tostring(sLevelOff)
        print("setpoints, on '" ..tostring(sLevelOn).."' off '"..tostring(sLevelOff).."'")
        if (deviceValue >= sLevelOn) then
            --print("humidity high enough to turn on WTW");
            commandArray['WTW Aan request'] = 'Off' -- request can be reset
            if (otherdevices['WTW stand 3'] == 'Off') then
                print("WTW goes On, '"..deviceName.."', value '"..tostring(deviceValue).."'");
                RequestWTW = 3
            end
        end
        if (deviceValue <= sLevelOff and otherdevices['WTW stand 3'] == 'On') then
            print("WTW goes Off, '"..deviceName.."', value '"..tostring(deviceValue).."'");
            RequestWTW = 1
            commandArray['Wtw blokkeer'] = 'Off' -- request can be reset
        end
    end
end
I process the RequestWTW value further on the determine of it needs to be switched on. It is a 3 level ventilator, level 1 is the normal level, level 2 I do not use for the humidity control

Re: Script for ventilator

Posted: Friday 11 January 2019 13:24
by waaren
Labtec wrote: Friday 11 January 2019 11:42 Can someone help me with a script for turning on my central ventilator.
If light is on (idx 138) for 3 minutes then turn on ventilator (idx 140) for 5 minutes.
See below for a dzVents script that should do what you describe. (just assuming it is for the toilet. If it is for the bathroom you are better of with the script JanJaap posted)

If you are not yet familiar with dzvents then please look at the 10 lines using dzVents with Domoticz for an intro to dzVents and howto get this script active in domoticz.

Code: Select all

-- Delayed ventilator

local callback = "threeMinutesPast"

return {
    on      =   {   
                    devices      =      { 138 },                -- Light
                    httpResponses   =   { callback }
                },
                
    logging =   {   
                    level     =   domoticz.LOG_DEBUG,
                    marker    =   "delayed Ventilator"    
                },
    
    execute = function(dz, item)
        local light       = dz.devices(138)
        local ventilator  = dz.devices(140)

        local function delayedURL(delay)
            local logString = "/json.htm?type=command&param=addlogmessage&message=" .. dz.utils.urlEncode("Check if light " .. light.name .. " is still On.")
            local  url= dz.settings['Domoticz url'] .. logString
            dz.openURL({    
                            url = url,
                            method = "GET",
                            callback = callback 
                      }).afterSec(delay)                      
        end
        
        if item.isDevice and item.active then
            delayedURL(180)
        elseif light.active then
            ventilator.switchOn().forSec(300)
        end
    end
}