dzvents test script did work now not more

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

Moderator: leecollings

Post Reply
anno
Posts: 36
Joined: Wednesday 01 March 2017 13:00
Target OS: Windows
Domoticz version: all
Contact:

dzvents test script did work now not more

Post by anno »

Code: Select all

local device0 = 'test 1'
local device1 = 'test 2'
local device2 = 'test 3'
local device3 = 'test 4'
local device4 = 'test 5'
local device5 = 'test 6'
local device6 = 'test 7'
local device7 = 'test 8'
local device8 = 'test 9'
local device9 = 'test 10'
local device10 = 'test 11'
local device11 = 'test 12'
        
return {

	on = {

		devices = {
			device0,
			device1,
			device2,
			device3,
			device4,
			device5,
			device6,
			device7,
			device8,
			device9,
			cevice10,
			device11,
			device12,
			device13,
			device14,
			device15,
			device16,
			device17,
			devcie18,
			device19,
		},

	},


	-- custom logging level for this script
	logging = {
        level = domoticz.LOG_INFO,
        marker = "test"
    },

	
	execute = function(dz, device)
		
        local kogelKraan= 'test 00'
		local waarde=0
		
		dz.log('device0 is '.. dz.devices(device0).state,dz.LOG_INFO)
		dz.log('device1 is '.. dz.devices(device1).state,dz.LOG_INFO)
		dz.log('device2 is '.. dz.devices(device2).state,dz.LOG_INFO)
		dz.log('device3 is '.. dz.devices(device3).state,dz.LOG_INFO)
		dz.log('device4 is '.. dz.devices(device4).state,dz.LOG_INFO)
		dz.log('device5 is '.. dz.devices(device5).state,dz.LOG_INFO)
		dz.log('device6 is '.. dz.devices(device6).state,dz.LOG_INFO)
		dz.log('device7 is '.. dz.devices(device7).state,dz.LOG_INFO)
		dz.log('device8 is '.. dz.devices(device8).state,dz.LOG_INFO)
		dz.log('device9 is '.. dz.devices(device9).state,dz.LOG_INFO)
		dz.log('device10 is '.. dz.devices(device10).state,dz.LOG_INFO)
		dz.log('device11 is '.. dz.devices(device11).state,dz.LOG_INFO)
		dz.log('device12 is '.. dz.devices(device12).state,dz.LOG_INFO)
		dz.log('device13 is '.. dz.devices(device13).state,dz.LOG_INFO)
		dz.log('device14 is '.. dz.devices(device14).state,dz.LOG_INFO)
		dz.log('device15 is '.. dz.devices(device15).state,dz.LOG_INFO)
		dz.log('device16 is '.. dz.devices(device16).state,dz.LOG_INFO)
		dz.log('device17 is '.. dz.devices(device17).state,dz.LOG_INFO)
		dz.log('device18 is '.. dz.devices(device18).state,dz.LOG_INFO)
		dz.log('device19 is '.. dz.devices(device19).state,dz.LOG_INFO)
		
		if (dz.devices(device0).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device1).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device2).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device3).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device4).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device5).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device6).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device7).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device8).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device9).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device10).state == 'On') then
			waarde=waarde+1
		end	
		if (dz.devices(device11).state == 'On') then
			waarde=waarde+1
		end
		dz.log('waarde is '.. waarde,dz.LOG_INFO)
		dz.log('result switch was '.. dz.devices(kogelKraan).state,dz.LOG_INFO)
		if waarde >= 5 then
		    dz.log('waarde => 5',dz.LOG_INFO)
		    dz.devices(kogelKraan).switchOff()
		else
		    if waarde < 5 then
		        dz.log('waarde < 5',dz.LOG_INFO)
		        dz.devices(kogelKraan).switchOn()
		    end
	    end   
	    
	end
}
This did work, but now i get 2 errors:

2023-09-22 12:31:02.082 Error: dzVents: Error: (3.1.8) test: An error occurred when calling event handler test
2023-09-22 12:31:02.082 Error: dzVents: Error: (3.1.8) test: .../domoticz/scripts/dzVents/generated_scripts/test.lua:68: attempt to concatenate a nil value (field 'state')

Can someone tell me what is wrong. This scripts is a test script that when there are less that 5 test devices on the test 00 needs to go on. And when there are 5 or more test devices on the test 00 needs to go off.
long time domiticz user, running 8 domoticz installations on vm's nuc i3. And espeay hosting more than 30.
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: dzvents test script did work now not more

Post by Kedi »

Your local devices are numbered to the last -> local device11 = 'test 12'
But your on = { section has a lot more and line 68 is creating the problem.
I can't tell what line 68 is in your case, if I copy the script it is: dz.log('device12 is '.. dz.devices(device12).state,dz.LOG_INFO)
device12 is not declared.
Logic will get you from A to B. Imagination will take you everywhere.
anno
Posts: 36
Joined: Wednesday 01 March 2017 13:00
Target OS: Windows
Domoticz version: all
Contact:

Re: dzvents test script did work now not more

Post by anno »

Indeed, i see, and also waarde=waarde+1 needs to be this waarde = waarde + 1 and same for local waarde=0 to local waarde = 0.

Now it is working again
long time domiticz user, running 8 domoticz installations on vm's nuc i3. And espeay hosting more than 30.
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: dzvents test script did work now not more

Post by Kedi »

There is no difference between those two. Space or no space is irrelevant.
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest