Timer function  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
oost1346
Posts: 8
Joined: Thursday 14 December 2017 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Timer function

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Timer function

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
oost1346
Posts: 8
Joined: Thursday 14 December 2017 11:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Timer function  [Solved]

Post by oost1346 »

Thanks waaren....works like a charm :)

Bob
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest