Page 1 of 1

How to do this in dz vents?

Posted: Monday 01 June 2020 12:05
by edwin1234
I tried in blocky but it doesnt work It keeps repeating the script
Is this possible in dzvents?
I have a switch “raam open” its have to go on for 1 minute if humidity sensor “temp/vocht” is 70% or higher
And if the humidity is lower then switch “raam dicht” must go on for 1 minute and then off

I will explain
Switch raam open switch a window opener that will take one minute to fully open and then needs the off signal
Switch raam dicht switch the window opener to close the window and that takes one minute to fully close and then needs an off signal.

Hope someone can help me
Thanks

Re: How to do this in dz vents?

Posted: Monday 01 June 2020 13:17
by waaren
edwin1234 wrote: Monday 01 June 2020 12:05 Switch raam open switch a window opener that will take one minute to fully open and then needs the off signal
Switch raam dicht switch the window opener to close the window and that takes one minute to fully close and then needs an off signal.
Could look like below script.

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'temp/vocht',
        },
    },
    
    logging = 
    {
        level = domoticz.LOG_DEBUG,  -- change to domoticz.LOG_ERROR when script works OK.
    },

    data =
    {
        currentState = 
        { 
            initial = '',
        },
    },

    execute = function(dz, item)
        local temperature = item.temperature
        local humidity = item.humidity
        local open = dz.devices('raam open')
        local close = dz.devices('raam dicht')

        dz.log('Device ' .. item.name .. '; temperature is '.. temperature .. '° C , humidity is ' ..humidity .. '% and window is ' .. dz.data.currentState ..'.', dz.LOG_DEBUG)
        if humidity > 70 and dz.data.currentState ~= 'Open' and open.lastUpdate.secondsAgo > 120 and close.lastUpdate.secondsAgo > 120 then -- don't want to toggle every couple of seconds
            open.switchOn()
            open.switchOff().afterSec(60)
            dz.data.currentState = 'Open'
        elseif humidity < 70 and dz.data.currentState ~= 'Closed' and open.lastUpdate.secondsAgo > 120 and close.lastUpdate.secondsAgo > 120 then -- don't want to toggle every couple of seconds
            close.switchOn()
            close.switchOff().afterSec(60)
            dz.data.currentState = 'Closed'
        end
    end
}



Re: How to do this in dz vents?  [Solved]

Posted: Monday 01 June 2020 14:50
by edwin1234
Thank you very much,
Your the best :P
I m gonna try it out

Regards
Edwin