Blocky to DzVents Curtains  [Solved]

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

Moderator: leecollings

Post Reply
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blocky to DzVents Curtains

Post 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!
Attachments
Curtains.png
Curtains.png (195.77 KiB) Viewed 949 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Blocky to DzVents Curtains

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blocky to DzVents Curtains  [Solved]

Post 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!
AllesVanZelf
Posts: 265
Joined: Monday 05 February 2018 8:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 12467
Location: Netherlands, near Haarlem
Contact:

Re: Blocky to DzVents Curtains

Post 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.
Domoticz 2020.1 (12230) on Raspberry Pi 3B with Raspian Buster. Besides Domoticz, Rpi is running Pi-Hole.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest