AfterSec(10) gives error

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

Moderator: leecollings

Post Reply
willemdomotica
Posts: 4
Joined: Sunday 20 December 2020 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

AfterSec(10) gives error

Post 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]
willemdomotica
Posts: 4
Joined: Sunday 20 December 2020 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: AfterSec(10) gives error

Post 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
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: AfterSec(10) gives error

Post by willemd »

willemdomotica
Posts: 4
Joined: Sunday 20 December 2020 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: AfterSec(10) gives error

Post 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)
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: AfterSec(10) gives error

Post 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.
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest