Page 1 of 1

AfterSec(10) gives error

Posted: Monday 05 December 2022 23:05
by willemdomotica
Hi, I am getting this error when using AfterSec(10) in a dzVents scripts execute section

Code: Select all

dz.devices('Siren Alarm').switchOff().AfterSec(10)
Error: attempt to call a nil value

The script works perfectly fine when I remove the option 'AfterSec(10)'
The device here is a coolcam siren, which I would like to silence 10 seconds later.
Tried to search for the answer in the dzVents documentation and on the forum, without luck so far.
Would appreciate if anybody can point me in the right direction.

Using:
Version: 2022.2
Build Hash: eea9db734
Compile Date: 2022-11-05 13:05:35
dzVents Version: 3.1.8
Python Version: 3.7.3 (default, Oct 31 2022, 14:04:00) [GCC 8.3.0]

Re: AfterSec(10) gives error

Posted: Monday 05 December 2022 23:22
by willemdomotica
Here is the whole script, in case you wonder:

Code: Select all

return {
    
on = { devices = { 'ZW-Deur_1' } },

logging = { level = domoticz.LOG_INFO, marker = "reset-alarm"} ,  

execute = function(dz, device)

local siren = 'Siren Alarm'

if (device.state == 'Off') and (dz.devices(siren).state == 'On') then
	dz.log('Alarm ' .. siren .. ' uitgeschakelen over 5 seconden  ', dz.LOG_INFO)
	dz.devices(siren).switchOff().AfterSec(5)
end -- if

end -- execute function

} -- return

Re: AfterSec(10) gives error

Posted: Monday 05 December 2022 23:31
by willemd

Re: AfterSec(10) gives error

Posted: Monday 05 December 2022 23:33
by willemdomotica
I seem to have answered my own question: LUA is case sensitive. hence dzVents is also case sensitive.
This means that the statement above must be correctly written as:

Code: Select all

afterSec(5)

Re: AfterSec(10) gives error

Posted: Tuesday 06 December 2022 22:47
by HvdW
Maybe this script can help you.

Code: Select all

-- Elektrische deken
The if construct is different.


local Sonof = 'Elektrische deken'

return
{
    on =
    {
        devices =
        {
            Sonof,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = 'Elektrische deken',
    },

    execute = function(dz, item)
        local Sonof = dz.devices(Sonof)

        if item == Sonof and item.active then
            Sonof.switchOff().afterMin(59)
        end

    end
}
I made it to switch off the electric blanket after one hour.