Page 1 of 1

Multiple afterSec for same device

Posted: Tuesday 02 June 2020 22:34
by Doomic
Already asked it in another topic. But i guess i could beter have created another one.
What i saw in the other topic was multiple use of afterSec for the same device.
However i can't get it working.
Only my last set statement is executed.

found something in de doc about scheduled commands within the range of the new scheduled command is automaticly canceled.
Therefore i changed the order by schedule first that command with the highest time. But this isn't working either; at the end, only the last command is executed.

Simple example:

Code: Select all

return {
    on = { 
        devices = { 
            "SwitchTest" 
        } 
    },
    execute = function(domoticz, device) 
        local varTest = domoticz.variables("VarTest")
        varTest.set(2).afterSec(2)
        varTest.set(1).afterSec(1)
    end
}
you should expect that varTest=2 after 2(or more) seconds. But it looks like .set(1) command is also canceling the set(2) command. So i end up with varTest=1 after 2 seconds.

is this a bug? Or can't you schedule multiple commands for 1 device/var?

Original post:
https://www.domoticz.com/forum/viewtopi ... 90#p249090

Re: Multiple afterSec for same device

Posted: Tuesday 02 June 2020 23:33
by waaren
Doomic wrote: Tuesday 02 June 2020 22:34 Only my last set statement is executed.
is this a bug? Or can't you schedule multiple commands for 1 device/var?
Explanation inside these scripts

Code: Select all

return
{
    on =
    {
        devices =
        {
            'afterTrigger', -- change to a device that will trigger this script
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },

    execute = function(dz)

        local myVar = dz.variables('test')
        local myVar2 = dz.variables('test2')

        for i = 1, 20 do
            myVar.set(i).afterSec(i)  -- all afterSec commands are executed
        end

        for i = 20, 1 , -1 do
             myVar2.set(i).afterSec(i) -- afterSec with a shorter delay overwrites all afterSec with a longer delay
        end
    end
}

Code: Select all

return
{
    on =
    {
        variables =
        {
            'test*',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },

    execute = function(dz, item)
        dz.log('Variable ' .. item.name .. ' was changed to ' .. item.value , dz.LOG_DEBUG)
    end
}

Re: Multiple afterSec for same device

Posted: Wednesday 03 June 2020 16:40
by Doomic
ok. then i understood the documentation wrong.. so sorter delay will cancel all longer delays...
and indeed i can see that this is working in a test script.

My origional problem appears to be something else...
First i tought the issue is with decimals... afterSec(2.5). But that is indeed also working fine.
even a chain like afterSec(2.2) | afterSec(2.7) | afterSec(3.1) or something like that works in my test setup.

i found that my silent() is not working. I have a blinds (roller shutter) dummy device. A dummy switch. And 2 dzvents scripts. first script is triggered by dummy switch. Second script is triggered by the blinds.

script for dummy switch looks like below. The other script is more complex, but if it is executed it conflicts with the dummy switch script. That is fine, but it should not be executed... For testing purpose i removed evrything inside that complex script and only place a log at the top of that script. Looks like the silent() is not respected. because that log statement is executed.
I also tried to place the silent after the afterSec() statement. same issue.

Code: Select all

return {
    on = { 
        devices = { 
            "SwitchTest" 
        } 
    },
    logging = {
        level = domoticz.LOG_DEBUG
    },
    execute = function(domoticz, device) 
		local rollerShutter = domoticz.devices("RollerShutter")
        rollerShutter.setLevel(1).silent().afterSec(1)
        rollerShutter.setLevel(2).silent().afterSec(3.1)
        rollerShutter.setLevel(3).silent().afterSec(3.6)
        rollerShutter.setLevel(4).silent().afterSec(4.2)
        rollerShutter.setLevel(5).silent().afterSec(4.7)
        rollerShutter.setLevel(10).silent().afterSec(9.5)
        rollerShutter.setLevel(20).silent().afterSec(20)
    end
}

Code: Select all

return {
    on = { 
        devices = { 
            "RollerShutter" 
        } 
    },
    logging = {
        level = domoticz.LOG_DEBUG
    },
    execute = function(domoticz, device) 
        domoticz.log("This script should not have been triggerd by dummy switch (script)");
    end
}

Re: Multiple afterSec for same device

Posted: Wednesday 03 June 2020 17:29
by waaren
Doomic wrote: Wednesday 03 June 2020 16:40 My origional problem appears to be something else...
First i tought the issue is with decimals... But that is indeed also working fine.
i found that my silent() is not working.
Thx for reporting

It's a combination of these two.
silent() is ignored when the afterSec value is a decimal.

Did a quick search but have not find why this happens. I also checked with some older versions and behavior is already in domoticz for a long time

Re: Multiple afterSec for same device  [Solved]

Posted: Wednesday 03 June 2020 21:01
by Doomic
that makes scense. Because i could not find why it sometimes worked. or why it sometimes got triggerd. With this information i start to debug some more.
Looks like it goes wrong as soon as you use 2 times afterSec with the same math.floor() value.
so afterSec(1.9).silent() & afterSec(2.0).silent() works fine. but afterSec(2.0).silent() & afterSec(2.9).silent() does not... and as soon you hit this situation, all next scheduled triggers won't be silent.

Code: Select all

return {
    on = { 
        devices = { 
            "SwitchTest" 
        } 
    },
    logging = {
        level = domoticz.LOG_DEBUG
    },
    execute = function(domoticz, device) 
		local rollerShutter = domoticz.devices("RollerShutter")
        rollerShutter.setLevel(1).afterSec(2.9).silent() -- OK
        rollerShutter.setLevel(2).afterSec(3.0).silent() -- OK
        rollerShutter.setLevel(3).afterSec(4.0).silent() -- OK
        rollerShutter.setLevel(4).afterSec(4.9).silent() -- NOT SILENT
        rollerShutter.setLevel(5).afterSec(7).silent() -- NOT SILENT
        rollerShutter.setLevel(6).afterSec(9).silent() -- NOT SILENT
    end
}
I guess i have to work around this issue.
Thanks for the help.