Page 1 of 1

conditional timer trigger

Posted: Saturday 30 September 2017 10:22
by dlefol
Hello,

I have a script in dzVents turning every 2 minutes using a timer trigger. In that script, the first thing I do is check if a specific value is ON and if it is the case I peform some actions. The script looks like this:

Code: Select all

return {
    active = true,
        on = {
                timer = {
                                'Every 2 minutes'
                        }
             },

    execute = function(domoticz)

        if(domoticz.devices(automation).state == 'On') then
             -- Perform some actions and checks every 2 minutes
       end
end

I was wondering if it would be possible to optimise this by triggering the timer call every 2 minutes only when the switch is ON, something looking a bit like that basically:

Code: Select all

return {
    active = true,
        on = {
                timer = {
                                'Every 2 minutes' if domoticz.devices(automation).state == 'On'
                        }
             },

    execute = function(domoticz)
             -- Perform some actions and checks every 2 minutes
end
I tried to look around but could not see anything looking like this. Any ideas ?

Cheers

Re: conditional timer trigger

Posted: Wednesday 04 October 2017 9:19
by BakSeeDaa
dlefol wrote: Saturday 30 September 2017 10:22 ... Any ideas ?

Cheers
According to the documentation you can use a function in the timer table...

Code: Select all

        function(domoticz)
            -- you can use domoticz.time to get the current time
            -- note that this function is called every minute!
            -- custom code that either returns true or false
            ...
        end
But it won't speed up your script. In fact it would slow things down because your function will be evaluated every minute.

Even if your statement

Code: Select all

'Every 2 minutes' if domoticz.devices(automation).state == 'On'
would work, it would still have to be evaluated every minute, hence wouldn't optimize your script in a positive direction.

;)

Re: conditional timer trigger

Posted: Wednesday 04 October 2017 10:15
by dlefol
good point I didn't think about that.

Thanks for taking the time to reply :)

Re: conditional timer trigger

Posted: Wednesday 04 October 2017 11:01
by dannybloe
I would do it in your execute block in this case as the execute-block is only executed when the triggers (device and timers) are met while a timer function is evaluated for EVERY event that is triggered in Domoticz. So for performance reasons put as much logic that uses device information in the execute block.