Page 1 of 1

error using this script

Posted: Thursday 28 November 2019 19:24
by snellejellep
hi all,

the basic functions of this script work but i get the following error:

Code: Select all

2019-11-28 19:22:42.439 Error: dzVents: Error: (2.5.0) An error occurred when calling event handler Licht hal beneden
2019-11-28 19:22:42.439 Error: dzVents: Error: (2.5.0) .../scripts/dzVents/generated_scripts/Licht hal beneden.lua:18: attempt to compare string with table
this is the script, what am i doing wrong?

Code: Select all

return {
	on = {
		devices = {
			'PIR hal beneden'
		}
	},
	execute = function(dz, device)
		dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
		
		local pir           = dz.devices("PIR hal beneden")
		local lamp          = dz.devices("Lamp hal beneden")
		local lux           = dz.devices("LUX hal beneden").lux
		local tijd          = dz.time
		
		if pir.state == "On" and lux < 20 then
		    lamp.cancelQueuedCommands()
		    lamp.switchOn().forMin(1)
		    if tijd > '23:00' and tijd < '06:00' then
		        lamp.dimTo(30)
		    elseif tijd > '06:00' and tijd < '23.00' then
		        lamp.dimTo(100)
		    end
		end
		
		
	end
}

Re: error using this script

Posted: Thursday 28 November 2019 19:43
by waaren
snellejellep wrote: Thursday 28 November 2019 19:24 the basic functions of this script work but i get the following error:

Code: Select all

2019-11-28 19:22:42.439 Error: dzVents: Error: (2.5.0) An error occurred when calling event handler Licht hal beneden
2019-11-28 19:22:42.439 Error: dzVents: Error: (2.5.0) .../scripts/dzVents/generated_scripts/Licht hal beneden.lua:18: attempt to compare string with table
dz.time is a table with methods, attributes and subtables and a table cannot be compared with a string like '23:00'
For this functionality the method matchesRule is available.

Check this

Code: Select all

return {
	on = {
		devices = {
			'PIR hal beneden'
		}
	},
	execute = function(dz, item)
		dz.log('Device ' .. item.name .. ' was changed', dz.LOG_INFO)
		
		local lamp          = dz.devices("Lamp hal beneden")
		local lux           = dz.devices("LUX hal beneden").lux
		
		if item.state == "On" and lux < 20 then
		    lamp.cancelQueuedCommands()
		    lamp.switchOff().afterMin(1)
		    if dz.time.matchesRule('at 23:00-06:00') then
		        lamp.dimTo(30)
		    else
		        lamp.dimTo(100)
		    end
		end
	end
}

Re: error using this script  [Solved]

Posted: Thursday 28 November 2019 19:56
by snellejellep
waaren wrote: Thursday 28 November 2019 19:43 dz.time is a table with methods, attributes and subtables and a table cannot be compared with a string like '23:00'
For this functionality the method matchesRule is available.
your script makes sense, i understand now. thanks again!

i got this error:

Code: Select all

2019-11-28 19:56:57.860 Error: dzVents: Error: (2.5.0) An error occurred when calling event handler Licht hal beneden
2019-11-28 19:56:57.860 Error: dzVents: Error: (2.5.0) .../scripts/dzVents/generated_scripts/Licht hal beneden.lua:8: attempt to index a nil value (global 'device')
i removed the log line 8 and it was gone.
i guess it has something to do with device no longer being specified in line 7? there is item instead of device there.