Page 1 of 1

Wildcards * in dzvents 2.0

Posted: Tuesday 04 July 2017 22:27
by TheCondor
Hello, i'm trying to convert all my script to dzvents and optimize that. Currently probably i don't understood how wildcards character works. Thanks in advance for the help!

Code: Select all

2017-07-04 22:15:00.664 dzVents: Info: ------ Start internal script: Tapparelle:, trigger: at 22:15
2017-07-04 22:15:00.664 Error: dzVents: Error: There is no device with that name or id: *_Tapparella
2017-07-04 22:15:00.664 Error: dzVents: Error: An error occured when calling event handler Tapparelle
2017-07-04 22:15:00.664 Error: dzVents: Error: ...omoticz/scripts/dzVents/generated_scripts/Tapparelle.lua:12: attempt to index a nil value
And this is my script that should close all the blinds at 22:15 in one is open:

Code: Select all

return {
        active = true,

        on = {
                timer = {
                        'at 22:15'
                }
        },

        execute = function(domoticz, dummy)

                if domoticz.devices('*_Tapparella').state ~= 'Closed' then
                        if domoticz.devices('Sala_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Sala_Tapparella').close()
                        end
                        if domoticz.devices('Camera_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Camera_Tapparella').close()
                        end
                        if domoticz.devices('Bagno_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Bagno_Tapparella').close()
                        end
                        if domoticz.devices('Stanzina_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Stanzina_Tapparella').close()
                        end
                                                if domoticz.devices('Cucina_Tapparella').state ~= 'Closed' then
                            domoticz.devices('Cucina_Tapparella').close()
                        end
                end
        end

Re: Wildcards * in dzvents 2.0

Posted: Thursday 06 July 2017 18:17
by dannybloe
Ah, you can only use wildcards in the 'on' section to specify a group of devices you wish to trigger.
In your case I would do it differently by first filtering out all devices with 'Taparella' in their name and then looping through those filtered devices to close them when necessary:

Code: Select all

return {
	active = true,
	on = {
		timer = {
			'at 22:15'
		}
	},
	execute = function(domoticz, dummy)
		-- close all Tarapellas 
		domoticz.devices().filter(function(device)
			return (string.match(device.name, '_Tapparella')~=nil)
		end).forEach(function(taparella)
			if (taparella.state ~= 'Closed') then
				taparella.close()
			end
		end)
		
	end
}

Re: Wildcards * in dzvents 2.0

Posted: Monday 10 July 2017 17:09
by TheCondor
Awesome! Really thanks for your incredible job danny and your kind support here!!!

Re: Wildcards * in dzvents 2.0

Posted: Thursday 03 August 2017 20:23
by EdwinK
So, to run this, I need to change the names _Tapparella to what I use (zonwering)? Or what else do I need? First time trying this dzevents thing.

Re: Wildcards * in dzvents 2.0

Posted: Thursday 03 August 2017 20:33
by TheCondor
Exactly, _Tapparella is A part of the nane of the devices i want to recoursive "Scan"

Re: Wildcards * in dzvents 2.0

Posted: Thursday 03 August 2017 21:46
by EdwinK
Thanks. Will see if I can adapt it to my needs