Page 1 of 1

Trying to fully understand the timer trigger

Posted: Friday 08 May 2020 10:11
by Number8
Hello,
I was wondering whether

Code: Select all

	on = {
		timer = {'every minute, every 2 minutes'},
	},
fires up script once every minute AND once every 2 minutes. I made some tests and apparently it does not. My understanding is that 'every 2 minutes' is concurrent to 'every minute' and cannot be served. I'm currently using a loop persistent variable to run some stuff every minute and some more stuff every 2 minutes. Is it the best approach?
Thank you

Re: Trying to fully understand the timer trigger

Posted: Friday 08 May 2020 10:32
by waaren
Number8 wrote: Friday 08 May 2020 10:11 My understanding is that 'every 2 minutes' is concurrent to 'every minute' and cannot be served.
The on = timer section is evaluated once a minute by dzVents and if any of the rules evaluates to true, the script is triggered.
There is no order in the evaluation so if more rules are true you cannot predict which one it will be, even it looks like it does.
After some time or a restart of the event system the order might change

If you want to combine the 2 minute actions with the every minute actions in one script you could do it like below.

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'every 2 minutes',
            'every 3 minutes',
            'every 1 minutes',
            'every 4 minutes',
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG, 
    },

    execute = function(dz, item)
        dz.log('this script was triggered by timer rule: '  .. item.trigger,dz.LOG_DEBUG )
        
        if dz.time.matchesRule('every 2 minutes') then
            dz.log('Doing all the every 2 minute actions here... ',dz.LOG_DEBUG )
            -- 2 minutes actions start
            
            -- 2 minutes actions end
        end    
    
        dz.log('Doing all the every minute work here... ',dz.LOG_DEBUG )

        
    end
}

[code]

Re: Trying to fully understand the timer trigger

Posted: Friday 08 May 2020 16:19
by Number8
Oh I see. But if I take the example to the letter, the 4 minutes trigger will never be seen. Should we code ?

Code: Select all

        timer = 
        {
            'every 4 minutes',
            'every 3 minutes',
            'every 2 minutes',
            'every 1 minute',
        },
    },
And then in the code, if the trigger is 4 minutes, then the code for 2 minutes and 1 minute shoud be run as well?

Thank you

Re: Trying to fully understand the timer trigger  [Solved]

Posted: Friday 08 May 2020 16:55
by waaren
Number8 wrote: Friday 08 May 2020 16:19 Oh I see. But if I take the example to the letter, the 4 minutes trigger will never be seen. Should we code ?
The timer section here was just an example. The only rule you need there for you requirement is ' every 1 minute' (or 'every minute' what does the same).