Page 1 of 1

Timer function

Posted: Sunday 30 August 2020 10:32
by oost1346
Hi guys,

I'm new to dzVents so need some help :)

I want to create an function which counts the minutes a certain switch is on and want to put the minutes in a variable (so I can use it in a blockly)
Can you experts give me an example of such code so I can play with it?

Thanks in advance....

Bob

Re: Timer function

Posted: Sunday 30 August 2020 18:08
by waaren
oost1346 wrote: Sunday 30 August 2020 10:32 I want to create an function which counts the minutes a certain switch is on and want to put the minutes in a variable (so I can use it in a blockly)
This should do it

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'every minute', 
        }
    },

    execute = function(dz)
        local myDevice = dz.devices('mySwitch')
        local myVar = dz.variables('mySwitch active minutes')

        if myDevice.active then
            myVar.set(myDevice.lastUpdate.minutesAgo)
        elseif myVar.value ~= 0 then
            myVar.set(0)
        end    
    end
}

Re: Timer function  [Solved]

Posted: Sunday 30 August 2020 22:57
by oost1346
Thanks waaren....works like a charm :)

Bob