Trying to fully understand the timer trigger  [Solved]

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

Moderator: leecollings

Post Reply
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Trying to fully understand the timer trigger

Post 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
Debian buster on NUC and three RPi with buster.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trying to fully understand the timer trigger

Post 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]
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Trying to fully understand the timer trigger

Post 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
Debian buster on NUC and three RPi with buster.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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).
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest