error using this script  [Solved]

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

error using this script

Post 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
}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: error using this script

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: error using this script  [Solved]

Post 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.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest