conditional timer trigger

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

Moderator: leecollings

Post Reply
dlefol
Posts: 35
Joined: Monday 21 December 2015 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

conditional timer trigger

Post 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
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: conditional timer trigger

Post 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.

;)
dlefol
Posts: 35
Joined: Monday 21 December 2015 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: conditional timer trigger

Post by dlefol »

good point I didn't think about that.

Thanks for taking the time to reply :)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: conditional timer trigger

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest