Page 1 of 1

attempt to call field 'after_min' (a nil value)

Posted: Thursday 07 September 2017 10:21
by DannyElfman
Hello,

Quick question. I am very new to LUA and dzVents. I have a simple script generating a classic nil value error but I just cannot get why I have this error ...

Basically, when my squeezebox is playing, it switches on a sonoff connected to my subwoofer.

Script :

Code: Select all

return {

      active = true, -- set to false to disable this script

        on = {
        devices = {
            -- scripts is executed if the device that was updated matches with one of these triggers
            368, -- id Squeezebox
        },

    },
  
    execute = function(domoticz, device)
        
        local caisson = domoticz.devices(527) -- sonoff caisson
        local musique = domoticz.devices('Squeezebox')
        
        if (device.state == 'Off') then
            caisson.switchOff()
        elseif (device.state == 'Stopped') then
            caisson.switchOff().after_min(10)
            musique.switchOff().after_min(10)
        else
            caisson.switchOn()
        
        end
    end
}
switchOn works fine.
switchOff too


From the log :

Code: Select all

2017-09-07 08:12:33.083 dzVents: Info: ------ Start internal script: Caisson_Musique: Device: "Squeezebox (Logitech Media Server)", Index: 368
2017-09-07 08:12:33.083 Error: dzVents: Error: An error occured when calling event handler Caisson_Musique
2017-09-07 08:12:33.083 Error: dzVents: Error: ...cz/scripts/dzVents/generated_scripts/Caisson_Musique.lua:40: attempt to call field 'after_min' (a nil value)
2017-09-07 08:12:33.083 dzVents: Info: ------ Finished Caisson_Musique
Any idea would be really appreciated :)

Re: attempt to call field 'after_min' (a nil value)

Posted: Thursday 07 September 2017 12:22
by elmortero
Please check http://www.domoticz.com/forum/viewtopic ... 59&t=18674 which has the info you need.
Hint: you are using the old dzVents manual, some things have changed.
Your answer is in the part about migrating to the new version.

Re: attempt to call field 'after_min' (a nil value)

Posted: Thursday 07 September 2017 21:05
by DannyElfman
Well, first thanks for taking the time to answer me.
Then thanks for spotting it out :)

I had printed the doc a month and a half ago cause I find it easier to read ... I forgot the update issue ^^

I have updated my script. I did not checked yet if it is working but I will and get back to you.

For those interested, the issue was indeed in the timed command which has to be updated with :

caisson.switchOff().afterMin(10)