Local variable not recognized?  [Solved]

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

Moderator: leecollings

Post Reply
straatm
Posts: 19
Joined: Monday 15 January 2018 10:06
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Local variable not recognized?

Post by straatm »

All I try to use the within_min() command and use a local variable at the beginning of the script.
But there is always this log that the Value is "a nil value" it seems the local variable is not recognized.
Someone any idea how to solve this? See script and log below.

Code: Select all

local RANDOM_DELAY_MINS = 20
return {
       on = { timer = { 'at nighttime at 07:00 on mon, tue, wed, thu, fri',
                     'at nighttime at 08:20 on sat, sun',
                     'at sunrise', 
                     'at sunset',
                     'at 15 minutes before sunset',
                     'at 22:00 at nighttime on mon, tue, wed, thu, fri, sat, sun',
                     'at 23:15' }
          -- timer = { 'at sunrise' },
          -- timer = { 'at 23:00 at nighttime on mon, tue, wed, thu, fri, sat, sun'}
	},
	execute = function(domoticz, timer)
	    domoticz.log(timer.trigger)
	    if (domoticz.time.matchesRule('at 07:00')) then
	       domoticz.log('Dit werkt om 7:00 uur')
	       domoticz.groups('Binnen-Lampen').switchOn().repeatAfterSec(1,3)
	    elseif (domoticz.time.matchesRule('at 08:20')) then
	       domoticz.log('Dit werkt om 8:20 uur op Zaterdag en Zondag')
	       domoticz.groups('Binnen-Lampen').switchOn().repeatAfterSec(1,3)
	    elseif (domoticz.time.matchesRule('at sunrise')) then
	       domoticz.log('Zonsopkomst')
	       domoticz.groups('Binnen-Lampen').switchOff().repeatAfterSec(1,3)
	    elseif (domoticz.time.matchesRule('at 15 minutes before sunset') and domoticz.time.matchesRule('at 00:00-23:00')) then
	       domoticz.log('15 minuten voor Zonsondergang') 
	       domoticz.groups('Binnen-Lampen').switchOn().repeatAfterSec(1,3)
	    elseif (domoticz.time.matchesRule('at 23:15') and domoticz.devices('$Hulp-Laat-Thuis').state == 'Off') then
	       domoticz.log('Slaaplekker') 
	       domoticz.groups('Binnen-Lampen').switchOff().within_min(RANDOM_DELAY_MINS)
	       domoticz.groups('Binnen-Lampen').switchOff().aftermin('30')
	    else
	       domoticz.log('Slaaplekkerrrrrr binnen')
	    end
	end
}

Code: Select all

2019-06-14 23:15:00.611 Status: dzVents: Error (2.4.19): An error occured when calling event handler DZ_SfeerVerlichtingBinnen
2019-06-14 23:15:00.611 Status: dzVents: Error (2.4.19): .../dzVents/generated_scripts/DZ_SfeerVerlichtingBinnen.lua:30: attempt to call field 'within_min' (a nil value)
2019-06-14 23:15:00.611 Status: dzVents: Info: ------ Finished DZ_SfeerVerlichtingBinnen
2019-06-14 23:15:00.612 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Local variable not recognized?

Post by waaren »

straatm wrote: Saturday 15 June 2019 8:30 All I try to use the within_min() command and use a local variable at the beginning of the script.
But there is always this log that the Value is "a nil value" it seems the local variable is not recognized.
The right way to call this method is withinMin(xxxx). You tried it with within_min(xxxx) which was the syntax for dzVents < 2.0
Also be aware that case matters. aftermin is not the same as afterMin
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
straatm
Posts: 19
Joined: Monday 15 January 2018 10:06
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Local variable not recognized?  [Solved]

Post by straatm »

Waaren,

Thanks that was the solution...
I used an old example taken from the internet

BR,
Marc
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests