Page 1 of 1

Timer function "afterSec" acts weird

Posted: Saturday 01 October 2022 20:03
by danko
About Domoticz
Version: 2022.1
Build Hash: c9526851b
Compile Date: 2022-01-31 08:34:32
dzVents Version: 3.1.8
Python Version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
--
(Running on a raspberry zero)


Being a complete noob, I do not understand the following behaviour:
The following script runs fine upto 20 seconds. Then it stops en continues after 40 seconds.
In the example it runs 10 cycles. If i change variable 'interval' to 1 it runs fine. (It never reaches second 20)
If I change 'interval' to 4 it runs only 5 cycles. (the other 6 are rapidly executed after 40 seconds.
It looks like a bug to me but i might overlook something obvious.

Any help is


return
{
on =
{
-- devices = {'Losse RGB lamp'},
timer = {'every minute'},

customEvents =
{
'delayed',
},
},
execute = function(domoticz, item)
light = domoticz.devices('Losse RGB lamp')
sec = 0
interval = 2
if item.isTimer then
-- domoticz.emitEvent('delayed', domoticz.time.rawTime ).afterSec(10)
-- groen, blauw, rood, intensity(rgb), intensity(W), intensity(Geel)
light.setHex(200, 222, 222) -- wit 1
sec = sec + interval
light.setHex(00, 22, 222).afterSec(sec) -- rood 2
sec = sec + interval
light.setHex(200, 22, 22).afterSec(sec) -- groen 3
sec = sec + interval
light.setHex(00, 222, 22).afterSec(sec) -- blauw 4
sec = sec + interval
light.setHex(00, 222, 222).afterSec(sec) -- paars 5
sec = sec + interval
light.setHex(200, 222, 22).afterSec(sec) -- cyaan 6
sec = sec + interval
light.setHex(00, 22, 222).afterSec(sec) -- rood 7
sec = sec + interval
light.setHex(200, 22, 22).afterSec(sec) -- groen 8
sec = sec + interval
light.setHex(00, 222, 22).afterSec(sec) -- blauw 9
sec = sec + interval
light.setHex(00, 222, 222).afterSec(sec) -- paars 10
sec = sec + interval
light.setHex(100, 100, 22).afterSec(sec) -- cyaan 11
-- sec = sec + 4
else
-- domoticz.notify('Delayed', 'Event was emitted at ' .. item.data, domoticz.PRIORITY_LOW)
domoticz.log('Event was emitted at ' .. item.data, domoticz.PRIORITY_LOW)
end
end
}

Re: Timer function "afterSec" acts weird

Posted: Sunday 02 October 2022 1:04
by plugge
You could start by making the variables local to avoid any global interaction.
(I did not check the rest of the script)

Code: Select all

local light = domoticz.devices('Losse RGB lamp')
local sec = 0
local interval = 2
(BTW: please put your script between code tags for readability.)

Re: Timer function "afterSec" acts weird

Posted: Sunday 02 October 2022 9:58
by danko
Plugge thanks for suggestion.
It surely is better programming practice.
But unfortunately it does not make a difference.