Page 1 of 1

Blocky to DzVents Curtains

Posted: Friday 01 May 2020 22:05
by wouterlet
Sorry for another Noob question.
I'm really trying around, but still got a lot to learn.

I attached my Blocky, and underneath my translation to DzVents:

Code: Select all

return {
	on = {
		timer = {'at 9:00', 'at 19:00', 'at 21:00'},
		devices = {'UV Accuweather'}
		},
    execute = function(domoticz, timer)
	if  dz.time.matchesRule('at 09:00') or 
	    (dz.devices('UV Accuweather') < '2' and 
	    dz.time.matchesRule('> 09:00') and  
	    dz.time.matchesRule('< 19:00') and 
	    dz.variables('Var Luik Pim Ivo') == 1) then
	    dz.devices('Gordijn Ivo').switchOff()
	    dz.devices('Gordijn Pim').switchOff()
	    dz.variables('Var Luik Pim Ivo').set(0)
	end
	if  dz.time.matchesRule('at 09:00 on mon, tue, wed, thu, fri') then
	    dz.devices('Gordijn Ons').switchOff()
	    dz.variables('Var Luik Ons').set(0)
    end
	if  dz.devices('UV Accuweather') < 2 and dz.time.matchesRule('> 14:00') and  dz.time.matchesRule('< 19:00') and dz.variables('Var Luik Ons') == 1 then
	    dz.devices('Gordijn Ons').switchOff()
	    dz.variables('Var Luik Ons').set(0)
	    end
    if dz.time('< 12:30') and dz.devices('UV Accuweather') > 1 and dz.variables('Var Luik Pim Ivo') == 0 then 
        dz.devices('Gordijn Ivo').switchStop()
	    dz.devices('Gordijn Pim').switchStop()
	    dz.variables('Var Luik Pim Ivo').set(1)
    end
    if dz.time('< 14:30') and dz.devices('UV Accuweather') > 1 and dz.variables('Var Luik Ons') == 0 then 
        dz.devices('Gordijn Ons').switchStop()
	    dz.variables('Var Luik Ons').set(1)
	end
	if  dz.time.matchesRule('at 19:00') then
	    dz.devices('Gordijn Ivo').switchOn()
	    dz.devices('Gordijn Pim').switchOn()
	    dz.variables('Var Luik Pim Ivo').set(1)
			end
	if  dz.time.matchesRule('at 21:00') then
	    dz.devices('Gordijn Ons').switchOn()
	    dz.variables('Var Luik Ons').set(1)
			end		
	end
}
My log gives me back:

2020-05-01 21:26:10.113 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Gordijnen Boven DzVents
2020-05-01 21:26:10.113 Error: dzVents: Error: (3.0.2) ...ts/dzVents/generated_scripts/Gordijnen Boven DzVents.lua:7: attempt to index a nil value (global 'dz')

Line 7 is: if dz.time.matchesRule('at 09:00') or

I also tried without 'at', so only '09:00', but that gave the same error.
Any help would be really appreciated!

Re: Blocky to DzVents Curtains

Posted: Friday 01 May 2020 22:51
by waaren
wouterlet wrote: Friday 01 May 2020 22:05

Code: Select all

    execute = function(domoticz, timer)
	if  dz.time.matchesRule('at 09:00') or 

Any help would be really appreciated!
execute is here a function with 2 parms.

first parm (here named domoticz) is the domoticz object which is in fact a table with all devices, variables, cameras, scenes, groups, etc )
2nd parm (here named timer) is the object that triggered this script.

so if you refer in the rest of the script to the domoticz object (like you try in dz.time.matchesRule) you should use the same name as in the function call.

So either you change

Code: Select all

execute = function(domoticz, timer) 
to

Code: Select all

function(dz, timer)
or you change 'dz' to ' domoticz' everywhere else in the script.

Re: Blocky to DzVents Curtains  [Solved]

Posted: Saturday 02 May 2020 9:38
by wouterlet
Someone allready told you you're amazing?
Always so quick answers with a nice explanation. I changed it and now it went to the next error. But at least I could solve thisone with google.
Thanks man!

Re: Blocky to DzVents Curtains

Posted: Sunday 03 May 2020 9:57
by AllesVanZelf
@Wouterlet, Could you please post your end-scripts in your posts. The one's that are working for you?
Now I see a lot of code and suggestions to change them, but not sure how the end result would look like. :? I'd like to learn dzvents too but need some more working examples.